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 "chrome/browser/in_process_webkit/storage_area.h" | 11 #include "chrome/browser/in_process_webkit/storage_area.h" |
11 #include "chrome/browser/in_process_webkit/webkit_context.h" | 12 #include "chrome/browser/in_process_webkit/webkit_context.h" |
12 #include "chrome/common/dom_storage_type.h" | 13 #include "chrome/common/dom_storage_type.h" |
13 #include "ipc/ipc_message.h" | 14 #include "ipc/ipc_message.h" |
14 | 15 |
15 class DOMStorageContext; | 16 class DOMStorageContext; |
| 17 class Task; |
16 class WebKitThread; | 18 class WebKitThread; |
17 | 19 |
18 // This class handles the logistics of DOM Storage within the browser process. | 20 // This class handles the logistics of DOM Storage within the browser process. |
19 // It mostly ferries information between IPCs and the WebKit implementations, | 21 // It mostly ferries information between IPCs and the WebKit implementations, |
20 // but it also handles some special cases like when renderer processes die. | 22 // but it also handles some special cases like when renderer processes die. |
21 class DOMStorageDispatcherHost : | 23 class DOMStorageDispatcherHost : |
22 public base::RefCountedThreadSafe<DOMStorageDispatcherHost> { | 24 public base::RefCountedThreadSafe<DOMStorageDispatcherHost> { |
23 public: | 25 public: |
24 // Only call the constructor from the UI thread. | 26 // Only call the constructor from the UI thread. |
25 DOMStorageDispatcherHost(IPC::Message::Sender* message_sender, | 27 DOMStorageDispatcherHost(IPC::Message::Sender* message_sender, |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
62 void OnRemoveItem(int64 storage_area_id, const string16& key); | 64 void OnRemoveItem(int64 storage_area_id, const string16& key); |
63 void OnClear(int64 storage_area_id); | 65 void OnClear(int64 storage_area_id); |
64 | 66 |
65 // Only call on the IO thread. | 67 // Only call on the IO thread. |
66 void OnStorageEvent(const string16& key, const NullableString16& old_value, | 68 void OnStorageEvent(const string16& key, const NullableString16& old_value, |
67 const NullableString16& new_value, const string16& origin, | 69 const NullableString16& new_value, const string16& origin, |
68 bool is_local_storage); | 70 bool is_local_storage); |
69 | 71 |
70 // A shortcut for accessing our context. | 72 // A shortcut for accessing our context. |
71 DOMStorageContext* Context() { | 73 DOMStorageContext* Context() { |
72 DCHECK(!shutdown_); | |
73 return webkit_context_->dom_storage_context(); | 74 return webkit_context_->dom_storage_context(); |
74 } | 75 } |
75 | 76 |
| 77 // Posts a task to the WebKit thread, initializing it if necessary. |
| 78 void PostTaskToWebKitThread( |
| 79 const tracked_objects::Location& from_here, Task* task); |
| 80 |
76 // Use whenever there's a chance OnStorageEvent will be called. | 81 // Use whenever there's a chance OnStorageEvent will be called. |
77 class AutoSetCurrentDispatcherHost { | 82 class AutoSetCurrentDispatcherHost { |
78 public: | 83 public: |
79 AutoSetCurrentDispatcherHost(DOMStorageDispatcherHost* dispatcher_host); | 84 AutoSetCurrentDispatcherHost(DOMStorageDispatcherHost* dispatcher_host); |
80 ~AutoSetCurrentDispatcherHost(); | 85 ~AutoSetCurrentDispatcherHost(); |
81 }; | 86 }; |
82 | 87 |
83 // Only access on the WebKit thread! Used for storage events. | 88 // Only access on the WebKit thread! Used for storage events. |
84 static DOMStorageDispatcherHost* current_; | 89 static DOMStorageDispatcherHost* current_; |
85 | 90 |
86 // Data shared between renderer processes with the same profile. | 91 // Data shared between renderer processes with the same profile. |
87 scoped_refptr<WebKitContext> webkit_context_; | 92 scoped_refptr<WebKitContext> webkit_context_; |
88 | 93 |
89 // ResourceDispatcherHost takes care of destruction. Immutable. | 94 // ResourceDispatcherHost takes care of destruction. Immutable. |
90 WebKitThread* webkit_thread_; | 95 WebKitThread* webkit_thread_; |
91 | 96 |
92 // Only set on the IO thread. | 97 // Only set on the IO thread. |
93 IPC::Message::Sender* message_sender_; | 98 IPC::Message::Sender* message_sender_; |
94 | 99 |
95 // If we get a corrupt message from a renderer, we need to kill it using this | 100 // If we get a corrupt message from a renderer, we need to kill it using this |
96 // handle. | 101 // handle. |
97 base::ProcessHandle process_handle_; | 102 base::ProcessHandle process_handle_; |
98 | 103 |
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 | |
109 DISALLOW_IMPLICIT_CONSTRUCTORS(DOMStorageDispatcherHost); | 104 DISALLOW_IMPLICIT_CONSTRUCTORS(DOMStorageDispatcherHost); |
110 }; | 105 }; |
111 | 106 |
112 #endif // CHROME_BROWSER_IN_PROCESS_WEBKIT_DOM_STORAGE_DISPATCHER_HOST_H_ | 107 #endif // CHROME_BROWSER_IN_PROCESS_WEBKIT_DOM_STORAGE_DISPATCHER_HOST_H_ |
OLD | NEW |