| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROME_BROWSER_RENDERER_HOST_DATABASE_DISPATCHER_HOST_H_ | 5 #ifndef CHROME_BROWSER_RENDERER_HOST_DATABASE_DISPATCHER_HOST_H_ |
| 6 #define CHROME_BROWSER_RENDERER_HOST_DATABASE_DISPATCHER_HOST_H_ | 6 #define CHROME_BROWSER_RENDERER_HOST_DATABASE_DISPATCHER_HOST_H_ |
| 7 | 7 |
| 8 #include "base/file_path.h" | 8 #include "base/file_path.h" |
| 9 #include "base/hash_tables.h" |
| 10 #include "base/process.h" |
| 11 #include "base/ref_counted.h" |
| 12 #include "base/string16.h" |
| 13 #include "ipc/ipc_message.h" |
| 14 #include "webkit/database/database_tracker.h" |
| 9 | 15 |
| 10 class ResourceMessageFilter; | 16 class DatabaseDispatcherHost |
| 17 : public base::RefCountedThreadSafe<DatabaseDispatcherHost>, |
| 18 public webkit_database::DatabaseTracker::Observer { |
| 19 public: |
| 20 DatabaseDispatcherHost(webkit_database::DatabaseTracker* db_tracker, |
| 21 IPC::Message::Sender* message_sender, |
| 22 base::ProcessHandle process_handle); |
| 23 void Shutdown(); |
| 11 | 24 |
| 12 namespace IPC { | |
| 13 class Message; | |
| 14 } | |
| 15 | |
| 16 class DatabaseDispatcherHost { | |
| 17 public: | |
| 18 DatabaseDispatcherHost(const FilePath& profile_path, | |
| 19 ResourceMessageFilter* resource_message_filter); | |
| 20 ~DatabaseDispatcherHost() {} | |
| 21 | |
| 22 // Returns true iff the message is HTML5 DB related and was processed. | |
| 23 bool OnMessageReceived(const IPC::Message& message, bool* message_was_ok); | 25 bool OnMessageReceived(const IPC::Message& message, bool* message_was_ok); |
| 24 | 26 |
| 25 private: | 27 // VFS message handlers (IO thread) |
| 26 // Message handlers. | 28 void OnDatabaseOpenFile(const FilePath& vfs_file_name, |
| 27 // Processes the request to return a handle to the given DB file. | |
| 28 void OnDatabaseOpenFile(const FilePath& file_name, | |
| 29 int desired_flags, | 29 int desired_flags, |
| 30 int32 message_id); | 30 int32 message_id); |
| 31 | 31 void OnDatabaseDeleteFile(const FilePath& vfs_file_name, |
| 32 // Processes the request to delete the given DB file. | |
| 33 void OnDatabaseDeleteFile(const FilePath& file_name, | |
| 34 const bool& sync_dir, | 32 const bool& sync_dir, |
| 35 int32 message_id); | 33 int32 message_id); |
| 36 | 34 void OnDatabaseGetFileAttributes(const FilePath& vfs_file_name, |
| 37 // Processes the request to return the attributes of the given DB file. | |
| 38 void OnDatabaseGetFileAttributes(const FilePath& file_name, | |
| 39 int32 message_id); | 35 int32 message_id); |
| 40 | 36 void OnDatabaseGetFileSize(const FilePath& vfs_file_name, |
| 41 // Processes the request to return the size of the given file. | |
| 42 void OnDatabaseGetFileSize(const FilePath& file_name, | |
| 43 int32 message_id); | 37 int32 message_id); |
| 44 | 38 |
| 45 // Returns the directory where all DB files are stored. | 39 // Database tracker message handlers (IO thread) |
| 46 FilePath GetDBDir(); | 40 void OnDatabaseOpened(const string16& origin_identifier, |
| 41 const string16& database_name, |
| 42 const string16& description, |
| 43 int64 estimated_size); |
| 44 void OnDatabaseModified(const string16& origin_identifier, |
| 45 const string16& database_name); |
| 46 void OnDatabaseClosed(const string16& origin_identifier, |
| 47 const string16& database_name); |
| 47 | 48 |
| 48 // Returns the absolute name of the given DB file. | 49 // DatabaseTracker::Observer callback (file thread) |
| 49 FilePath GetDBFileFullPath(const FilePath& file_name); | 50 virtual void OnDatabaseSizeChanged(const string16& origin_identifier, |
| 51 const string16& database_name, |
| 52 int64 database_size, |
| 53 int64 space_available); |
| 50 | 54 |
| 51 // The user data directory. | 55 private: |
| 52 FilePath profile_path_; | 56 void AddObserver(); |
| 57 void RemoveObserver(); |
| 58 FilePath GetDBFileFullPath(const FilePath& vfs_file_name); |
| 53 | 59 |
| 54 // The ResourceMessageFilter instance of this renderer process. Can't keep | 60 void ReceivedBadMessage(uint16 msg_type); |
| 55 // a refptr or else we'll get into a cycle. It's always ok to use this in | 61 void SendMessage(IPC::Message* message); |
| 56 // the IO thread since if the RMF goes away, this object is deleted. | 62 |
| 57 ResourceMessageFilter* resource_message_filter_; | 63 // VFS message handlers (file thread) |
| 64 void DatabaseOpenFile(const FilePath& vfs_file_name, |
| 65 int desired_flags, |
| 66 int32 message_id); |
| 67 void DatabaseDeleteFile(const FilePath& vfs_file_name, |
| 68 bool sync_dir, |
| 69 int32 message_id, |
| 70 int reschedule_count); |
| 71 void DatabaseGetFileAttributes(const FilePath& vfs_file_name, |
| 72 int32 message_id); |
| 73 void DatabaseGetFileSize(const FilePath& vfs_file_name, |
| 74 int32 message_id); |
| 75 |
| 76 // Database tracker message handlers (file thread) |
| 77 void DatabaseOpened(const string16& origin_identifier, |
| 78 const string16& file_name, |
| 79 const string16& description, |
| 80 int64 estimated_size); |
| 81 void DatabaseModified(const string16& origin_identifier, |
| 82 const string16& database_name); |
| 83 void DatabaseClosed(const string16& origin_identifier, |
| 84 const string16& database_name); |
| 85 |
| 86 void AddAccessedOrigin(const string16& origin_identifier); |
| 87 bool HasAccessedOrigin(const string16& origin_identifier); |
| 88 |
| 89 // The database tracker for the current profile. |
| 90 scoped_refptr<webkit_database::DatabaseTracker> db_tracker_; |
| 91 |
| 92 // The sender to be used for sending out IPC messages. |
| 93 IPC::Message::Sender* message_sender_; |
| 94 |
| 95 // The handle of this process. |
| 96 const base::ProcessHandle process_handle_; |
| 97 |
| 98 // True if and only if this instance was added as an observer |
| 99 // to DatabaseTracker. |
| 100 bool observer_added_; |
| 101 |
| 102 // If true, all messages that are normally processed by this class |
| 103 // will be silently discarded. This field should be set to true |
| 104 // only when the corresponding renderer process is about to go away. |
| 105 bool shutdown_; |
| 106 |
| 107 base::hash_set<string16> accessed_origins_; |
| 58 }; | 108 }; |
| 59 | 109 |
| 60 #endif // CHROME_BROWSER_RENDERER_HOST_DATABASE_DISPATCHER_HOST_H_ | 110 #endif // CHROME_BROWSER_RENDERER_HOST_DATABASE_DISPATCHER_HOST_H_ |
| OLD | NEW |