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

Side by Side Diff: chrome/browser/browsing_data_local_storage_helper.cc

Issue 6246105: Only invoke WebKit methods in browsing data helpers on the WEBKIT thread. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 10 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/file_util.h" 7 #include "base/file_util.h"
8 #include "base/message_loop.h" 8 #include "base/message_loop.h"
9 #include "base/string_util.h" 9 #include "base/string_util.h"
10 #include "base/utf_string_conversions.h" 10 #include "base/utf_string_conversions.h"
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
140 file_path); 140 file_path);
141 } 141 }
142 142
143 CannedBrowsingDataLocalStorageHelper::CannedBrowsingDataLocalStorageHelper( 143 CannedBrowsingDataLocalStorageHelper::CannedBrowsingDataLocalStorageHelper(
144 Profile* profile) 144 Profile* profile)
145 : BrowsingDataLocalStorageHelper(profile) { 145 : BrowsingDataLocalStorageHelper(profile) {
146 } 146 }
147 147
148 void CannedBrowsingDataLocalStorageHelper::AddLocalStorage( 148 void CannedBrowsingDataLocalStorageHelper::AddLocalStorage(
149 const GURL& origin) { 149 const GURL& origin) {
150 WebKit::WebSecurityOrigin web_security_origin = 150 base::AutoLock auto_lock(lock_);
151 WebKit::WebSecurityOrigin::createFromString( 151 pending_local_storage_info_.push_back(origin);
152 UTF8ToUTF16(origin.spec()));
153 std::string security_origin(web_security_origin.toString().utf8());
154
155 for (std::vector<LocalStorageInfo>::iterator
156 local_storage = local_storage_info_.begin();
157 local_storage != local_storage_info_.end(); ++local_storage) {
158 if (local_storage->origin == security_origin)
159 return;
160 }
161
162 local_storage_info_.push_back(LocalStorageInfo(
163 web_security_origin.protocol().utf8(),
164 web_security_origin.host().utf8(),
165 web_security_origin.port(),
166 web_security_origin.databaseIdentifier().utf8(),
167 security_origin,
168 profile_->GetWebKitContext()->dom_storage_context()->
169 GetLocalStorageFilePath(web_security_origin.databaseIdentifier()),
170 0,
171 base::Time()));
172 } 152 }
173 153
174 void CannedBrowsingDataLocalStorageHelper::Reset() { 154 void CannedBrowsingDataLocalStorageHelper::Reset() {
155 base::AutoLock auto_lock(lock_);
175 local_storage_info_.clear(); 156 local_storage_info_.clear();
157 pending_local_storage_info_.clear();
176 } 158 }
177 159
178 bool CannedBrowsingDataLocalStorageHelper::empty() const { 160 bool CannedBrowsingDataLocalStorageHelper::empty() const {
179 return local_storage_info_.empty(); 161 base::AutoLock auto_lock(lock_);
162 return local_storage_info_.empty() && pending_local_storage_info_.empty();
180 } 163 }
181 164
182 void CannedBrowsingDataLocalStorageHelper::StartFetching( 165 void CannedBrowsingDataLocalStorageHelper::StartFetching(
183 Callback1<const std::vector<LocalStorageInfo>& >::Type* callback) { 166 Callback1<const std::vector<LocalStorageInfo>& >::Type* callback) {
184 callback->Run(local_storage_info_); 167 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
185 delete callback; 168 DCHECK(!is_fetching_);
169 DCHECK(callback);
170 is_fetching_ = true;
171 completion_callback_.reset(callback);
172 BrowserThread::PostTask(
173 BrowserThread::WEBKIT, FROM_HERE,
174 NewRunnableMethod(
175 this,
176 &CannedBrowsingDataLocalStorageHelper::
177 ConvertPendingInfoInWebKitThread));
186 } 178 }
179
180 void CannedBrowsingDataLocalStorageHelper::ConvertPendingInfoInWebKitThread() {
181 base::AutoLock auto_lock(lock_);
182 for (std::vector<GURL>::iterator info = pending_local_storage_info_.begin();
183 info != pending_local_storage_info_.end(); ++info) {
184 WebKit::WebSecurityOrigin web_security_origin =
185 WebKit::WebSecurityOrigin::createFromString(
186 UTF8ToUTF16(info->spec()));
187 std::string security_origin(web_security_origin.toString().utf8());
188
189 bool duplicate = false;
190 for (std::vector<LocalStorageInfo>::iterator
191 local_storage = local_storage_info_.begin();
192 local_storage != local_storage_info_.end(); ++local_storage) {
193 if (local_storage->origin == security_origin) {
194 duplicate = true;
195 break;
196 }
197 }
198 if (duplicate)
199 continue;
200
201 local_storage_info_.push_back(LocalStorageInfo(
202 web_security_origin.protocol().utf8(),
203 web_security_origin.host().utf8(),
204 web_security_origin.port(),
205 web_security_origin.databaseIdentifier().utf8(),
206 security_origin,
207 profile_->GetWebKitContext()->dom_storage_context()->
208 GetLocalStorageFilePath(web_security_origin.databaseIdentifier()),
209 0,
210 base::Time()));
211 }
212 pending_local_storage_info_.clear();
213
214 BrowserThread::PostTask(
215 BrowserThread::UI, FROM_HERE,
216 NewRunnableMethod(
217 this, &CannedBrowsingDataLocalStorageHelper::NotifyInUIThread));
218 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698