summaryrefslogtreecommitdiffstats
path: root/chrome/common
diff options
context:
space:
mode:
Diffstat (limited to 'chrome/common')
-rw-r--r--chrome/common/database_util.cc77
-rw-r--r--chrome/common/database_util.h23
-rw-r--r--chrome/common/web_database_observer_impl.cc52
-rw-r--r--chrome/common/web_database_observer_impl.h27
4 files changed, 179 insertions, 0 deletions
diff --git a/chrome/common/database_util.cc b/chrome/common/database_util.cc
new file mode 100644
index 0000000..7a54724
--- /dev/null
+++ b/chrome/common/database_util.cc
@@ -0,0 +1,77 @@
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/common/database_util.h"
+
+#if defined(USE_SYSTEM_SQLITE)
+#include <sqlite3.h>
+#else
+#include "third_party/sqlite/preprocessed/sqlite3.h"
+#endif
+
+#include "chrome/common/db_message_filter.h"
+#include "chrome/common/render_messages.h"
+#include "third_party/WebKit/WebKit/chromium/public/WebString.h"
+
+using WebKit::WebKitClient;
+using WebKit::WebString;
+
+WebKitClient::FileHandle DatabaseUtil::databaseOpenFile(
+ const WebString& vfs_file_name, int desired_flags,
+ WebKitClient::FileHandle* dir_handle) {
+ DBMessageFilter* db_message_filter = DBMessageFilter::GetInstance();
+ int message_id = db_message_filter->GetUniqueID();
+
+#if defined(OS_WIN)
+ ViewMsg_DatabaseOpenFileResponse_Params default_response =
+ { base::kInvalidPlatformFileValue };
+#elif defined(OS_POSIX)
+ ViewMsg_DatabaseOpenFileResponse_Params default_response =
+ { base::FileDescriptor(base::kInvalidPlatformFileValue, true),
+ base::FileDescriptor(base::kInvalidPlatformFileValue, true) };
+#endif
+
+ ViewMsg_DatabaseOpenFileResponse_Params result =
+ db_message_filter->SendAndWait(
+ new ViewHostMsg_DatabaseOpenFile(
+ vfs_file_name, desired_flags, message_id),
+ message_id, default_response);
+
+#if defined(OS_WIN)
+ if (dir_handle)
+ *dir_handle = base::kInvalidPlatformFileValue;
+ return result.file_handle;
+#elif defined(OS_POSIX)
+ if (dir_handle)
+ *dir_handle = result.dir_handle.fd;
+ return result.file_handle.fd;
+#endif
+}
+
+int DatabaseUtil::databaseDeleteFile(
+ const WebString& vfs_file_name, bool sync_dir) {
+ DBMessageFilter* db_message_filter = DBMessageFilter::GetInstance();
+ int message_id = db_message_filter->GetUniqueID();
+ return db_message_filter->SendAndWait(
+ new ViewHostMsg_DatabaseDeleteFile(vfs_file_name, sync_dir, message_id),
+ message_id, SQLITE_IOERR_DELETE);
+}
+
+long DatabaseUtil::databaseGetFileAttributes(
+ const WebString& vfs_file_name) {
+ DBMessageFilter* db_message_filter = DBMessageFilter::GetInstance();
+ int message_id = db_message_filter->GetUniqueID();
+ return db_message_filter->SendAndWait(
+ new ViewHostMsg_DatabaseGetFileAttributes(vfs_file_name, message_id),
+ message_id, -1L);
+}
+
+long long DatabaseUtil::databaseGetFileSize(
+ const WebString& vfs_file_name) {
+ DBMessageFilter* db_message_filter = DBMessageFilter::GetInstance();
+ int message_id = db_message_filter->GetUniqueID();
+ return db_message_filter->SendAndWait(
+ new ViewHostMsg_DatabaseGetFileSize(vfs_file_name, message_id),
+ message_id, 0LL);
+}
diff --git a/chrome/common/database_util.h b/chrome/common/database_util.h
new file mode 100644
index 0000000..70bd029
--- /dev/null
+++ b/chrome/common/database_util.h
@@ -0,0 +1,23 @@
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_COMMON_DATABASE_UTIL_H_
+#define CHROME_COMMON_DATABASE_UTIL_H_
+
+#include "webkit/glue/webkitclient_impl.h"
+
+// A class of utility functions used by RendererWebKitClientImpl and
+// WorkerWebKitClientImpl to handle database file accesses.
+class DatabaseUtil {
+ public:
+ static WebKit::WebKitClient::FileHandle databaseOpenFile(
+ const WebKit::WebString& vfs_file_name,
+ int desired_flags, WebKit::WebKitClient::FileHandle* dir_handle);
+ static int databaseDeleteFile(const WebKit::WebString& vfs_file_name,
+ bool sync_dir);
+ static long databaseGetFileAttributes(const WebKit::WebString& vfs_file_name);
+ static long long databaseGetFileSize(const WebKit::WebString& vfs_file_name);
+};
+
+#endif // CHROME_COMMON_DATABASE_UTIL_H_
diff --git a/chrome/common/web_database_observer_impl.cc b/chrome/common/web_database_observer_impl.cc
new file mode 100644
index 0000000..32d358c
--- /dev/null
+++ b/chrome/common/web_database_observer_impl.cc
@@ -0,0 +1,52 @@
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/common/web_database_observer_impl.h"
+
+#include "base/auto_reset.h"
+#include "base/message_loop.h"
+#include "base/string16.h"
+#include "chrome/common/render_messages.h"
+#include "third_party/WebKit/WebKit/chromium/public/WebDatabase.h"
+
+WebDatabaseObserverImpl::WebDatabaseObserverImpl(
+ IPC::Message::Sender* sender)
+ : sender_(sender),
+ waiting_for_dbs_to_close_(false) {
+}
+
+void WebDatabaseObserverImpl::databaseOpened(
+ const WebKit::WebDatabase& database) {
+ string16 origin_identifier = database.securityOrigin().databaseIdentifier();
+ string16 database_name = database.name();
+ sender_->Send(new ViewHostMsg_DatabaseOpened(
+ origin_identifier, database_name,
+ database.displayName(), database.estimatedSize()));
+ database_connections_.AddConnection(origin_identifier, database_name);
+}
+
+void WebDatabaseObserverImpl::databaseModified(
+ const WebKit::WebDatabase& database) {
+ sender_->Send(new ViewHostMsg_DatabaseModified(
+ database.securityOrigin().databaseIdentifier(), database.name()));
+}
+
+void WebDatabaseObserverImpl::databaseClosed(
+ const WebKit::WebDatabase& database) {
+ string16 origin_identifier = database.securityOrigin().databaseIdentifier();
+ string16 database_name = database.name();
+ sender_->Send(new ViewHostMsg_DatabaseClosed(
+ origin_identifier, database_name));
+ database_connections_.RemoveConnection(origin_identifier, database_name);
+ if (waiting_for_dbs_to_close_ && database_connections_.IsEmpty())
+ MessageLoop::current()->Quit();
+}
+
+void WebDatabaseObserverImpl::WaitForAllDatabasesToClose() {
+ if (!database_connections_.IsEmpty()) {
+ AutoReset waiting_for_dbs_auto_reset(&waiting_for_dbs_to_close_, true);
+ MessageLoop::ScopedNestableTaskAllower nestable(MessageLoop::current());
+ MessageLoop::current()->Run();
+ }
+}
diff --git a/chrome/common/web_database_observer_impl.h b/chrome/common/web_database_observer_impl.h
new file mode 100644
index 0000000..3f5e80b
--- /dev/null
+++ b/chrome/common/web_database_observer_impl.h
@@ -0,0 +1,27 @@
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_COMMON_WEB_DATABASE_OBSERVER_IMPL_H_
+#define CHROME_COMMON_WEB_DATABASE_OBSERVER_IMPL_H_
+
+#include "ipc/ipc_message.h"
+#include "third_party/WebKit/WebKit/chromium/public/WebDatabaseObserver.h"
+#include "webkit/database/database_connections.h"
+
+class WebDatabaseObserverImpl : public WebKit::WebDatabaseObserver {
+ public:
+ explicit WebDatabaseObserverImpl(IPC::Message::Sender* sender);
+ virtual void databaseOpened(const WebKit::WebDatabase& database);
+ virtual void databaseModified(const WebKit::WebDatabase& database);
+ virtual void databaseClosed(const WebKit::WebDatabase& database);
+
+ void WaitForAllDatabasesToClose();
+
+ private:
+ IPC::Message::Sender* sender_;
+ bool waiting_for_dbs_to_close_;
+ webkit_database::DatabaseConnections database_connections_;
+};
+
+#endif // CHROME_COMMON_WEB_DATABASE_OBSERVER_IMPL_H_