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

Side by Side Diff: content/renderer/dom_storage/dom_storage_dispatcher.cc

Issue 12398008: Purge in-memory localStorage areas if the # of areas exceeds the limit (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 9 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) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/renderer/dom_storage/dom_storage_dispatcher.h" 5 #include "content/renderer/dom_storage/dom_storage_dispatcher.h"
6 6
7 #include <list> 7 #include <list>
8 #include <map> 8 #include <map>
9 9
10 #include "base/string_number_conversions.h" 10 #include "base/string_number_conversions.h"
11 #include "base/synchronization/lock.h" 11 #include "base/synchronization/lock.h"
12 #include "content/common/dom_storage_messages.h" 12 #include "content/common/dom_storage_messages.h"
13 #include "content/renderer/dom_storage/webstoragearea_impl.h" 13 #include "content/renderer/dom_storage/webstoragearea_impl.h"
14 #include "content/renderer/dom_storage/webstoragenamespace_impl.h" 14 #include "content/renderer/dom_storage/webstoragenamespace_impl.h"
15 #include "content/renderer/render_thread_impl.h" 15 #include "content/renderer/render_thread_impl.h"
16 #include "ipc/ipc_sync_message_filter.h"
16 #include "third_party/WebKit/Source/Platform/chromium/public/Platform.h" 17 #include "third_party/WebKit/Source/Platform/chromium/public/Platform.h"
17 #include "third_party/WebKit/Source/WebKit/chromium/public/WebKit.h" 18 #include "third_party/WebKit/Source/WebKit/chromium/public/WebKit.h"
18 #include "third_party/WebKit/Source/WebKit/chromium/public/WebStorageEventDispat cher.h" 19 #include "third_party/WebKit/Source/WebKit/chromium/public/WebStorageEventDispat cher.h"
19 #include "webkit/dom_storage/dom_storage_cached_area.h" 20 #include "webkit/dom_storage/dom_storage_cached_area.h"
20 #include "webkit/dom_storage/dom_storage_proxy.h" 21 #include "webkit/dom_storage/dom_storage_proxy.h"
21 #include "webkit/dom_storage/dom_storage_types.h" 22 #include "webkit/dom_storage/dom_storage_types.h"
22 23
23 using dom_storage::DomStorageCachedArea; 24 using dom_storage::DomStorageCachedArea;
24 using dom_storage::DomStorageProxy; 25 using dom_storage::DomStorageProxy;
25 using dom_storage::ValuesMap; 26 using dom_storage::ValuesMap;
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 // ProxyImpl ----------------------------------------------------- 97 // ProxyImpl -----------------------------------------------------
97 // An implementation of the DomStorageProxy interface in terms of IPC. 98 // An implementation of the DomStorageProxy interface in terms of IPC.
98 // This class also manages the collection of cached areas and pending 99 // This class also manages the collection of cached areas and pending
99 // operations awaiting completion callbacks. 100 // operations awaiting completion callbacks.
100 class DomStorageDispatcher::ProxyImpl : public DomStorageProxy { 101 class DomStorageDispatcher::ProxyImpl : public DomStorageProxy {
101 public: 102 public:
102 explicit ProxyImpl(RenderThreadImpl* sender); 103 explicit ProxyImpl(RenderThreadImpl* sender);
103 104
104 // Methods for use by DomStorageDispatcher directly. 105 // Methods for use by DomStorageDispatcher directly.
105 DomStorageCachedArea* OpenCachedArea( 106 DomStorageCachedArea* OpenCachedArea(
106 int64 namespace_id, const GURL& origin); 107 int64 namespace_id, const GURL& origin, int64 storage_size);
107 void CloseCachedArea(DomStorageCachedArea* area); 108 void CloseCachedArea(DomStorageCachedArea* area);
108 DomStorageCachedArea* LookupCachedArea( 109 DomStorageCachedArea* LookupCachedArea(
109 int64 namespace_id, const GURL& origin); 110 int64 namespace_id, const GURL& origin);
110 void CompleteOnePendingCallback(bool success); 111 void CompleteOnePendingCallback(bool success);
111 void Shutdown(); 112 void Shutdown();
112 113
113 // DomStorageProxy interface for use by DomStorageCachedArea. 114 // DomStorageProxy interface for use by DomStorageCachedArea.
114 virtual void LoadArea(int connection_id, ValuesMap* values, 115 virtual void LoadArea(int connection_id, ValuesMap* values,
115 const CompletionCallback& callback) OVERRIDE; 116 const CompletionCallback& callback) OVERRIDE;
116 virtual void SetItem(int connection_id, const string16& key, 117 virtual void SetItem(int connection_id, const string16& key,
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 scoped_refptr<MessageThrottlingFilter> throttling_filter_; 173 scoped_refptr<MessageThrottlingFilter> throttling_filter_;
173 }; 174 };
174 175
175 DomStorageDispatcher::ProxyImpl::ProxyImpl(RenderThreadImpl* sender) 176 DomStorageDispatcher::ProxyImpl::ProxyImpl(RenderThreadImpl* sender)
176 : sender_(sender), 177 : sender_(sender),
177 throttling_filter_(new MessageThrottlingFilter(sender)) { 178 throttling_filter_(new MessageThrottlingFilter(sender)) {
178 sender_->AddFilter(throttling_filter_); 179 sender_->AddFilter(throttling_filter_);
179 } 180 }
180 181
181 DomStorageCachedArea* DomStorageDispatcher::ProxyImpl::OpenCachedArea( 182 DomStorageCachedArea* DomStorageDispatcher::ProxyImpl::OpenCachedArea(
182 int64 namespace_id, const GURL& origin) { 183 int64 namespace_id, const GURL& origin, int64 storage_size) {
183 std::string key = GetCachedAreaKey(namespace_id, origin); 184 std::string key = GetCachedAreaKey(namespace_id, origin);
184 if (CachedAreaHolder* holder = GetAreaHolder(key)) { 185 if (CachedAreaHolder* holder = GetAreaHolder(key)) {
185 ++(holder->open_count_); 186 ++(holder->open_count_);
186 return holder->area_; 187 return holder->area_;
187 } 188 }
188 scoped_refptr<DomStorageCachedArea> area = 189 scoped_refptr<DomStorageCachedArea> area =
189 new DomStorageCachedArea(namespace_id, origin, this); 190 new DomStorageCachedArea(namespace_id, origin, this, storage_size);
190 cached_areas_[key] = CachedAreaHolder(area, 1); 191 cached_areas_[key] = CachedAreaHolder(area, 1);
191 return area.get(); 192 return area.get();
192 } 193 }
193 194
194 void DomStorageDispatcher::ProxyImpl::CloseCachedArea( 195 void DomStorageDispatcher::ProxyImpl::CloseCachedArea(
195 DomStorageCachedArea* area) { 196 DomStorageCachedArea* area) {
196 std::string key = GetCachedAreaKey(area->namespace_id(), area->origin()); 197 std::string key = GetCachedAreaKey(area->namespace_id(), area->origin());
197 CachedAreaHolder* holder = GetAreaHolder(key); 198 CachedAreaHolder* holder = GetAreaHolder(key);
198 DCHECK(holder); 199 DCHECK(holder);
199 DCHECK_EQ(holder->area_.get(), area); 200 DCHECK_EQ(holder->area_.get(), area);
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
262 DomStorageDispatcher::DomStorageDispatcher() 263 DomStorageDispatcher::DomStorageDispatcher()
263 : proxy_(new ProxyImpl(RenderThreadImpl::current())) { 264 : proxy_(new ProxyImpl(RenderThreadImpl::current())) {
264 } 265 }
265 266
266 DomStorageDispatcher::~DomStorageDispatcher() { 267 DomStorageDispatcher::~DomStorageDispatcher() {
267 proxy_->Shutdown(); 268 proxy_->Shutdown();
268 } 269 }
269 270
270 scoped_refptr<DomStorageCachedArea> DomStorageDispatcher::OpenCachedArea( 271 scoped_refptr<DomStorageCachedArea> DomStorageDispatcher::OpenCachedArea(
271 int connection_id, int64 namespace_id, const GURL& origin) { 272 int connection_id, int64 namespace_id, const GURL& origin) {
273 /*
272 RenderThreadImpl::current()->Send( 274 RenderThreadImpl::current()->Send(
273 new DOMStorageHostMsg_OpenStorageArea( 275 new DOMStorageHostMsg_OpenStorageArea(
274 connection_id, namespace_id, origin)); 276 connection_id, namespace_id, origin));
275 return proxy_->OpenCachedArea(namespace_id, origin); 277 */
278 scoped_refptr<IPC::SyncMessageFilter> sync_msg_filter(
279 RenderThreadImpl::current()->sync_message_filter());
280 int64 storage_size = 0;
281 sync_msg_filter->Send(new DOMStorageHostMsg_OpenStorageArea(
282 connection_id, namespace_id, origin, &storage_size));
283 return proxy_->OpenCachedArea(namespace_id, origin, storage_size);
276 } 284 }
277 285
278 void DomStorageDispatcher::CloseCachedArea( 286 void DomStorageDispatcher::CloseCachedArea(
279 int connection_id, DomStorageCachedArea* area) { 287 int connection_id, DomStorageCachedArea* area) {
280 RenderThreadImpl::current()->Send( 288 RenderThreadImpl::current()->Send(
281 new DOMStorageHostMsg_CloseStorageArea(connection_id)); 289 new DOMStorageHostMsg_CloseStorageArea(connection_id));
282 proxy_->CloseCachedArea(area); 290 proxy_->CloseCachedArea(area);
283 } 291 }
284 292
285 bool DomStorageDispatcher::OnMessageReceived(const IPC::Message& msg) { 293 bool DomStorageDispatcher::OnMessageReceived(const IPC::Message& msg) {
286 bool handled = true; 294 bool handled = true;
287 IPC_BEGIN_MESSAGE_MAP(DomStorageDispatcher, msg) 295 IPC_BEGIN_MESSAGE_MAP(DomStorageDispatcher, msg)
288 IPC_MESSAGE_HANDLER(DOMStorageMsg_Event, OnStorageEvent) 296 IPC_MESSAGE_HANDLER(DOMStorageMsg_Event, OnStorageEvent)
289 IPC_MESSAGE_HANDLER(DOMStorageMsg_AsyncOperationComplete, 297 IPC_MESSAGE_HANDLER(DOMStorageMsg_AsyncOperationComplete,
290 OnAsyncOperationComplete) 298 OnAsyncOperationComplete)
291 IPC_MESSAGE_UNHANDLED(handled = false) 299 IPC_MESSAGE_UNHANDLED(handled = false)
292 IPC_END_MESSAGE_MAP() 300 IPC_END_MESSAGE_MAP()
293 return handled; 301 return handled;
294 } 302 }
295 303
296 void DomStorageDispatcher::OnStorageEvent( 304 void DomStorageDispatcher::OnStorageEvent(
297 const DOMStorageMsg_Event_Params& params) { 305 const DOMStorageMsg_Event_Params& params) {
298 RenderThreadImpl::current()->EnsureWebKitInitialized(); 306 RenderThreadImpl::current()->EnsureWebKitInitialized();
299 307
300 bool originated_in_process = params.connection_id != 0; 308 bool originated_in_process = params.connection_id != 0;
301 WebStorageAreaImpl* originating_area = NULL; 309 WebStorageAreaImpl* originating_area = NULL;
302 if (originated_in_process) { 310 if (originated_in_process) {
303 originating_area = WebStorageAreaImpl::FromConnectionId( 311 originating_area = WebStorageAreaImpl::FromConnectionId(
304 params.connection_id); 312 params.connection_id);
313 originating_area->cached_area()->set_global_storage_size(
314 params.storage_size);
305 } else { 315 } else {
306 DomStorageCachedArea* cached_area = proxy_->LookupCachedArea( 316 DomStorageCachedArea* cached_area = proxy_->LookupCachedArea(
307 params.namespace_id, params.origin); 317 params.namespace_id, params.origin);
308 if (cached_area) 318 if (cached_area) {
309 cached_area->ApplyMutation(params.key, params.new_value); 319 cached_area->ApplyMutation(params.key, params.new_value);
320 cached_area->set_global_storage_size(params.storage_size);
321 }
310 } 322 }
311 323
312 if (params.namespace_id == dom_storage::kLocalStorageNamespaceId) { 324 if (params.namespace_id == dom_storage::kLocalStorageNamespaceId) {
313 WebKit::WebStorageEventDispatcher::dispatchLocalStorageEvent( 325 WebKit::WebStorageEventDispatcher::dispatchLocalStorageEvent(
314 params.key, 326 params.key,
315 params.old_value, 327 params.old_value,
316 params.new_value, 328 params.new_value,
317 params.origin, 329 params.origin,
318 params.page_url, 330 params.page_url,
319 originating_area, 331 originating_area,
(...skipping 11 matching lines...) Expand all
331 originating_area, 343 originating_area,
332 originated_in_process); 344 originated_in_process);
333 } 345 }
334 } 346 }
335 347
336 void DomStorageDispatcher::OnAsyncOperationComplete(bool success) { 348 void DomStorageDispatcher::OnAsyncOperationComplete(bool success) {
337 proxy_->CompleteOnePendingCallback(success); 349 proxy_->CompleteOnePendingCallback(success);
338 } 350 }
339 351
340 } // namespace content 352 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698