OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. Use of this | 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. Use of this |
2 // source code is governed by a BSD-style license that can be found in the | 2 // source code is governed by a BSD-style license that can be found in the |
3 // LICENSE file. | 3 // LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_IN_PROCESS_WEBKIT_DOM_STORAGE_DISPATCHER_HOST_H_ | 5 #ifndef CHROME_BROWSER_IN_PROCESS_WEBKIT_DOM_STORAGE_DISPATCHER_HOST_H_ |
6 #define CHROME_BROWSER_IN_PROCESS_WEBKIT_DOM_STORAGE_DISPATCHER_HOST_H_ | 6 #define CHROME_BROWSER_IN_PROCESS_WEBKIT_DOM_STORAGE_DISPATCHER_HOST_H_ |
7 | 7 |
| 8 #include "base/hash_tables.h" |
| 9 #include "base/scoped_ptr.h" |
8 #include "base/ref_counted.h" | 10 #include "base/ref_counted.h" |
9 #include "ipc/ipc_message.h" | 11 #include "ipc/ipc_message.h" |
10 | 12 |
11 class WebKitContext; | 13 class WebKitContext; |
12 class WebKitThread; | 14 class WebKitThread; |
13 | 15 |
| 16 namespace WebKit { |
| 17 class WebStorageArea; |
| 18 class WebStorageNamespace; |
| 19 } |
| 20 |
14 // This class handles the logistics of DOM Storage within the browser process. | 21 // This class handles the logistics of DOM Storage within the browser process. |
15 // It mostly ferries information between IPCs and the WebKit implementations, | 22 // It mostly ferries information between IPCs and the WebKit implementations, |
16 // but it also handles some special cases like when renderer processes die. | 23 // but it also handles some special cases like when renderer processes die. |
17 // THIS CLASS MUST NOT BE DESTROYED ON THE WEBKIT THREAD. | |
18 class DOMStorageDispatcherHost : | 24 class DOMStorageDispatcherHost : |
19 public base::RefCountedThreadSafe<DOMStorageDispatcherHost> { | 25 public base::RefCountedThreadSafe<DOMStorageDispatcherHost> { |
20 public: | 26 public: |
21 // Only call the constructor from the UI thread. | 27 // Only call the constructor from the UI thread. |
22 DOMStorageDispatcherHost(IPC::Message::Sender* message_sender, | 28 DOMStorageDispatcherHost(IPC::Message::Sender* message_sender, |
23 WebKitContext*, WebKitThread*); | 29 WebKitContext*, WebKitThread*); |
24 | 30 |
25 // Only call from IO thread. | 31 // Only call from ResourceMessageFilter on the IO thread. |
26 bool OnMessageReceived(const IPC::Message& message); | 32 void Shutdown(); |
| 33 bool OnMessageReceived(const IPC::Message& message, bool *msg_is_ok); |
27 | 34 |
28 // Send a message to the renderer process associated with our | 35 // Send a message to the renderer process associated with our |
29 // message_sender_ via the IO thread. May be called from any thread. | 36 // message_sender_ via the IO thread. May be called from any thread. |
30 void Send(IPC::Message* message); | 37 void Send(IPC::Message* message); |
31 | 38 |
32 private: | 39 private: |
33 friend class base::RefCountedThreadSafe<DOMStorageDispatcherHost>; | 40 friend class base::RefCountedThreadSafe<DOMStorageDispatcherHost>; |
34 ~DOMStorageDispatcherHost(); | 41 ~DOMStorageDispatcherHost(); |
35 | 42 |
| 43 // Message Handlers. |
| 44 void OnNamespaceId(bool is_local_storage, IPC::Message* reply_msg); |
| 45 void OnCloneNamespaceId(int64 namespace_id, IPC::Message* reply_msg); |
| 46 void OnDerefNamespaceId(int64 namespace_id); |
| 47 void OnStorageAreaId(int64 namespace_id, const string16& origin, |
| 48 IPC::Message* reply_msg); |
| 49 void OnLock(int64 storage_area_id, IPC::Message* reply_msg); |
| 50 void OnUnlock(int64 storage_area_id); |
| 51 void OnLength(int64 storage_area_id, IPC::Message* reply_msg); |
| 52 void OnKey(int64 storage_area_id, unsigned index, IPC::Message* reply_msg); |
| 53 void OnGetItem(int64 storage_area_id, const string16& key, |
| 54 IPC::Message* reply_msg); |
| 55 void OnSetItem(int64 storage_area_id, const string16& key, |
| 56 const string16& value); |
| 57 void OnRemoveItem(int64 storage_area_id, const string16& key); |
| 58 void OnClear(int64 storage_area_id, IPC::Message* reply_msg); |
| 59 |
| 60 // Get a WebStorageNamespace or WebStorageArea based from its ID. Only call |
| 61 // on the WebKit thread. |
| 62 WebKit::WebStorageArea* GetStorageArea(int64 id); |
| 63 WebKit::WebStorageNamespace* GetStorageNamespace(int64 id); |
| 64 |
| 65 // Add a WebStorageNamespace or WebStorageArea and get a new unique ID for |
| 66 // it. Only call on the WebKit thread. |
| 67 int64 AddStorageArea(WebKit::WebStorageArea* new_storage_area); |
| 68 int64 AddStorageNamespace(WebKit::WebStorageNamespace* new_namespace); |
| 69 |
| 70 // Get the path to the LocalStorage directory. Calculate it if we haven't |
| 71 // already. Only call on the WebKit thread. |
| 72 string16 GetLocalStoragePath(); |
| 73 |
36 // Data shared between renderer processes with the same profile. | 74 // Data shared between renderer processes with the same profile. |
37 scoped_refptr<WebKitContext> webkit_context_; | 75 scoped_refptr<WebKitContext> webkit_context_; |
38 | 76 |
39 // ResourceDispatcherHost takes care of destruction. Immutable. | 77 // ResourceDispatcherHost takes care of destruction. Immutable. |
40 WebKitThread* webkit_thread_; | 78 WebKitThread* webkit_thread_; |
41 | 79 |
42 // Only set on the IO thread. | 80 // Only set on the IO thread. |
43 IPC::Message::Sender* message_sender_; | 81 IPC::Message::Sender* message_sender_; |
44 | 82 |
| 83 // The last used storage_area_id and storage_namespace_id's. Only use on the |
| 84 // WebKit thread. |
| 85 int64 last_storage_area_id_; |
| 86 int64 last_storage_namespace_id_; |
| 87 |
| 88 // Used to maintain a mapping between storage_area_id's used in IPC messages |
| 89 // and the actual WebStorageArea instances. Only use on the WebKit thread. |
| 90 typedef base::hash_map<int64, WebKit::WebStorageArea*> StorageAreaMap; |
| 91 StorageAreaMap storage_area_map_; |
| 92 |
| 93 // Mapping between storage_namespace_id's used in IPC messages and the |
| 94 // WebStorageNamespace instances. Only use on the WebKit thread. |
| 95 typedef base::hash_map<int64, WebKit::WebStorageNamespace*> |
| 96 StorageNamespaceMap; |
| 97 StorageNamespaceMap storage_namespace_map_; |
| 98 |
| 99 // Has this dispatcher ever handled a message. If not, then we can skip |
| 100 // the entire shutdown procedure. This is only set to true on the IO thread |
| 101 // and must be true if we're reading it on the WebKit thread. |
| 102 bool ever_used_; |
| 103 |
| 104 // This is set once the Shutdown routine runs on the WebKit thread. Once |
| 105 // set, we should not process any more messages because storage_area_map_ |
| 106 // and storage_namespace_map_ contain pointers to deleted objects. |
| 107 bool shutdown_; |
| 108 |
45 DISALLOW_IMPLICIT_CONSTRUCTORS(DOMStorageDispatcherHost); | 109 DISALLOW_IMPLICIT_CONSTRUCTORS(DOMStorageDispatcherHost); |
46 }; | 110 }; |
47 | 111 |
48 #endif // CHROME_BROWSER_IN_PROCESS_WEBKIT_DOM_STORAGE_DISPATCHER_HOST_H_ | 112 #endif // CHROME_BROWSER_IN_PROCESS_WEBKIT_DOM_STORAGE_DISPATCHER_HOST_H_ |
OLD | NEW |