Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(148)

Side by Side Diff: chrome/browser/in_process_webkit/dom_storage_dispatcher_host.h

Issue 223013: Another stab at the Chromium side of storage events. The WebKit side can be ... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 11 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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" 8 #include "base/hash_tables.h"
9 #include "base/process.h" 9 #include "base/process.h"
10 #include "base/ref_counted.h" 10 #include "base/ref_counted.h"
(...skipping 11 matching lines...) Expand all
22 class DOMStorageDispatcherHost : 22 class DOMStorageDispatcherHost :
23 public base::RefCountedThreadSafe<DOMStorageDispatcherHost> { 23 public base::RefCountedThreadSafe<DOMStorageDispatcherHost> {
24 public: 24 public:
25 // Only call the constructor from the UI thread. 25 // Only call the constructor from the UI thread.
26 DOMStorageDispatcherHost(IPC::Message::Sender* message_sender, 26 DOMStorageDispatcherHost(IPC::Message::Sender* message_sender,
27 WebKitContext* webkit_context, WebKitThread* webkit_thread); 27 WebKitContext* webkit_context, WebKitThread* webkit_thread);
28 28
29 // Only call from ResourceMessageFilter on the IO thread. 29 // Only call from ResourceMessageFilter on the IO thread.
30 void Init(base::ProcessHandle process_handle); 30 void Init(base::ProcessHandle process_handle);
31 31
32 // Only call from ResourceMessageFilter on the IO thread. Calls self on the
33 // WebKit thread in some cases.
34 void Shutdown();
35
32 // Only call from ResourceMessageFilter on the IO thread. 36 // Only call from ResourceMessageFilter on the IO thread.
33 void Shutdown();
34 bool OnMessageReceived(const IPC::Message& message, bool *msg_is_ok); 37 bool OnMessageReceived(const IPC::Message& message, bool *msg_is_ok);
35 38
36 // Send a message to the renderer process associated with our 39 // Send a message to the renderer process associated with our
37 // message_sender_ via the IO thread. May be called from any thread. 40 // message_sender_ via the IO thread. May be called from any thread.
38 void Send(IPC::Message* message); 41 void Send(IPC::Message* message);
39 42
43 // Only call on the WebKit thread.
44 static void DispatchStorageEvent(const string16& key,
45 const NullableString16& old_value, const NullableString16& new_value,
46 const string16& origin, bool is_local_storage);
47
40 private: 48 private:
41 friend class base::RefCountedThreadSafe<DOMStorageDispatcherHost>; 49 friend class base::RefCountedThreadSafe<DOMStorageDispatcherHost>;
42 ~DOMStorageDispatcherHost(); 50 ~DOMStorageDispatcherHost();
43 51
44 // Message Handlers. 52 // Message Handlers.
45 void OnNamespaceId(DOMStorageType storage_type, IPC::Message* reply_msg); 53 void OnNamespaceId(DOMStorageType storage_type, IPC::Message* reply_msg);
46 void OnCloneNamespaceId(int64 namespace_id, IPC::Message* reply_msg); 54 void OnCloneNamespaceId(int64 namespace_id, IPC::Message* reply_msg);
47 void OnStorageAreaId(int64 namespace_id, const string16& origin, 55 void OnStorageAreaId(int64 namespace_id, const string16& origin,
48 IPC::Message* reply_msg); 56 IPC::Message* reply_msg);
49 void OnLength(int64 storage_area_id, IPC::Message* reply_msg); 57 void OnLength(int64 storage_area_id, IPC::Message* reply_msg);
50 void OnKey(int64 storage_area_id, unsigned index, IPC::Message* reply_msg); 58 void OnKey(int64 storage_area_id, unsigned index, IPC::Message* reply_msg);
51 void OnGetItem(int64 storage_area_id, const string16& key, 59 void OnGetItem(int64 storage_area_id, const string16& key,
52 IPC::Message* reply_msg); 60 IPC::Message* reply_msg);
53 void OnSetItem(int64 storage_area_id, const string16& key, 61 void OnSetItem(int64 storage_area_id, const string16& key,
54 const string16& value); 62 const string16& value);
55 void OnRemoveItem(int64 storage_area_id, const string16& key); 63 void OnRemoveItem(int64 storage_area_id, const string16& key);
56 void OnClear(int64 storage_area_id); 64 void OnClear(int64 storage_area_id);
57 65
66 // Only call on the IO thread.
67 void OnStorageEvent(const string16& key, const NullableString16& old_value,
68 const NullableString16& new_value, const string16& origin,
69 bool is_local_storage);
70
58 // A shortcut for accessing our context. 71 // A shortcut for accessing our context.
59 DOMStorageContext* Context() { 72 DOMStorageContext* Context() {
60 DCHECK(!shutdown_); 73 DCHECK(!shutdown_);
61 return webkit_context_->GetDOMStorageContext(); 74 return webkit_context_->dom_storage_context();
62 } 75 }
63 76
77 // Use whenever there's a chance OnStorageEvent will be called.
78 class AutoSetCurrentDispatcherHost {
79 public:
80 AutoSetCurrentDispatcherHost(DOMStorageDispatcherHost* dispatcher_host);
81 ~AutoSetCurrentDispatcherHost();
82 };
83
84 // Only access on the WebKit thread! Used for storage events.
85 static DOMStorageDispatcherHost* current_;
86
64 // Data shared between renderer processes with the same profile. 87 // Data shared between renderer processes with the same profile.
65 scoped_refptr<WebKitContext> webkit_context_; 88 scoped_refptr<WebKitContext> webkit_context_;
66 89
67 // ResourceDispatcherHost takes care of destruction. Immutable. 90 // ResourceDispatcherHost takes care of destruction. Immutable.
68 WebKitThread* webkit_thread_; 91 WebKitThread* webkit_thread_;
69 92
70 // Only set on the IO thread. 93 // Only set on the IO thread.
71 IPC::Message::Sender* message_sender_; 94 IPC::Message::Sender* message_sender_;
72 95
73 // If we get a corrupt message from a renderer, we need to kill it using this 96 // If we get a corrupt message from a renderer, we need to kill it using this
74 // handle. 97 // handle.
75 base::ProcessHandle process_handle_; 98 base::ProcessHandle process_handle_;
76 99
77 // Has this dispatcher ever handled a message. If not, then we can skip 100 // Has this dispatcher ever handled a message. If not, then we can skip
78 // the entire shutdown procedure. This is only set to true on the IO thread 101 // the entire shutdown procedure. This is only set to true on the IO thread
79 // and must be true if we're reading it on the WebKit thread. 102 // and must be true if we're reading it on the WebKit thread.
80 bool ever_used_; 103 bool ever_used_;
81 104
82 // This is set once the Shutdown routine runs on the WebKit thread. Once 105 // This is set once the Shutdown routine runs on the WebKit thread. Once
83 // set, we should not process any more messages because storage_area_map_ 106 // set, we should not process any more messages because storage_area_map_
84 // and storage_namespace_map_ contain pointers to deleted objects. 107 // and storage_namespace_map_ contain pointers to deleted objects.
85 bool shutdown_; 108 bool shutdown_;
86 109
87 DISALLOW_IMPLICIT_CONSTRUCTORS(DOMStorageDispatcherHost); 110 DISALLOW_IMPLICIT_CONSTRUCTORS(DOMStorageDispatcherHost);
88 }; 111 };
89 112
113 #if defined(COMPILER_GCC)
114 namespace __gnu_cxx {
115
116 template<>
117 struct hash<DOMStorageDispatcherHost*> {
118 std::size_t operator()(DOMStorageDispatcherHost* const& p) const {
119 return reinterpret_cast<std::size_t>(p);
120 }
121 };
122
123 } // namespace __gnu_cxx
124 #endif
125
90 #endif // CHROME_BROWSER_IN_PROCESS_WEBKIT_DOM_STORAGE_DISPATCHER_HOST_H_ 126 #endif // CHROME_BROWSER_IN_PROCESS_WEBKIT_DOM_STORAGE_DISPATCHER_HOST_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698