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

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

Issue 9704048: Make the content::DOMStorageContext methods callable on the main thread and hide the threading deta… (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 8 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) 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_impl.h" 5 #include "content/browser/in_process_webkit/dom_storage_context_impl.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 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 // because it is backed by disk and can be reloaded later. If we purge a 197 // because it is backed by disk and can be reloaded later. If we purge a
198 // SessionStorage namespace, its data will be gone forever, because it isn't 198 // SessionStorage namespace, its data will be gone forever, because it isn't
199 // currently backed by disk. 199 // currently backed by disk.
200 DOMStorageNamespace* local_storage = 200 DOMStorageNamespace* local_storage =
201 GetStorageNamespace(kLocalStorageNamespaceId, false); 201 GetStorageNamespace(kLocalStorageNamespaceId, false);
202 if (local_storage) 202 if (local_storage)
203 local_storage->PurgeMemory(); 203 local_storage->PurgeMemory();
204 } 204 }
205 205
206 void DOMStorageContextImpl::DeleteDataModifiedSince(const base::Time& cutoff) { 206 void DOMStorageContextImpl::DeleteDataModifiedSince(const base::Time& cutoff) {
207 if (!webkit_message_loop_->RunsTasksOnCurrentThread()) {
208 webkit_message_loop_->PostTask(
209 FROM_HERE,
210 base::Bind(
211 &DOMStorageContextImpl::DeleteDataModifiedSince, this, cutoff));
212 return;
213 }
214
207 // Make sure that we don't delete a database that's currently being accessed 215 // Make sure that we don't delete a database that's currently being accessed
208 // by unloading all of the databases temporarily. 216 // by unloading all of the databases temporarily.
209 PurgeMemory(); 217 PurgeMemory();
210 218
211 file_util::FileEnumerator file_enumerator( 219 file_util::FileEnumerator file_enumerator(
212 data_path_.Append(kLocalStorageDirectory), false, 220 data_path_.Append(kLocalStorageDirectory), false,
213 file_util::FileEnumerator::FILES); 221 file_util::FileEnumerator::FILES);
214 for (FilePath path = file_enumerator.Next(); !path.value().empty(); 222 for (FilePath path = file_enumerator.Next(); !path.value().empty();
215 path = file_enumerator.Next()) { 223 path = file_enumerator.Next()) {
216 GURL origin(WebSecurityOrigin::createFromDatabaseIdentifier( 224 GURL origin(WebSecurityOrigin::createFromDatabaseIdentifier(
217 webkit_glue::FilePathToWebString(path.BaseName())).toString()); 225 webkit_glue::FilePathToWebString(path.BaseName())).toString());
218 if (special_storage_policy_->IsStorageProtected(origin)) 226 if (special_storage_policy_->IsStorageProtected(origin))
219 continue; 227 continue;
220 228
221 file_util::FileEnumerator::FindInfo find_info; 229 file_util::FileEnumerator::FindInfo find_info;
222 file_enumerator.GetFindInfo(&find_info); 230 file_enumerator.GetFindInfo(&find_info);
223 if (file_util::HasFileBeenModifiedSince(find_info, cutoff)) 231 if (file_util::HasFileBeenModifiedSince(find_info, cutoff))
224 file_util::Delete(path, false); 232 file_util::Delete(path, false);
225 } 233 }
226 } 234 }
227 235
228 void DOMStorageContextImpl::DeleteLocalStorageFile(const FilePath& file_path) { 236 void DOMStorageContextImpl::DeleteLocalStorageFile(const FilePath& file_path) {
229 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED)); 237 if (!webkit_message_loop_->RunsTasksOnCurrentThread()) {
238 webkit_message_loop_->PostTask(
239 FROM_HERE,
240 base::Bind(
241 &DOMStorageContextImpl::DeleteLocalStorageFile, this, file_path));
242 return;
243 }
230 244
231 // Make sure that we don't delete a database that's currently being accessed 245 // Make sure that we don't delete a database that's currently being accessed
232 // by unloading all of the databases temporarily. 246 // by unloading all of the databases temporarily.
233 // TODO(bulach): both this method and DeleteDataModifiedSince could purge 247 // TODO(bulach): both this method and DeleteDataModifiedSince could purge
234 // only the memory used by the specific file instead of all memory at once. 248 // only the memory used by the specific file instead of all memory at once.
235 // See http://crbug.com/32000 249 // See http://crbug.com/32000
236 PurgeMemory(); 250 PurgeMemory();
237 file_util::Delete(file_path, false); 251 file_util::Delete(file_path, false);
238 } 252 }
239 253
240 void DOMStorageContextImpl::DeleteForOrigin(const string16& origin_id) { 254 void DOMStorageContextImpl::DeleteForOrigin(const string16& origin_id) {
241 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED));
242 DeleteLocalStorageFile(GetFilePath(origin_id)); 255 DeleteLocalStorageFile(GetFilePath(origin_id));
243 } 256 }
244 257
245 void DOMStorageContextImpl::DeleteAllLocalStorageFiles() { 258 void DOMStorageContextImpl::DeleteAllLocalStorageFiles() {
246 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED)); 259 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED));
247 260
248 // Make sure that we don't delete a database that's currently being accessed 261 // Make sure that we don't delete a database that's currently being accessed
249 // by unloading all of the databases temporarily. 262 // by unloading all of the databases temporarily.
250 PurgeMemory(); 263 PurgeMemory();
251 264
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
288 void DOMStorageContextImpl::CompleteCloningSessionStorage( 301 void DOMStorageContextImpl::CompleteCloningSessionStorage(
289 int64 existing_id, int64 clone_id) { 302 int64 existing_id, int64 clone_id) {
290 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED)); 303 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED));
291 DOMStorageNamespace* existing_namespace = 304 DOMStorageNamespace* existing_namespace =
292 GetStorageNamespace(existing_id, false); 305 GetStorageNamespace(existing_id, false);
293 // If nothing exists, then there's nothing to clone. 306 // If nothing exists, then there's nothing to clone.
294 if (existing_namespace) 307 if (existing_namespace)
295 RegisterStorageNamespace(existing_namespace->Copy(clone_id)); 308 RegisterStorageNamespace(existing_namespace->Copy(clone_id));
296 } 309 }
297 310
298 base::SequencedTaskRunner* DOMStorageContextImpl::task_runner() const { 311 void DOMStorageContextImpl::GetAllStorageFiles(
299 return webkit_message_loop_; 312 GetAllStorageFilesCallback callback) {
300 } 313 if (!webkit_message_loop_->RunsTasksOnCurrentThread()) {
314 webkit_message_loop_->PostTask(
315 FROM_HERE,
316 base::Bind(
317 &DOMStorageContextImpl::GetAllStorageFiles, this, callback));
318 return;
319 }
301 320
302 std::vector<FilePath> DOMStorageContextImpl::GetAllStorageFiles() {
303 std::vector<FilePath> files; 321 std::vector<FilePath> files;
304 file_util::FileEnumerator file_enumerator( 322 file_util::FileEnumerator file_enumerator(
305 data_path_.Append(kLocalStorageDirectory), false, 323 data_path_.Append(kLocalStorageDirectory), false,
306 file_util::FileEnumerator::FILES); 324 file_util::FileEnumerator::FILES);
307 for (FilePath file_path = file_enumerator.Next(); !file_path.empty(); 325 for (FilePath file_path = file_enumerator.Next(); !file_path.empty();
308 file_path = file_enumerator.Next()) { 326 file_path = file_enumerator.Next()) {
309 if (file_path.Extension() == kLocalStorageExtension) 327 if (file_path.Extension() == kLocalStorageExtension)
310 files.push_back(file_path); 328 files.push_back(file_path);
311 } 329 }
312 return files; 330
331 BrowserThread::PostTask(
332 BrowserThread::UI, FROM_HERE,
333 base::Bind(&DOMStorageContextImpl::RunAllStorageFilesCallback,
334 this, files, callback));
335 }
336
337 void DOMStorageContextImpl::RunAllStorageFilesCallback(
338 const std::vector<FilePath>& files, GetAllStorageFilesCallback callback) {
michaeln 2012/03/15 01:43:40 const ref here too
jam 2012/03/15 04:06:17 Done.
339 callback.Run(files);
313 } 340 }
314 341
315 FilePath DOMStorageContextImpl::GetFilePath(const string16& origin_id) const { 342 FilePath DOMStorageContextImpl::GetFilePath(const string16& origin_id) const {
316 FilePath storage_dir = data_path_.Append(kLocalStorageDirectory); 343 FilePath storage_dir = data_path_.Append(kLocalStorageDirectory);
317 FilePath::StringType id = webkit_glue::WebStringToFilePathString(origin_id); 344 FilePath::StringType id = webkit_glue::WebStringToFilePathString(origin_id);
318 return storage_dir.Append(id.append(kLocalStorageExtension)); 345 return storage_dir.Append(id.append(kLocalStorageExtension));
319 } 346 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698