diff options
author | dumi@chromium.org <dumi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-11-13 06:37:03 +0000 |
---|---|---|
committer | dumi@chromium.org <dumi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-11-13 06:37:03 +0000 |
commit | 60cba79ac19628c205fce7cfdfd7845c1c3b6b60 (patch) | |
tree | 6731697cd5520c0e29818f4ee922e62a56dbddf9 | |
parent | 0c6fbd6e38d3fc5c04cbc22fe769e766f814253b (diff) | |
download | chromium_src-60cba79ac19628c205fce7cfdfd7845c1c3b6b60.zip chromium_src-60cba79ac19628c205fce7cfdfd7845c1c3b6b60.tar.gz chromium_src-60cba79ac19628c205fce7cfdfd7845c1c3b6b60.tar.bz2 |
Cleans up a bit the DB-related methods.
TEST=none
BUG=none
Review URL: http://codereview.chromium.org/394006
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@31891 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/renderer_host/database_dispatcher_host.cc | 38 | ||||
-rw-r--r-- | chrome/browser/renderer_host/database_dispatcher_host.h | 18 | ||||
-rw-r--r-- | chrome/common/render_messages_internal.h | 8 | ||||
-rw-r--r-- | chrome/renderer/renderer_webkitclient_impl.cc | 23 | ||||
-rw-r--r-- | chrome/renderer/renderer_webkitclient_impl.h | 12 | ||||
-rw-r--r-- | webkit/database/database_util.cc | 22 | ||||
-rw-r--r-- | webkit/database/database_util.h | 4 | ||||
-rw-r--r-- | webkit/database/database_util_unittest.cc | 4 | ||||
-rw-r--r-- | webkit/glue/webkitclient_impl.cc | 8 | ||||
-rw-r--r-- | webkit/glue/webkitclient_impl.h | 12 |
10 files changed, 69 insertions, 80 deletions
diff --git a/chrome/browser/renderer_host/database_dispatcher_host.cc b/chrome/browser/renderer_host/database_dispatcher_host.cc index e143364..9a2d98a 100644 --- a/chrome/browser/renderer_host/database_dispatcher_host.cc +++ b/chrome/browser/renderer_host/database_dispatcher_host.cc @@ -70,16 +70,6 @@ void DatabaseDispatcherHost::RemoveObserver() { db_tracker_->RemoveObserver(this); } -// TODO(dumi): remove this function when switching IPC parameters -// from FilePath to string16 -FilePath DatabaseDispatcherHost::GetFullFilePathForVfsFile( - const FilePath& vfs_file_name) { - DCHECK(ChromeThread::CurrentlyOn(ChromeThread::FILE)); - DCHECK(!vfs_file_name.empty()); - return DatabaseUtil::GetFullFilePathForVfsFile( - db_tracker_, WideToUTF16(vfs_file_name.ToWStringHack())); -} - bool DatabaseDispatcherHost::OnMessageReceived( const IPC::Message& message, bool* message_was_ok) { DCHECK(!shutdown_); @@ -115,7 +105,7 @@ void DatabaseDispatcherHost::SendMessage(IPC::Message* message) { delete message; } -void DatabaseDispatcherHost::OnDatabaseOpenFile(const FilePath& vfs_file_name, +void DatabaseDispatcherHost::OnDatabaseOpenFile(const string16& vfs_file_name, int desired_flags, int32 message_id) { if (!observer_added_) { @@ -150,7 +140,7 @@ static void SetOpenFileResponseParams( // Opens the given database file, then schedules // a task on the IO thread's message loop to send an IPC back to // corresponding renderer process with the file handle. -void DatabaseDispatcherHost::DatabaseOpenFile(const FilePath& vfs_file_name, +void DatabaseDispatcherHost::DatabaseOpenFile(const string16& vfs_file_name, int desired_flags, int32 message_id) { DCHECK(ChromeThread::CurrentlyOn(ChromeThread::FILE)); @@ -161,7 +151,8 @@ void DatabaseDispatcherHost::DatabaseOpenFile(const FilePath& vfs_file_name, desired_flags, process_handle_, &target_handle, &target_dir_handle); } else { - FilePath db_file = GetFullFilePathForVfsFile(vfs_file_name); + FilePath db_file = + DatabaseUtil::GetFullFilePathForVfsFile(db_tracker_, vfs_file_name); if (!db_file.empty()) { VfsBackend::OpenFile(db_file, desired_flags, process_handle_, &target_handle, &target_dir_handle); @@ -178,7 +169,7 @@ void DatabaseDispatcherHost::DatabaseOpenFile(const FilePath& vfs_file_name, message_id, response_params))); } -void DatabaseDispatcherHost::OnDatabaseDeleteFile(const FilePath& vfs_file_name, +void DatabaseDispatcherHost::OnDatabaseDeleteFile(const string16& vfs_file_name, const bool& sync_dir, int32 message_id) { ChromeThread::PostTask( @@ -195,7 +186,7 @@ void DatabaseDispatcherHost::OnDatabaseDeleteFile(const FilePath& vfs_file_name, // Deletes the given database file, then schedules // a task on the IO thread's message loop to send an IPC back to // corresponding renderer process with the error code. -void DatabaseDispatcherHost::DatabaseDeleteFile(const FilePath& vfs_file_name, +void DatabaseDispatcherHost::DatabaseDeleteFile(const string16& vfs_file_name, bool sync_dir, int32 message_id, int reschedule_count) { @@ -204,7 +195,8 @@ void DatabaseDispatcherHost::DatabaseDeleteFile(const FilePath& vfs_file_name, // Return an error if the file name is invalid or if the file could not // be deleted after kNumDeleteRetries attempts. int error_code = SQLITE_IOERR_DELETE; - FilePath db_file = GetFullFilePathForVfsFile(vfs_file_name); + FilePath db_file = + DatabaseUtil::GetFullFilePathForVfsFile(db_tracker_, vfs_file_name); if (!db_file.empty()) { error_code = VfsBackend::DeleteFile(db_file, sync_dir); if ((error_code == SQLITE_IOERR_DELETE) && reschedule_count) { @@ -231,7 +223,7 @@ void DatabaseDispatcherHost::DatabaseDeleteFile(const FilePath& vfs_file_name, } void DatabaseDispatcherHost::OnDatabaseGetFileAttributes( - const FilePath& vfs_file_name, + const string16& vfs_file_name, int32 message_id) { ChromeThread::PostTask( ChromeThread::FILE, FROM_HERE, @@ -246,11 +238,12 @@ void DatabaseDispatcherHost::OnDatabaseGetFileAttributes( // a task on the IO thread's message loop to send an IPC back to // corresponding renderer process. void DatabaseDispatcherHost::DatabaseGetFileAttributes( - const FilePath& vfs_file_name, + const string16& vfs_file_name, int32 message_id) { DCHECK(ChromeThread::CurrentlyOn(ChromeThread::FILE)); int32 attributes = -1; - FilePath db_file = GetFullFilePathForVfsFile(vfs_file_name); + FilePath db_file = + DatabaseUtil::GetFullFilePathForVfsFile(db_tracker_, vfs_file_name); if (!db_file.empty()) attributes = VfsBackend::GetFileAttributes(db_file); ChromeThread::PostTask( @@ -262,7 +255,7 @@ void DatabaseDispatcherHost::DatabaseGetFileAttributes( } void DatabaseDispatcherHost::OnDatabaseGetFileSize( - const FilePath& vfs_file_name, int32 message_id) { + const string16& vfs_file_name, int32 message_id) { ChromeThread::PostTask( ChromeThread::FILE, FROM_HERE, NewRunnableMethod(this, @@ -275,11 +268,12 @@ void DatabaseDispatcherHost::OnDatabaseGetFileSize( // Gets the size of the given file, then schedules a task // on the IO thread's message loop to send an IPC back to // the corresponding renderer process. -void DatabaseDispatcherHost::DatabaseGetFileSize(const FilePath& vfs_file_name, +void DatabaseDispatcherHost::DatabaseGetFileSize(const string16& vfs_file_name, int32 message_id) { DCHECK(ChromeThread::CurrentlyOn(ChromeThread::FILE)); int64 size = 0; - FilePath db_file = GetFullFilePathForVfsFile(vfs_file_name); + FilePath db_file = + DatabaseUtil::GetFullFilePathForVfsFile(db_tracker_, vfs_file_name); if (!db_file.empty()) size = VfsBackend::GetFileSize(db_file); ChromeThread::PostTask( diff --git a/chrome/browser/renderer_host/database_dispatcher_host.h b/chrome/browser/renderer_host/database_dispatcher_host.h index b1d31d7..7b6a558 100644 --- a/chrome/browser/renderer_host/database_dispatcher_host.h +++ b/chrome/browser/renderer_host/database_dispatcher_host.h @@ -5,7 +5,6 @@ #ifndef CHROME_BROWSER_RENDERER_HOST_DATABASE_DISPATCHER_HOST_H_ #define CHROME_BROWSER_RENDERER_HOST_DATABASE_DISPATCHER_HOST_H_ -#include "base/file_path.h" #include "base/hash_tables.h" #include "base/process.h" #include "base/ref_counted.h" @@ -25,15 +24,15 @@ class DatabaseDispatcherHost bool OnMessageReceived(const IPC::Message& message, bool* message_was_ok); // VFS message handlers (IO thread) - void OnDatabaseOpenFile(const FilePath& vfs_file_name, + void OnDatabaseOpenFile(const string16& vfs_file_name, int desired_flags, int32 message_id); - void OnDatabaseDeleteFile(const FilePath& vfs_file_name, + void OnDatabaseDeleteFile(const string16& vfs_file_name, const bool& sync_dir, int32 message_id); - void OnDatabaseGetFileAttributes(const FilePath& vfs_file_name, + void OnDatabaseGetFileAttributes(const string16& vfs_file_name, int32 message_id); - void OnDatabaseGetFileSize(const FilePath& vfs_file_name, + void OnDatabaseGetFileSize(const string16& vfs_file_name, int32 message_id); // Database tracker message handlers (IO thread) @@ -55,22 +54,21 @@ class DatabaseDispatcherHost private: void AddObserver(); void RemoveObserver(); - FilePath GetFullFilePathForVfsFile(const FilePath& vfs_file_name); void ReceivedBadMessage(uint16 msg_type); void SendMessage(IPC::Message* message); // VFS message handlers (file thread) - void DatabaseOpenFile(const FilePath& vfs_file_name, + void DatabaseOpenFile(const string16& vfs_file_name, int desired_flags, int32 message_id); - void DatabaseDeleteFile(const FilePath& vfs_file_name, + void DatabaseDeleteFile(const string16& vfs_file_name, bool sync_dir, int32 message_id, int reschedule_count); - void DatabaseGetFileAttributes(const FilePath& vfs_file_name, + void DatabaseGetFileAttributes(const string16& vfs_file_name, int32 message_id); - void DatabaseGetFileSize(const FilePath& vfs_file_name, + void DatabaseGetFileSize(const string16& vfs_file_name, int32 message_id); // Database tracker message handlers (file thread) diff --git a/chrome/common/render_messages_internal.h b/chrome/common/render_messages_internal.h index 3d99dbe..03ad8d1 100644 --- a/chrome/common/render_messages_internal.h +++ b/chrome/common/render_messages_internal.h @@ -1949,24 +1949,24 @@ IPC_BEGIN_MESSAGES(ViewHost) // Asks the browser process to open a DB file with the given name IPC_MESSAGE_CONTROL3(ViewHostMsg_DatabaseOpenFile, - FilePath /* file name */, + string16 /* vfs file name */, int /* desired flags */, int32 /* a unique message ID */) // Asks the browser process to delete a DB file IPC_MESSAGE_CONTROL3(ViewHostMsg_DatabaseDeleteFile, - FilePath /* the name of the file */, + string16 /* vfs file name */, bool /* whether or not to sync the directory */, int32 /* a unique message ID */) // Asks the browser process to return the attributes of a DB file IPC_MESSAGE_CONTROL2(ViewHostMsg_DatabaseGetFileAttributes, - FilePath /* the name of the file */, + string16 /* vfs file name */, int32 /* a unique message ID */) // Asks the browser process to return the size of a DB file IPC_MESSAGE_CONTROL2(ViewHostMsg_DatabaseGetFileSize, - FilePath /* the name of the file */, + string16 /* vfs file name */, int32 /* a unique message ID */) // Notifies the browser process that a new database has been opened diff --git a/chrome/renderer/renderer_webkitclient_impl.cc b/chrome/renderer/renderer_webkitclient_impl.cc index cec8119..43c568f 100644 --- a/chrome/renderer/renderer_webkitclient_impl.cc +++ b/chrome/renderer/renderer_webkitclient_impl.cc @@ -300,7 +300,7 @@ WebString RendererWebKitClientImpl::SandboxSupport::getFontFamilyForCharacters( //------------------------------------------------------------------------------ WebKitClient::FileHandle RendererWebKitClientImpl::databaseOpenFile( - const WebString& file_name, int desired_flags, + 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(); @@ -316,8 +316,7 @@ WebKitClient::FileHandle RendererWebKitClientImpl::databaseOpenFile( ViewMsg_DatabaseOpenFileResponse_Params result = db_message_filter->SendAndWait( new ViewHostMsg_DatabaseOpenFile( - FilePath(webkit_glue::WebStringToFilePathString(file_name)), - desired_flags, message_id), + vfs_file_name, desired_flags, message_id), message_id, default_response); #if defined(OS_WIN) @@ -334,35 +333,29 @@ WebKitClient::FileHandle RendererWebKitClientImpl::databaseOpenFile( } int RendererWebKitClientImpl::databaseDeleteFile( - const WebString& file_name, bool sync_dir) { + 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( - FilePath(webkit_glue::WebStringToFilePathString(file_name)), sync_dir, - message_id), + new ViewHostMsg_DatabaseDeleteFile(vfs_file_name, sync_dir, message_id), message_id, SQLITE_IOERR_DELETE); } long RendererWebKitClientImpl::databaseGetFileAttributes( - const WebString& file_name) { + 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( - FilePath(webkit_glue::WebStringToFilePathString(file_name)), - message_id), + new ViewHostMsg_DatabaseGetFileAttributes(vfs_file_name, message_id), message_id, -1L); } long long RendererWebKitClientImpl::databaseGetFileSize( - const WebString& file_name) { + 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( - FilePath(webkit_glue::WebStringToFilePathString(file_name)), - message_id), + new ViewHostMsg_DatabaseGetFileSize(vfs_file_name, message_id), message_id, 0LL); } diff --git a/chrome/renderer/renderer_webkitclient_impl.h b/chrome/renderer/renderer_webkitclient_impl.h index 19e88a8..cf97ad7 100644 --- a/chrome/renderer/renderer_webkitclient_impl.h +++ b/chrome/renderer/renderer_webkitclient_impl.h @@ -56,12 +56,14 @@ class RendererWebKitClientImpl : public webkit_glue::WebKitClientImpl { const WebKit::WebURL& url, bool is_local_storage); virtual WebKit::WebKitClient::FileHandle databaseOpenFile( - const WebKit::WebString& file_name, int desired_flags, + const WebKit::WebString& vfs_file_name, int desired_flags, WebKit::WebKitClient::FileHandle* dir_handle); - virtual int databaseDeleteFile(const WebKit::WebString& file_name, - bool sync_dir); - virtual long databaseGetFileAttributes(const WebKit::WebString& file_name); - virtual long long databaseGetFileSize(const WebKit::WebString& file_name); + virtual int databaseDeleteFile(const WebKit::WebString& vfs_file_name, + bool sync_dir); + virtual long databaseGetFileAttributes( + const WebKit::WebString& vfs_file_name); + virtual long long databaseGetFileSize( + const WebKit::WebString& vfs_file_name); virtual WebKit::WebString signedPublicKeyAndChallengeString( unsigned key_size_index, const WebKit::WebString& challenge, diff --git a/webkit/database/database_util.cc b/webkit/database/database_util.cc index b571a72..b1ba76a 100644 --- a/webkit/database/database_util.cc +++ b/webkit/database/database_util.cc @@ -10,15 +10,15 @@ namespace webkit_database { -bool DatabaseUtil::CrackVfsFilePath(const string16& vfs_file_path, +bool DatabaseUtil::CrackVfsFileName(const string16& vfs_file_name, string16* origin_identifier, string16* database_name, string16* sqlite_suffix) { - // 'vfs_file_path' is of the form <origin_identifier>/<db_name>#<suffix>. + // 'vfs_file_name' is of the form <origin_identifier>/<db_name>#<suffix>. // <suffix> is optional. - DCHECK(!vfs_file_path.empty()); - size_t first_slash_index = vfs_file_path.find('/'); - size_t last_pound_index = vfs_file_path.rfind('#'); + DCHECK(!vfs_file_name.empty()); + size_t first_slash_index = vfs_file_name.find('/'); + size_t last_pound_index = vfs_file_name.rfind('#'); // '/' and '#' must be present in the string. Also, the string cannot start // with a '/' (origin_identifier cannot be empty) and '/' must come before '#' if ((first_slash_index == string16::npos) || @@ -28,20 +28,20 @@ bool DatabaseUtil::CrackVfsFilePath(const string16& vfs_file_path, return false; } - *origin_identifier = vfs_file_path.substr(0, first_slash_index); - *database_name = vfs_file_path.substr( + *origin_identifier = vfs_file_name.substr(0, first_slash_index); + *database_name = vfs_file_name.substr( first_slash_index + 1, last_pound_index - first_slash_index - 1); - *sqlite_suffix = vfs_file_path.substr( - last_pound_index + 1, vfs_file_path.length() - last_pound_index - 1); + *sqlite_suffix = vfs_file_name.substr( + last_pound_index + 1, vfs_file_name.length() - last_pound_index - 1); return true; } FilePath DatabaseUtil::GetFullFilePathForVfsFile( - DatabaseTracker* db_tracker, const string16& vfs_file_path) { + DatabaseTracker* db_tracker, const string16& vfs_file_name) { string16 origin_identifier; string16 database_name; string16 sqlite_suffix; - if (!CrackVfsFilePath(vfs_file_path, &origin_identifier, + if (!CrackVfsFileName(vfs_file_name, &origin_identifier, &database_name, &sqlite_suffix)) { return FilePath(); // invalid vfs_file_name } diff --git a/webkit/database/database_util.h b/webkit/database/database_util.h index 7df1d38..c18e5f4 100644 --- a/webkit/database/database_util.h +++ b/webkit/database/database_util.h @@ -14,12 +14,12 @@ class DatabaseTracker; class DatabaseUtil { public: - static bool CrackVfsFilePath(const string16& vfs_file_path, + static bool CrackVfsFileName(const string16& vfs_file_name, string16* origin_identifier, string16* database_name, string16* sqlite_suffix); static FilePath GetFullFilePathForVfsFile(DatabaseTracker* db_tracker, - const string16& vfs_file_path); + const string16& vfs_file_name); }; diff --git a/webkit/database/database_util_unittest.cc b/webkit/database/database_util_unittest.cc index 4718e89..87422a5 100644 --- a/webkit/database/database_util_unittest.cc +++ b/webkit/database/database_util_unittest.cc @@ -9,7 +9,7 @@ using webkit_database::DatabaseUtil; static void TestVfsFilePath(bool expected_result, - const char* vfs_file_path, + const char* vfs_file_name, const char* expected_origin_identifier = "", const char* expected_database_name = "", const char* expected_sqlite_suffix = "") { @@ -17,7 +17,7 @@ static void TestVfsFilePath(bool expected_result, string16 database_name; string16 sqlite_suffix; EXPECT_EQ(expected_result, - DatabaseUtil::CrackVfsFilePath(ASCIIToUTF16(vfs_file_path), + DatabaseUtil::CrackVfsFileName(ASCIIToUTF16(vfs_file_name), &origin_identifier, &database_name, &sqlite_suffix)); diff --git a/webkit/glue/webkitclient_impl.cc b/webkit/glue/webkitclient_impl.cc index 61d2d6a..e495673 100644 --- a/webkit/glue/webkitclient_impl.cc +++ b/webkit/glue/webkitclient_impl.cc @@ -291,7 +291,7 @@ void WebKitClientImpl::callOnMainThread(void (*func)()) { } base::PlatformFile WebKitClientImpl::databaseOpenFile( - const WebKit::WebString& file_name, int desired_flags, + const WebKit::WebString& vfs_file_name, int desired_flags, base::PlatformFile* dir_handle) { if (dir_handle) *dir_handle = base::kInvalidPlatformFileValue; @@ -299,17 +299,17 @@ base::PlatformFile WebKitClientImpl::databaseOpenFile( } int WebKitClientImpl::databaseDeleteFile( - const WebKit::WebString& file_name, bool sync_dir) { + const WebKit::WebString& vfs_file_name, bool sync_dir) { return -1; } long WebKitClientImpl::databaseGetFileAttributes( - const WebKit::WebString& file_name) { + const WebKit::WebString& vfs_file_name) { return 0; } long long WebKitClientImpl::databaseGetFileSize( - const WebKit::WebString& file_name) { + const WebKit::WebString& vfs_file_name) { return 0; } diff --git a/webkit/glue/webkitclient_impl.h b/webkit/glue/webkitclient_impl.h index bdeb01b..4791d64 100644 --- a/webkit/glue/webkitclient_impl.h +++ b/webkit/glue/webkitclient_impl.h @@ -38,12 +38,14 @@ class WebKitClientImpl : public WebKit::WebKitClient { virtual bool isDirectory(const WebKit::WebString& path); virtual WebKit::WebURL filePathToURL(const WebKit::WebString& path); virtual base::PlatformFile databaseOpenFile( - const WebKit::WebString& file_name, int desired_flags, + const WebKit::WebString& vfs_file_name, + int desired_flags, base::PlatformFile* dir_handle); - virtual int databaseDeleteFile(const WebKit::WebString& file_name, - bool sync_dir); - virtual long databaseGetFileAttributes(const WebKit::WebString& file_name); - virtual long long databaseGetFileSize(const WebKit::WebString& file_name); + virtual int databaseDeleteFile(const WebKit::WebString& vfs_file_name, + bool sync_dir); + virtual long databaseGetFileAttributes( + const WebKit::WebString& vfs_file_name); + virtual long long databaseGetFileSize(const WebKit::WebString& vfs_file_name); virtual WebKit::WebString signedPublicKeyAndChallengeString( unsigned key_size_index, const WebKit::WebString& challenge, const WebKit::WebURL& url); |