Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / content / browser / renderer_host / database_message_filter.h
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef CONTENT_BROWSER_RENDERER_HOST_DATABASE_MESSAGE_FILTER_H_
6 #define CONTENT_BROWSER_RENDERER_HOST_DATABASE_MESSAGE_FILTER_H_
7
8 #include "base/containers/hash_tables.h"
9 #include "base/strings/string16.h"
10 #include "content/public/browser/browser_message_filter.h"
11 #include "storage/browser/database/database_tracker.h"
12 #include "storage/common/database/database_connections.h"
13 #include "storage/common/quota/quota_types.h"
14
15 namespace content {
16
17 class DatabaseMessageFilter : public BrowserMessageFilter,
18                               public storage::DatabaseTracker::Observer {
19  public:
20   explicit DatabaseMessageFilter(storage::DatabaseTracker* db_tracker);
21
22   // BrowserMessageFilter implementation.
23   virtual void OnChannelClosing() OVERRIDE;
24   virtual void OverrideThreadForMessage(
25       const IPC::Message& message,
26       BrowserThread::ID* thread) OVERRIDE;
27   virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
28
29   storage::DatabaseTracker* database_tracker() const {
30     return db_tracker_.get();
31   }
32
33  private:
34   virtual ~DatabaseMessageFilter();
35
36   class PromptDelegate;
37
38   void AddObserver();
39   void RemoveObserver();
40
41   // VFS message handlers (file thread)
42   void OnDatabaseOpenFile(const base::string16& vfs_file_name,
43                           int desired_flags,
44                           IPC::Message* reply_msg);
45   void OnDatabaseDeleteFile(const base::string16& vfs_file_name,
46                             const bool& sync_dir,
47                             IPC::Message* reply_msg);
48   void OnDatabaseGetFileAttributes(const base::string16& vfs_file_name,
49                                    IPC::Message* reply_msg);
50   void OnDatabaseGetFileSize(const base::string16& vfs_file_name,
51                              IPC::Message* reply_msg);
52
53   // Quota message handler (io thread)
54   void OnDatabaseGetSpaceAvailable(const std::string& origin_identifier,
55                                    IPC::Message* reply_msg);
56   void OnDatabaseGetUsageAndQuota(IPC::Message* reply_msg,
57                                   storage::QuotaStatusCode status,
58                                   int64 usage,
59                                   int64 quota);
60
61   // Database tracker message handlers (file thread)
62   void OnDatabaseOpened(const std::string& origin_identifier,
63                         const base::string16& database_name,
64                         const base::string16& description,
65                         int64 estimated_size);
66   void OnDatabaseModified(const std::string& origin_identifier,
67                           const base::string16& database_name);
68   void OnDatabaseClosed(const std::string& origin_identifier,
69                         const base::string16& database_name);
70   void OnHandleSqliteError(const std::string& origin_identifier,
71                            const base::string16& database_name,
72                            int error);
73
74   // DatabaseTracker::Observer callbacks (file thread)
75   virtual void OnDatabaseSizeChanged(const std::string& origin_identifier,
76                                      const base::string16& database_name,
77                                      int64 database_size) OVERRIDE;
78   virtual void OnDatabaseScheduledForDeletion(
79       const std::string& origin_identifier,
80       const base::string16& database_name) OVERRIDE;
81
82   void DatabaseDeleteFile(const base::string16& vfs_file_name,
83                           bool sync_dir,
84                           IPC::Message* reply_msg,
85                           int reschedule_count);
86
87   // The database tracker for the current browser context.
88   scoped_refptr<storage::DatabaseTracker> db_tracker_;
89
90   // True if and only if this instance was added as an observer
91   // to DatabaseTracker.
92   bool observer_added_;
93
94   // Keeps track of all DB connections opened by this renderer
95   storage::DatabaseConnections database_connections_;
96 };
97
98 }  // namespace content
99
100 #endif  // CONTENT_BROWSER_RENDERER_HOST_DATABASE_MESSAGE_FILTER_H_