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/process.h" | 8 #include "base/process.h" |
9 #include "base/ref_counted.h" | 9 #include "base/ref_counted.h" |
10 #include "base/tracked.h" | 10 #include "base/tracked.h" |
11 #include "chrome/browser/in_process_webkit/storage_area.h" | 11 #include "chrome/browser/in_process_webkit/storage_area.h" |
12 #include "chrome/browser/in_process_webkit/webkit_context.h" | 12 #include "chrome/browser/in_process_webkit/webkit_context.h" |
13 #include "chrome/common/dom_storage_type.h" | 13 #include "chrome/common/dom_storage_type.h" |
14 #include "ipc/ipc_message.h" | 14 #include "ipc/ipc_message.h" |
15 | 15 |
16 class DOMStorageContext; | 16 class DOMStorageContext; |
17 class Task; | 17 class Task; |
18 class WebKitThread; | 18 class WebKitThread; |
| 19 struct ViewMsg_DOMStorageEvent_Params; |
19 | 20 |
20 // 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. |
21 // It mostly ferries information between IPCs and the WebKit implementations, | 22 // It mostly ferries information between IPCs and the WebKit implementations, |
22 // 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. |
23 class DOMStorageDispatcherHost : | 24 class DOMStorageDispatcherHost : |
24 public base::RefCountedThreadSafe<DOMStorageDispatcherHost> { | 25 public base::RefCountedThreadSafe<DOMStorageDispatcherHost> { |
25 public: | 26 public: |
26 // Only call the constructor from the UI thread. | 27 // Only call the constructor from the UI thread. |
27 DOMStorageDispatcherHost(IPC::Message::Sender* message_sender, | 28 DOMStorageDispatcherHost(IPC::Message::Sender* message_sender, |
28 WebKitContext* webkit_context, WebKitThread* webkit_thread); | 29 WebKitContext* webkit_context, WebKitThread* webkit_thread); |
29 | 30 |
30 // Only call from ResourceMessageFilter on the IO thread. | 31 // Only call from ResourceMessageFilter on the IO thread. |
31 void Init(base::ProcessHandle process_handle); | 32 void Init(base::ProcessHandle process_handle); |
32 | 33 |
33 // Only call from ResourceMessageFilter on the IO thread. Calls self on the | 34 // Only call from ResourceMessageFilter on the IO thread. Calls self on the |
34 // WebKit thread in some cases. | 35 // WebKit thread in some cases. |
35 void Shutdown(); | 36 void Shutdown(); |
36 | 37 |
37 // Only call from ResourceMessageFilter on the IO thread. | 38 // Only call from ResourceMessageFilter on the IO thread. |
38 bool OnMessageReceived(const IPC::Message& message, bool *msg_is_ok); | 39 bool OnMessageReceived(const IPC::Message& message, bool *msg_is_ok); |
39 | 40 |
40 // Send a message to the renderer process associated with our | 41 // Send a message to the renderer process associated with our |
41 // message_sender_ via the IO thread. May be called from any thread. | 42 // message_sender_ via the IO thread. May be called from any thread. |
42 void Send(IPC::Message* message); | 43 void Send(IPC::Message* message); |
43 | 44 |
44 // Only call on the WebKit thread. | 45 // Only call on the WebKit thread. |
45 static void DispatchStorageEvent(const string16& key, | 46 static void DispatchStorageEvent(const NullableString16& key, |
46 const NullableString16& old_value, const NullableString16& new_value, | 47 const NullableString16& old_value, const NullableString16& new_value, |
47 const string16& origin, bool is_local_storage); | 48 const string16& origin, bool is_local_storage); |
48 | 49 |
49 private: | 50 private: |
50 friend class base::RefCountedThreadSafe<DOMStorageDispatcherHost>; | 51 friend class base::RefCountedThreadSafe<DOMStorageDispatcherHost>; |
51 ~DOMStorageDispatcherHost(); | 52 ~DOMStorageDispatcherHost(); |
52 | 53 |
53 // Message Handlers. | 54 // Message Handlers. |
54 void OnNamespaceId(DOMStorageType storage_type, IPC::Message* reply_msg); | 55 void OnNamespaceId(DOMStorageType storage_type, IPC::Message* reply_msg); |
55 void OnCloneNamespaceId(int64 namespace_id, IPC::Message* reply_msg); | 56 void OnCloneNamespaceId(int64 namespace_id, IPC::Message* reply_msg); |
56 void OnStorageAreaId(int64 namespace_id, const string16& origin, | 57 void OnStorageAreaId(int64 namespace_id, const string16& origin, |
57 IPC::Message* reply_msg); | 58 IPC::Message* reply_msg); |
58 void OnLength(int64 storage_area_id, IPC::Message* reply_msg); | 59 void OnLength(int64 storage_area_id, IPC::Message* reply_msg); |
59 void OnKey(int64 storage_area_id, unsigned index, IPC::Message* reply_msg); | 60 void OnKey(int64 storage_area_id, unsigned index, IPC::Message* reply_msg); |
60 void OnGetItem(int64 storage_area_id, const string16& key, | 61 void OnGetItem(int64 storage_area_id, const string16& key, |
61 IPC::Message* reply_msg); | 62 IPC::Message* reply_msg); |
62 void OnSetItem(int64 storage_area_id, const string16& key, | 63 void OnSetItem(int64 storage_area_id, const string16& key, |
63 const string16& value, IPC::Message* reply_msg); | 64 const string16& value, IPC::Message* reply_msg); |
64 void OnRemoveItem(int64 storage_area_id, const string16& key); | 65 void OnRemoveItem(int64 storage_area_id, const string16& key); |
65 void OnClear(int64 storage_area_id); | 66 void OnClear(int64 storage_area_id); |
66 | 67 |
67 // Only call on the IO thread. | 68 // Only call on the IO thread. |
68 void OnStorageEvent(const string16& key, const NullableString16& old_value, | 69 void OnStorageEvent(const ViewMsg_DOMStorageEvent_Params& params); |
69 const NullableString16& new_value, const string16& origin, | |
70 bool is_local_storage); | |
71 | 70 |
72 // A shortcut for accessing our context. | 71 // A shortcut for accessing our context. |
73 DOMStorageContext* Context() { | 72 DOMStorageContext* Context() { |
74 return webkit_context_->dom_storage_context(); | 73 return webkit_context_->dom_storage_context(); |
75 } | 74 } |
76 | 75 |
77 // Posts a task to the WebKit thread, initializing it if necessary. | 76 // Posts a task to the WebKit thread, initializing it if necessary. |
78 void PostTaskToWebKitThread( | 77 void PostTaskToWebKitThread( |
79 const tracked_objects::Location& from_here, Task* task); | 78 const tracked_objects::Location& from_here, Task* task); |
80 | 79 |
81 // Use whenever there's a chance OnStorageEvent will be called. | 80 // Use whenever there's a chance OnStorageEvent will be called. |
82 class AutoSetCurrentDispatcherHost { | 81 class ScopedStorageEventContext { |
83 public: | 82 public: |
84 AutoSetCurrentDispatcherHost(DOMStorageDispatcherHost* dispatcher_host); | 83 ScopedStorageEventContext(DOMStorageDispatcherHost* dispatcher_host); |
85 ~AutoSetCurrentDispatcherHost(); | 84 ~ScopedStorageEventContext(); |
86 }; | 85 }; |
87 | 86 |
88 // Only access on the WebKit thread! Used for storage events. | 87 // Only access on the WebKit thread! Used for storage events. |
89 static DOMStorageDispatcherHost* current_; | 88 static DOMStorageDispatcherHost* storage_event_host_; |
90 | 89 |
91 // Data shared between renderer processes with the same profile. | 90 // Data shared between renderer processes with the same profile. |
92 scoped_refptr<WebKitContext> webkit_context_; | 91 scoped_refptr<WebKitContext> webkit_context_; |
93 | 92 |
94 // ResourceDispatcherHost takes care of destruction. Immutable. | 93 // ResourceDispatcherHost takes care of destruction. Immutable. |
95 WebKitThread* webkit_thread_; | 94 WebKitThread* webkit_thread_; |
96 | 95 |
97 // Only set on the IO thread. | 96 // Only set on the IO thread. |
98 IPC::Message::Sender* message_sender_; | 97 IPC::Message::Sender* message_sender_; |
99 | 98 |
100 // If we get a corrupt message from a renderer, we need to kill it using this | 99 // If we get a corrupt message from a renderer, we need to kill it using this |
101 // handle. | 100 // handle. |
102 base::ProcessHandle process_handle_; | 101 base::ProcessHandle process_handle_; |
103 | 102 |
104 DISALLOW_IMPLICIT_CONSTRUCTORS(DOMStorageDispatcherHost); | 103 DISALLOW_IMPLICIT_CONSTRUCTORS(DOMStorageDispatcherHost); |
105 }; | 104 }; |
106 | 105 |
107 #endif // CHROME_BROWSER_IN_PROCESS_WEBKIT_DOM_STORAGE_DISPATCHER_HOST_H_ | 106 #endif // CHROME_BROWSER_IN_PROCESS_WEBKIT_DOM_STORAGE_DISPATCHER_HOST_H_ |
OLD | NEW |