diff options
Diffstat (limited to 'chrome/browser/renderer_host/database_dispatcher_host.h')
-rw-r--r-- | chrome/browser/renderer_host/database_dispatcher_host.h | 118 |
1 files changed, 84 insertions, 34 deletions
diff --git a/chrome/browser/renderer_host/database_dispatcher_host.h b/chrome/browser/renderer_host/database_dispatcher_host.h index fd403d2..5053138 100644 --- a/chrome/browser/renderer_host/database_dispatcher_host.h +++ b/chrome/browser/renderer_host/database_dispatcher_host.h @@ -6,55 +6,105 @@ #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" +#include "base/string16.h" +#include "ipc/ipc_message.h" +#include "webkit/database/database_tracker.h" -class ResourceMessageFilter; - -namespace IPC { -class Message; -} - -class DatabaseDispatcherHost { +class DatabaseDispatcherHost + : public base::RefCountedThreadSafe<DatabaseDispatcherHost>, + public webkit_database::DatabaseTracker::Observer { public: - DatabaseDispatcherHost(const FilePath& profile_path, - ResourceMessageFilter* resource_message_filter); - ~DatabaseDispatcherHost() {} + DatabaseDispatcherHost(webkit_database::DatabaseTracker* db_tracker, + IPC::Message::Sender* message_sender, + base::ProcessHandle process_handle); + void Shutdown(); - // Returns true iff the message is HTML5 DB related and was processed. bool OnMessageReceived(const IPC::Message& message, bool* message_was_ok); - private: - // Message handlers. - // Processes the request to return a handle to the given DB file. - void OnDatabaseOpenFile(const FilePath& file_name, + // VFS message handlers (IO thread) + void OnDatabaseOpenFile(const FilePath& vfs_file_name, int desired_flags, int32 message_id); - - // Processes the request to delete the given DB file. - void OnDatabaseDeleteFile(const FilePath& file_name, + void OnDatabaseDeleteFile(const FilePath& vfs_file_name, const bool& sync_dir, int32 message_id); - - // Processes the request to return the attributes of the given DB file. - void OnDatabaseGetFileAttributes(const FilePath& file_name, + void OnDatabaseGetFileAttributes(const FilePath& vfs_file_name, int32 message_id); - - // Processes the request to return the size of the given file. - void OnDatabaseGetFileSize(const FilePath& file_name, + void OnDatabaseGetFileSize(const FilePath& vfs_file_name, int32 message_id); - // Returns the directory where all DB files are stored. - FilePath GetDBDir(); + // Database tracker message handlers (IO thread) + void OnDatabaseOpened(const string16& origin_identifier, + const string16& database_name, + const string16& description, + int64 estimated_size); + void OnDatabaseModified(const string16& origin_identifier, + const string16& database_name); + void OnDatabaseClosed(const string16& origin_identifier, + const string16& database_name); + + // DatabaseTracker::Observer callback (file thread) + virtual void OnDatabaseSizeChanged(const string16& origin_identifier, + const string16& database_name, + int64 database_size, + int64 space_available); + + private: + void AddObserver(); + void RemoveObserver(); + FilePath GetDBFileFullPath(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, + int desired_flags, + int32 message_id); + void DatabaseDeleteFile(const FilePath& vfs_file_name, + bool sync_dir, + int32 message_id, + int reschedule_count); + void DatabaseGetFileAttributes(const FilePath& vfs_file_name, + int32 message_id); + void DatabaseGetFileSize(const FilePath& vfs_file_name, + int32 message_id); + + // Database tracker message handlers (file thread) + void DatabaseOpened(const string16& origin_identifier, + const string16& file_name, + const string16& description, + int64 estimated_size); + void DatabaseModified(const string16& origin_identifier, + const string16& database_name); + void DatabaseClosed(const string16& origin_identifier, + const string16& database_name); + + void AddAccessedOrigin(const string16& origin_identifier); + bool HasAccessedOrigin(const string16& origin_identifier); + + // The database tracker for the current profile. + scoped_refptr<webkit_database::DatabaseTracker> db_tracker_; + + // The sender to be used for sending out IPC messages. + IPC::Message::Sender* message_sender_; + + // The handle of this process. + const base::ProcessHandle process_handle_; - // Returns the absolute name of the given DB file. - FilePath GetDBFileFullPath(const FilePath& file_name); + // True if and only if this instance was added as an observer + // to DatabaseTracker. + bool observer_added_; - // The user data directory. - FilePath profile_path_; + // If true, all messages that are normally processed by this class + // will be silently discarded. This field should be set to true + // only when the corresponding renderer process is about to go away. + bool shutdown_; - // The ResourceMessageFilter instance of this renderer process. Can't keep - // a refptr or else we'll get into a cycle. It's always ok to use this in - // the IO thread since if the RMF goes away, this object is deleted. - ResourceMessageFilter* resource_message_filter_; + base::hash_set<string16> accessed_origins_; }; #endif // CHROME_BROWSER_RENDERER_HOST_DATABASE_DISPATCHER_HOST_H_ |