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

Side by Side Diff: content/browser/in_process_webkit/dom_storage_context.cc

Issue 8879013: Deprecate WEBKIT thread (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: update after rebase Created 9 years 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/in_process_webkit/dom_storage_context.h" 5 #include "content/browser/in_process_webkit/dom_storage_context.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/file_path.h" 10 #include "base/file_path.h"
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 bool has_session_only_databases = 83 bool has_session_only_databases =
84 special_storage_policy_.get() && 84 special_storage_policy_.get() &&
85 special_storage_policy_->HasSessionOnlyOrigins(); 85 special_storage_policy_->HasSessionOnlyOrigins();
86 86
87 // Clearning only session-only databases, and there are none. 87 // Clearning only session-only databases, and there are none.
88 if (!clear_local_state_on_exit_ && !has_session_only_databases) 88 if (!clear_local_state_on_exit_ && !has_session_only_databases)
89 return; 89 return;
90 90
91 // Not being on the WEBKIT thread here means we are running in a unit test 91 // Not being on the WEBKIT thread here means we are running in a unit test
92 // where no clean up is needed. 92 // where no clean up is needed.
93 if (BrowserThread::CurrentlyOn(BrowserThread::WEBKIT)) { 93 if (BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED)) {
94 ClearLocalState(data_path_.Append(kLocalStorageDirectory), 94 ClearLocalState(data_path_.Append(kLocalStorageDirectory),
95 special_storage_policy_, 95 special_storage_policy_,
96 clear_local_state_on_exit_); 96 clear_local_state_on_exit_);
97 } 97 }
98 } 98 }
99 99
100 int64 DOMStorageContext::AllocateStorageAreaId() { 100 int64 DOMStorageContext::AllocateStorageAreaId() {
101 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT)); 101 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED));
102 return ++last_storage_area_id_; 102 return ++last_storage_area_id_;
103 } 103 }
104 104
105 int64 DOMStorageContext::AllocateSessionStorageNamespaceId() { 105 int64 DOMStorageContext::AllocateSessionStorageNamespaceId() {
106 if (BrowserThread::CurrentlyOn(BrowserThread::UI)) 106 if (BrowserThread::CurrentlyOn(BrowserThread::UI))
107 return ++last_session_storage_namespace_id_on_ui_thread_; 107 return ++last_session_storage_namespace_id_on_ui_thread_;
108 return --last_session_storage_namespace_id_on_io_thread_; 108 return --last_session_storage_namespace_id_on_io_thread_;
109 } 109 }
110 110
111 int64 DOMStorageContext::CloneSessionStorage(int64 original_id) { 111 int64 DOMStorageContext::CloneSessionStorage(int64 original_id) {
112 DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::WEBKIT)); 112 DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED));
113 int64 clone_id = AllocateSessionStorageNamespaceId(); 113 int64 clone_id = AllocateSessionStorageNamespaceId();
114 BrowserThread::PostTask( 114 BrowserThread::PostTask(
115 BrowserThread::WEBKIT, FROM_HERE, 115 BrowserThread::WEBKIT_DEPRECATED, FROM_HERE,
116 base::Bind(&DOMStorageContext::CompleteCloningSessionStorage, this, 116 base::Bind(&DOMStorageContext::CompleteCloningSessionStorage, this,
117 original_id, clone_id)); 117 original_id, clone_id));
118 return clone_id; 118 return clone_id;
119 } 119 }
120 120
121 void DOMStorageContext::RegisterStorageArea(DOMStorageArea* storage_area) { 121 void DOMStorageContext::RegisterStorageArea(DOMStorageArea* storage_area) {
122 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT)); 122 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED));
123 int64 id = storage_area->id(); 123 int64 id = storage_area->id();
124 DCHECK(!GetStorageArea(id)); 124 DCHECK(!GetStorageArea(id));
125 storage_area_map_[id] = storage_area; 125 storage_area_map_[id] = storage_area;
126 } 126 }
127 127
128 void DOMStorageContext::UnregisterStorageArea(DOMStorageArea* storage_area) { 128 void DOMStorageContext::UnregisterStorageArea(DOMStorageArea* storage_area) {
129 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT)); 129 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED));
130 int64 id = storage_area->id(); 130 int64 id = storage_area->id();
131 DCHECK(GetStorageArea(id)); 131 DCHECK(GetStorageArea(id));
132 storage_area_map_.erase(id); 132 storage_area_map_.erase(id);
133 } 133 }
134 134
135 DOMStorageArea* DOMStorageContext::GetStorageArea(int64 id) { 135 DOMStorageArea* DOMStorageContext::GetStorageArea(int64 id) {
136 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT)); 136 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED));
137 StorageAreaMap::iterator iter = storage_area_map_.find(id); 137 StorageAreaMap::iterator iter = storage_area_map_.find(id);
138 if (iter == storage_area_map_.end()) 138 if (iter == storage_area_map_.end())
139 return NULL; 139 return NULL;
140 return iter->second; 140 return iter->second;
141 } 141 }
142 142
143 void DOMStorageContext::DeleteSessionStorageNamespace(int64 namespace_id) { 143 void DOMStorageContext::DeleteSessionStorageNamespace(int64 namespace_id) {
144 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT)); 144 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED));
145 StorageNamespaceMap::iterator iter = 145 StorageNamespaceMap::iterator iter =
146 storage_namespace_map_.find(namespace_id); 146 storage_namespace_map_.find(namespace_id);
147 if (iter == storage_namespace_map_.end()) 147 if (iter == storage_namespace_map_.end())
148 return; 148 return;
149 DCHECK(iter->second->dom_storage_type() == DOM_STORAGE_SESSION); 149 DCHECK(iter->second->dom_storage_type() == DOM_STORAGE_SESSION);
150 delete iter->second; 150 delete iter->second;
151 storage_namespace_map_.erase(iter); 151 storage_namespace_map_.erase(iter);
152 } 152 }
153 153
154 DOMStorageNamespace* DOMStorageContext::GetStorageNamespace( 154 DOMStorageNamespace* DOMStorageContext::GetStorageNamespace(
155 int64 id, bool allocation_allowed) { 155 int64 id, bool allocation_allowed) {
156 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT)); 156 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED));
157 StorageNamespaceMap::iterator iter = storage_namespace_map_.find(id); 157 StorageNamespaceMap::iterator iter = storage_namespace_map_.find(id);
158 if (iter != storage_namespace_map_.end()) 158 if (iter != storage_namespace_map_.end())
159 return iter->second; 159 return iter->second;
160 if (!allocation_allowed) 160 if (!allocation_allowed)
161 return NULL; 161 return NULL;
162 if (id == kLocalStorageNamespaceId) 162 if (id == kLocalStorageNamespaceId)
163 return CreateLocalStorage(); 163 return CreateLocalStorage();
164 return CreateSessionStorage(id); 164 return CreateSessionStorage(id);
165 } 165 }
166 166
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 continue; 213 continue;
214 214
215 file_util::FileEnumerator::FindInfo find_info; 215 file_util::FileEnumerator::FindInfo find_info;
216 file_enumerator.GetFindInfo(&find_info); 216 file_enumerator.GetFindInfo(&find_info);
217 if (file_util::HasFileBeenModifiedSince(find_info, cutoff)) 217 if (file_util::HasFileBeenModifiedSince(find_info, cutoff))
218 file_util::Delete(path, false); 218 file_util::Delete(path, false);
219 } 219 }
220 } 220 }
221 221
222 void DOMStorageContext::DeleteLocalStorageFile(const FilePath& file_path) { 222 void DOMStorageContext::DeleteLocalStorageFile(const FilePath& file_path) {
223 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT)); 223 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED));
224 224
225 // Make sure that we don't delete a database that's currently being accessed 225 // Make sure that we don't delete a database that's currently being accessed
226 // by unloading all of the databases temporarily. 226 // by unloading all of the databases temporarily.
227 // TODO(bulach): both this method and DeleteDataModifiedSince could purge 227 // TODO(bulach): both this method and DeleteDataModifiedSince could purge
228 // only the memory used by the specific file instead of all memory at once. 228 // only the memory used by the specific file instead of all memory at once.
229 // See http://crbug.com/32000 229 // See http://crbug.com/32000
230 PurgeMemory(); 230 PurgeMemory();
231 file_util::Delete(file_path, false); 231 file_util::Delete(file_path, false);
232 } 232 }
233 233
234 void DOMStorageContext::DeleteLocalStorageForOrigin(const string16& origin_id) { 234 void DOMStorageContext::DeleteLocalStorageForOrigin(const string16& origin_id) {
235 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT)); 235 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED));
236 DeleteLocalStorageFile(GetLocalStorageFilePath(origin_id)); 236 DeleteLocalStorageFile(GetLocalStorageFilePath(origin_id));
237 } 237 }
238 238
239 void DOMStorageContext::DeleteAllLocalStorageFiles() { 239 void DOMStorageContext::DeleteAllLocalStorageFiles() {
240 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT)); 240 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED));
241 241
242 // Make sure that we don't delete a database that's currently being accessed 242 // Make sure that we don't delete a database that's currently being accessed
243 // by unloading all of the databases temporarily. 243 // by unloading all of the databases temporarily.
244 PurgeMemory(); 244 PurgeMemory();
245 245
246 file_util::FileEnumerator file_enumerator( 246 file_util::FileEnumerator file_enumerator(
247 data_path_.Append(kLocalStorageDirectory), false, 247 data_path_.Append(kLocalStorageDirectory), false,
248 file_util::FileEnumerator::FILES); 248 file_util::FileEnumerator::FILES);
249 for (FilePath file_path = file_enumerator.Next(); !file_path.empty(); 249 for (FilePath file_path = file_enumerator.Next(); !file_path.empty();
250 file_path = file_enumerator.Next()) { 250 file_path = file_enumerator.Next()) {
(...skipping 15 matching lines...) Expand all
266 DOMStorageNamespace* DOMStorageContext::CreateSessionStorage( 266 DOMStorageNamespace* DOMStorageContext::CreateSessionStorage(
267 int64 namespace_id) { 267 int64 namespace_id) {
268 DOMStorageNamespace* new_namespace = 268 DOMStorageNamespace* new_namespace =
269 DOMStorageNamespace::CreateSessionStorageNamespace(this, namespace_id); 269 DOMStorageNamespace::CreateSessionStorageNamespace(this, namespace_id);
270 RegisterStorageNamespace(new_namespace); 270 RegisterStorageNamespace(new_namespace);
271 return new_namespace; 271 return new_namespace;
272 } 272 }
273 273
274 void DOMStorageContext::RegisterStorageNamespace( 274 void DOMStorageContext::RegisterStorageNamespace(
275 DOMStorageNamespace* storage_namespace) { 275 DOMStorageNamespace* storage_namespace) {
276 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT)); 276 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED));
277 int64 id = storage_namespace->id(); 277 int64 id = storage_namespace->id();
278 DCHECK(!GetStorageNamespace(id, false)); 278 DCHECK(!GetStorageNamespace(id, false));
279 storage_namespace_map_[id] = storage_namespace; 279 storage_namespace_map_[id] = storage_namespace;
280 } 280 }
281 281
282 /* static */ 282 /* static */
283 void DOMStorageContext::CompleteCloningSessionStorage( 283 void DOMStorageContext::CompleteCloningSessionStorage(
284 DOMStorageContext* context, int64 existing_id, int64 clone_id) { 284 DOMStorageContext* context, int64 existing_id, int64 clone_id) {
285 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT)); 285 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED));
286 DOMStorageNamespace* existing_namespace = 286 DOMStorageNamespace* existing_namespace =
287 context->GetStorageNamespace(existing_id, false); 287 context->GetStorageNamespace(existing_id, false);
288 // If nothing exists, then there's nothing to clone. 288 // If nothing exists, then there's nothing to clone.
289 if (existing_namespace) 289 if (existing_namespace)
290 context->RegisterStorageNamespace(existing_namespace->Copy(clone_id)); 290 context->RegisterStorageNamespace(existing_namespace->Copy(clone_id));
291 } 291 }
292 292
293 FilePath DOMStorageContext::GetLocalStorageFilePath( 293 FilePath DOMStorageContext::GetLocalStorageFilePath(
294 const string16& origin_id) const { 294 const string16& origin_id) const {
295 FilePath storageDir = data_path_.Append( 295 FilePath storageDir = data_path_.Append(
296 DOMStorageContext::kLocalStorageDirectory); 296 DOMStorageContext::kLocalStorageDirectory);
297 FilePath::StringType id = 297 FilePath::StringType id =
298 webkit_glue::WebStringToFilePathString(origin_id); 298 webkit_glue::WebStringToFilePathString(origin_id);
299 return storageDir.Append(id.append(kLocalStorageExtension)); 299 return storageDir.Append(id.append(kLocalStorageExtension));
300 } 300 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698