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

Side by Side Diff: content/browser/dom_storage/dom_storage_message_filter.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/browser/dom_storage/dom_storage_message_filter.h" 5 #include "content/browser/dom_storage/dom_storage_message_filter.h"
6 6
7 #include "base/auto_reset.h" 7 #include "base/auto_reset.h"
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/stringprintf.h"
9 #include "base/nullable_string16.h" 10 #include "base/nullable_string16.h"
10 #include "base/threading/sequenced_worker_pool.h" 11 #include "base/threading/sequenced_worker_pool.h"
11 #include "base/utf_string_conversions.h" 12 #include "base/utf_string_conversions.h"
12 #include "content/public/browser/user_metrics.h" 13 #include "content/public/browser/user_metrics.h"
13 #include "content/browser/dom_storage/dom_storage_context_impl.h" 14 #include "content/browser/dom_storage/dom_storage_context_impl.h"
14 #include "content/common/dom_storage_messages.h" 15 #include "content/common/dom_storage_messages.h"
15 #include "googleurl/src/gurl.h" 16 #include "googleurl/src/gurl.h"
16 #include "webkit/dom_storage/dom_storage_area.h" 17 #include "webkit/dom_storage/dom_storage_area.h"
17 #include "webkit/dom_storage/dom_storage_host.h" 18 #include "webkit/dom_storage/dom_storage_host.h"
18 #include "webkit/dom_storage/dom_storage_task_runner.h" 19 #include "webkit/dom_storage/dom_storage_task_runner.h"
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 IPC_MESSAGE_HANDLER(DOMStorageHostMsg_RemoveItem, OnRemoveItem) 89 IPC_MESSAGE_HANDLER(DOMStorageHostMsg_RemoveItem, OnRemoveItem)
89 IPC_MESSAGE_HANDLER(DOMStorageHostMsg_Clear, OnClear) 90 IPC_MESSAGE_HANDLER(DOMStorageHostMsg_Clear, OnClear)
90 IPC_MESSAGE_HANDLER(DOMStorageHostMsg_FlushMessages, OnFlushMessages) 91 IPC_MESSAGE_HANDLER(DOMStorageHostMsg_FlushMessages, OnFlushMessages)
91 IPC_MESSAGE_UNHANDLED(handled = false) 92 IPC_MESSAGE_UNHANDLED(handled = false)
92 IPC_END_MESSAGE_MAP() 93 IPC_END_MESSAGE_MAP()
93 return handled; 94 return handled;
94 } 95 }
95 96
96 void DOMStorageMessageFilter::OnOpenStorageArea(int connection_id, 97 void DOMStorageMessageFilter::OnOpenStorageArea(int connection_id,
97 int64 namespace_id, 98 int64 namespace_id,
98 const GURL& origin) { 99 const GURL& origin,
100 int64* storage_size) {
99 DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::IO)); 101 DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::IO));
100 if (!host_->OpenStorageArea(connection_id, namespace_id, origin)) { 102 if (!host_->OpenStorageArea(connection_id, namespace_id, origin)) {
101 RecordAction(UserMetricsAction("BadMessageTerminate_DSMF_1")); 103 RecordAction(UserMetricsAction("BadMessageTerminate_DSMF_1"));
102 BadMessageReceived(); 104 BadMessageReceived();
103 } 105 }
106 *storage_size = context_->GetInMemoryStorageSize();
104 } 107 }
105 108
106 void DOMStorageMessageFilter::OnCloseStorageArea(int connection_id) { 109 void DOMStorageMessageFilter::OnCloseStorageArea(int connection_id) {
107 DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::IO)); 110 DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::IO));
108 host_->CloseStorageArea(connection_id); 111 host_->CloseStorageArea(connection_id);
109 } 112 }
110 113
111 void DOMStorageMessageFilter::OnLoadStorageArea(int connection_id, 114 void DOMStorageMessageFilter::OnLoadStorageArea(int connection_id,
112 dom_storage::ValuesMap* map) { 115 dom_storage::ValuesMap* map) {
113 DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::IO)); 116 DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::IO));
114 if (!host_->ExtractAreaValues(connection_id, map)) { 117 if (!host_->ExtractAreaValues(connection_id, map)) {
115 RecordAction(UserMetricsAction("BadMessageTerminate_DSMF_2")); 118 RecordAction(UserMetricsAction("BadMessageTerminate_DSMF_2"));
116 BadMessageReceived(); 119 BadMessageReceived();
117 } 120 }
118 Send(new DOMStorageMsg_AsyncOperationComplete(true)); 121 Send(new DOMStorageMsg_AsyncOperationComplete(true));
119 } 122 }
120 123
121 void DOMStorageMessageFilter::OnSetItem( 124 void DOMStorageMessageFilter::OnSetItem(
122 int connection_id, const string16& key, 125 int connection_id, const string16& key,
123 const string16& value, const GURL& page_url) { 126 const string16& value, const GURL& page_url) {
124 DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::IO)); 127 DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::IO));
125 DCHECK_EQ(0, connection_dispatching_message_for_); 128 DCHECK_EQ(0, connection_dispatching_message_for_);
michaeln 2013/03/05 00:04:46 Since there is an async code path for localstorage
kinuko 2013/03/06 06:20:15 Updated to use the async IPC.
126 base::AutoReset<int> auto_reset(&connection_dispatching_message_for_, 129 base::AutoReset<int> auto_reset(&connection_dispatching_message_for_,
127 connection_id); 130 connection_id);
128 NullableString16 not_used; 131 NullableString16 not_used;
129 bool success = host_->SetAreaItem(connection_id, key, value, 132 bool success = host_->SetAreaItem(connection_id, key, value,
130 page_url, &not_used); 133 page_url, &not_used);
131 Send(new DOMStorageMsg_AsyncOperationComplete(success)); 134 Send(new DOMStorageMsg_AsyncOperationComplete(success));
132 } 135 }
133 136
134 void DOMStorageMessageFilter::OnRemoveItem( 137 void DOMStorageMessageFilter::OnRemoveItem(
135 int connection_id, const string16& key, 138 int connection_id, const string16& key,
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
201 if (originated_in_process || 204 if (originated_in_process ||
202 host_->HasAreaOpen(area->namespace_id(), area->origin())) { 205 host_->HasAreaOpen(area->namespace_id(), area->origin())) {
203 DOMStorageMsg_Event_Params params; 206 DOMStorageMsg_Event_Params params;
204 params.origin = area->origin(); 207 params.origin = area->origin();
205 params.page_url = page_url; 208 params.page_url = page_url;
206 params.connection_id = connection_dispatching_message_for_; 209 params.connection_id = connection_dispatching_message_for_;
207 params.key = key; 210 params.key = key;
208 params.new_value = new_value; 211 params.new_value = new_value;
209 params.old_value = old_value; 212 params.old_value = old_value;
210 params.namespace_id = area->namespace_id(); 213 params.namespace_id = area->namespace_id();
214 params.storage_size = context_->GetInMemoryStorageSize();
211 Send(new DOMStorageMsg_Event(params)); 215 Send(new DOMStorageMsg_Event(params));
212 } 216 }
213 } 217 }
214 218
215 } // namespace content 219 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/dom_storage/dom_storage_message_filter.h ('k') | content/common/dom_storage_messages.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698