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

Side by Side Diff: chrome/browser/browsing_data_local_storage_helper.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 "chrome/browser/browsing_data_local_storage_helper.h" 5 #include "chrome/browser/browsing_data_local_storage_helper.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/file_util.h" 8 #include "base/file_util.h"
9 #include "base/message_loop.h" 9 #include "base/message_loop.h"
10 #include "base/string_util.h" 10 #include "base/string_util.h"
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 size(size), 45 size(size),
46 last_modified(last_modified) { 46 last_modified(last_modified) {
47 } 47 }
48 48
49 BrowsingDataLocalStorageHelper::LocalStorageInfo::~LocalStorageInfo() {} 49 BrowsingDataLocalStorageHelper::LocalStorageInfo::~LocalStorageInfo() {}
50 50
51 BrowsingDataLocalStorageHelper::BrowsingDataLocalStorageHelper( 51 BrowsingDataLocalStorageHelper::BrowsingDataLocalStorageHelper(
52 Profile* profile) 52 Profile* profile)
53 : dom_storage_context_(BrowserContext::GetDOMStorageContext(profile)), 53 : dom_storage_context_(BrowserContext::GetDOMStorageContext(profile)),
54 is_fetching_(false) { 54 is_fetching_(false) {
55 DCHECK(dom_storage_context_.get()); 55 DCHECK(dom_storage_context_);
56 } 56 }
57 57
58 BrowsingDataLocalStorageHelper::~BrowsingDataLocalStorageHelper() { 58 BrowsingDataLocalStorageHelper::~BrowsingDataLocalStorageHelper() {
59 } 59 }
60 60
61 void BrowsingDataLocalStorageHelper::StartFetching( 61 void BrowsingDataLocalStorageHelper::StartFetching(
62 const base::Callback<void(const std::list<LocalStorageInfo>&)>& callback) { 62 const base::Callback<void(const std::list<LocalStorageInfo>&)>& callback) {
63 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 63 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
64 DCHECK(!is_fetching_); 64 DCHECK(!is_fetching_);
65 DCHECK_EQ(false, callback.is_null()); 65 DCHECK_EQ(false, callback.is_null());
66 66
67 is_fetching_ = true; 67 is_fetching_ = true;
68 completion_callback_ = callback; 68 completion_callback_ = callback;
69 dom_storage_context_->task_runner()->PostTask( 69 dom_storage_context_->GetAllStorageFiles(
70 FROM_HERE,
71 base::Bind( 70 base::Bind(
72 &BrowsingDataLocalStorageHelper::FetchLocalStorageInfoHelper, 71 &BrowsingDataLocalStorageHelper::GetAllStorageFilesCallback, this));
73 this));
74 } 72 }
75 73
76 void BrowsingDataLocalStorageHelper::CancelNotification() { 74 void BrowsingDataLocalStorageHelper::CancelNotification() {
77 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 75 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
78 completion_callback_.Reset(); 76 completion_callback_.Reset();
79 } 77 }
80 78
81 void BrowsingDataLocalStorageHelper::DeleteLocalStorageFile( 79 void BrowsingDataLocalStorageHelper::DeleteLocalStorageFile(
82 const FilePath& file_path) { 80 const FilePath& file_path) {
83 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 81 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
84 dom_storage_context_->task_runner()->PostTask( 82 dom_storage_context_->DeleteLocalStorageFile(file_path);
83 }
84
85 void BrowsingDataLocalStorageHelper::GetAllStorageFilesCallback(
86 const std::vector<FilePath>& files) {
87 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
88 BrowserThread::PostTask(
89 BrowserThread::FILE,
85 FROM_HERE, 90 FROM_HERE,
86 base::Bind( 91 base::Bind(
87 &BrowsingDataLocalStorageHelper::DeleteLocalStorageFileHelper, 92 &BrowsingDataLocalStorageHelper::FetchLocalStorageInfo,
88 this, file_path)); 93 this, files));
89 } 94 }
90 95
91 void BrowsingDataLocalStorageHelper::FetchLocalStorageInfoHelper() { 96 void BrowsingDataLocalStorageHelper::FetchLocalStorageInfo(
92 DCHECK(dom_storage_context_->task_runner()->RunsTasksOnCurrentThread()); 97 const std::vector<FilePath>& files) {
93 std::vector<FilePath> files = dom_storage_context_->GetAllStorageFiles(); 98 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
94 for (size_t i = 0; i < files.size(); ++i) { 99 for (size_t i = 0; i < files.size(); ++i) {
95 FilePath file_path = files[i]; 100 FilePath file_path = files[i];
96 WebSecurityOrigin web_security_origin = 101 WebSecurityOrigin web_security_origin =
97 WebSecurityOrigin::createFromDatabaseIdentifier( 102 WebSecurityOrigin::createFromDatabaseIdentifier(
98 webkit_glue::FilePathToWebString(file_path.BaseName())); 103 webkit_glue::FilePathToWebString(file_path.BaseName()));
99 if (EqualsASCII(web_security_origin.protocol(), chrome::kExtensionScheme)) { 104 if (EqualsASCII(web_security_origin.protocol(), chrome::kExtensionScheme)) {
100 // Extension state is not considered browsing data. 105 // Extension state is not considered browsing data.
101 continue; 106 continue;
102 } 107 }
103 base::PlatformFileInfo file_info; 108 base::PlatformFileInfo file_info;
(...skipping 21 matching lines...) Expand all
125 DCHECK(is_fetching_); 130 DCHECK(is_fetching_);
126 // Note: completion_callback_ mutates only in the UI thread, so it's safe to 131 // Note: completion_callback_ mutates only in the UI thread, so it's safe to
127 // test it here. 132 // test it here.
128 if (!completion_callback_.is_null()) { 133 if (!completion_callback_.is_null()) {
129 completion_callback_.Run(local_storage_info_); 134 completion_callback_.Run(local_storage_info_);
130 completion_callback_.Reset(); 135 completion_callback_.Reset();
131 } 136 }
132 is_fetching_ = false; 137 is_fetching_ = false;
133 } 138 }
134 139
135 void BrowsingDataLocalStorageHelper::DeleteLocalStorageFileHelper(
136 const FilePath& file_path) {
137 DCHECK(dom_storage_context_->task_runner()->RunsTasksOnCurrentThread());
138 dom_storage_context_->DeleteLocalStorageFile(file_path);
139 }
140
141 //--------------------------------------------------------- 140 //---------------------------------------------------------
142 141
143 CannedBrowsingDataLocalStorageHelper::CannedBrowsingDataLocalStorageHelper( 142 CannedBrowsingDataLocalStorageHelper::CannedBrowsingDataLocalStorageHelper(
144 Profile* profile) 143 Profile* profile)
145 : BrowsingDataLocalStorageHelper(profile), 144 : BrowsingDataLocalStorageHelper(profile),
146 profile_(profile) { 145 profile_(profile) {
147 } 146 }
148 147
149 CannedBrowsingDataLocalStorageHelper* 148 CannedBrowsingDataLocalStorageHelper*
150 CannedBrowsingDataLocalStorageHelper::Clone() { 149 CannedBrowsingDataLocalStorageHelper::Clone() {
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
220 0, 219 0,
221 base::Time())); 220 base::Time()));
222 } 221 }
223 pending_local_storage_info_.clear(); 222 pending_local_storage_info_.clear();
224 223
225 BrowserThread::PostTask( 224 BrowserThread::PostTask(
226 BrowserThread::UI, FROM_HERE, 225 BrowserThread::UI, FROM_HERE,
227 base::Bind(&CannedBrowsingDataLocalStorageHelper::NotifyInUIThread, 226 base::Bind(&CannedBrowsingDataLocalStorageHelper::NotifyInUIThread,
228 this)); 227 this));
229 } 228 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698