chromium/third_party/blink/renderer/modules/webdatabase/database.cc

/*
 * Copyright (C) 2013 Apple Inc. All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

#include "third_party/blink/renderer/modules/webdatabase/database.h"

#include <memory>
#include <utility>

#include "base/synchronization/waitable_event.h"
#include "base/thread_annotations.h"
#include "third_party/blink/public/platform/platform.h"
#include "third_party/blink/public/platform/task_type.h"
#include "third_party/blink/renderer/core/execution_context/execution_context.h"
#include "third_party/blink/renderer/core/frame/web_feature.h"
#include "third_party/blink/renderer/core/inspector/console_message.h"
#include "third_party/blink/renderer/core/probe/core_probes.h"
#include "third_party/blink/renderer/modules/webdatabase/change_version_data.h"
#include "third_party/blink/renderer/modules/webdatabase/change_version_wrapper.h"
#include "third_party/blink/renderer/modules/webdatabase/database_authorizer.h"
#include "third_party/blink/renderer/modules/webdatabase/database_context.h"
#include "third_party/blink/renderer/modules/webdatabase/database_task.h"
#include "third_party/blink/renderer/modules/webdatabase/database_thread.h"
#include "third_party/blink/renderer/modules/webdatabase/database_tracker.h"
#include "third_party/blink/renderer/modules/webdatabase/sql_error.h"
#include "third_party/blink/renderer/modules/webdatabase/sql_transaction_backend.h"
#include "third_party/blink/renderer/modules/webdatabase/sql_transaction_client.h"
#include "third_party/blink/renderer/modules/webdatabase/sql_transaction_coordinator.h"
#include "third_party/blink/renderer/modules/webdatabase/sqlite/sqlite_statement.h"
#include "third_party/blink/renderer/modules/webdatabase/sqlite/sqlite_transaction.h"
#include "third_party/blink/renderer/modules/webdatabase/storage_log.h"
#include "third_party/blink/renderer/modules/webdatabase/web_database_host.h"
#include "third_party/blink/renderer/platform/heap/garbage_collected.h"
#include "third_party/blink/renderer/platform/scheduler/public/frame_scheduler.h"
#include "third_party/blink/renderer/platform/scheduler/public/post_cross_thread_task.h"
#include "third_party/blink/renderer/platform/scheduler/public/scheduling_policy.h"
#include "third_party/blink/renderer/platform/wtf/allocator/allocator.h"
#include "third_party/blink/renderer/platform/wtf/cross_thread_functional.h"

// Registering "opened" databases with the DatabaseTracker
// =======================================================
// The DatabaseTracker maintains a list of databases that have been
// "opened" so that the client can call interrupt or delete on every database
// associated with a DatabaseContext.
//
// We will only call DatabaseTracker::addOpenDatabase() to add the database
// to the tracker as opened when we've succeeded in opening the database,
// and will set m_opened to true. Similarly, we only call
// DatabaseTracker::removeOpenDatabase() to remove the database from the
// tracker when we set m_opened to false in closeDatabase(). This sets up
// a simple symmetry between open and close operations, and a direct
// correlation to adding and removing databases from the tracker's list,
// thus ensuring that we have a correct list for the interrupt and
// delete operations to work on.
//
// The only databases instances not tracked by the tracker's open database
// list are the ones that have not been added yet, or the ones that we
// attempted an open on but failed to. Such instances only exist in the
// DatabaseServer's factory methods for creating database backends.
//
// The factory methods will either call openAndVerifyVersion() or
// performOpenAndVerify(). These methods will add the newly instantiated
// database backend if they succeed in opening the requested database.
// In the case of failure to open the database, the factory methods will
// simply discard the newly instantiated database backend when they return.
// The ref counting mechanims will automatically destruct the un-added
// (and un-returned) databases instances.

namespace blink {

namespace {

// Stores a cached version of each database, keyed by a unique integer obtained
// by providing an origin-name pair.
class DatabaseVersionCache {};

DatabaseVersionCache& GetDatabaseVersionCache() {}

}  // namespace

static const char kVersionKey[] =;
static const char kInfoTableName[] =;

static String FormatErrorMessage(const char* message,
                                 int sqlite_error_code,
                                 const char* sqlite_error_message) {}

static bool RetrieveTextResultFromDatabase(SQLiteDatabase& db,
                                           const String& query,
                                           String& result_string) {}

static bool SetTextValueInDatabase(SQLiteDatabase& db,
                                   const String& query,
                                   const String& value) {}

Database::Database(DatabaseContext* database_context,
                   const String& name,
                   const String& expected_version,
                   const String& display_name)
    :{}

Database::~Database() {}

void Database::Trace(Visitor* visitor) const {}

bool Database::OpenAndVerifyVersion(bool set_version_in_new_database,
                                    DatabaseError& error,
                                    String& error_message,
                                    V8DatabaseCallback* creation_callback) {}

void Database::RunCreationCallback(
    V8DatabaseCallback* creation_callback,
    std::unique_ptr<probe::AsyncTaskContext> async_task_context) {}

void Database::Close() {}

SQLTransactionBackend* Database::RunTransaction(SQLTransaction* transaction,
                                                bool read_only,
                                                const ChangeVersionData* data) {}

void Database::InProgressTransactionCompleted() {}

void Database::ScheduleTransaction() {}

void Database::ScheduleTransactionStep(SQLTransactionBackend* transaction) {}

SQLTransactionClient* Database::TransactionClient() const {}

SQLTransactionCoordinator* Database::TransactionCoordinator() const {}

// static
const char* Database::DatabaseInfoTableName() {}

void Database::CloseDatabase() {}

String Database::version() const {}

class DoneCreatingDatabaseOnExitCaller {};

bool Database::PerformOpenAndVerify(bool should_set_version_in_new_database,
                                    DatabaseError& error,
                                    String& error_message) {}

String Database::StringIdentifier() const {}

String Database::DisplayName() const {}

String Database::FileName() const {}

bool Database::GetVersionFromDatabase(String& version,
                                      bool should_cache_version) {}

bool Database::SetVersionInDatabase(const String& version,
                                    bool should_cache_version) {}

void Database::SetExpectedVersion(const String& version) {}

String Database::GetCachedVersion() const {}

void Database::SetCachedVersion(const String& actual_version) {}

bool Database::GetActualVersionForTransaction(String& actual_version) {}

void Database::DisableAuthorizer() {}

void Database::EnableAuthorizer() {}

void Database::SetAuthorizerPermissions(int permissions) {}

bool Database::LastActionChangedDatabase() {}

bool Database::LastActionWasInsert() {}

void Database::ResetDeletes() {}

bool Database::HadDeletes() {}

void Database::ResetAuthorizer() {}

uint64_t Database::MaximumSize() const {}

void Database::IncrementalVacuumIfNeeded() {}

void Database::ReportSqliteError(int sqlite_error_code) {}

void Database::LogErrorMessage(const String& message) {}

ExecutionContext* Database::GetExecutionContext() const {}

void Database::CloseImmediately() {}

void Database::changeVersion(const String& old_version,
                             const String& new_version,
                             V8SQLTransactionCallback* callback,
                             V8SQLTransactionErrorCallback* error_callback,
                             V8VoidCallback* success_callback) {}

void Database::transaction(V8SQLTransactionCallback* callback,
                           V8SQLTransactionErrorCallback* error_callback,
                           V8VoidCallback* success_callback) {}

void Database::readTransaction(V8SQLTransactionCallback* callback,
                               V8SQLTransactionErrorCallback* error_callback,
                               V8VoidCallback* success_callback) {}

void Database::PerformTransaction(
    SQLTransaction::OnProcessCallback* callback,
    SQLTransaction::OnErrorCallback* error_callback,
    SQLTransaction::OnSuccessCallback* success_callback) {}

static void CallTransactionErrorCallback(
    SQLTransaction::OnErrorCallback* callback,
    std::unique_ptr<SQLErrorData> error_data) {}

void Database::RunTransaction(
    SQLTransaction::OnProcessCallback* callback,
    SQLTransaction::OnErrorCallback* error_callback,
    SQLTransaction::OnSuccessCallback* success_callback,
    bool read_only,
    const ChangeVersionData* change_version_data) {}

void Database::ScheduleTransactionCallback(SQLTransaction* transaction) {}

Vector<String> Database::PerformGetTableNames() {}

Vector<String> Database::TableNames() {}

const SecurityOrigin* Database::GetSecurityOrigin() const {}

base::SingleThreadTaskRunner* Database::GetDatabaseTaskRunner() const {}

}  // namespace blink