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

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

Issue 258008: Move initialization of ChromeURLRequestContexts to the IO thread. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: sync again, just in case Created 11 years, 2 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
« no previous file with comments | « chrome/browser/browsing_data_remover.h ('k') | chrome/browser/chrome_plugin_host.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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_remover.h" 5 #include "chrome/browser/browsing_data_remover.h"
6 6
7 #include "chrome/browser/chrome_thread.h" 7 #include "chrome/browser/chrome_thread.h"
8 #include "chrome/browser/browser_process.h" 8 #include "chrome/browser/browser_process.h"
9 #include "chrome/browser/download/download_manager.h" 9 #include "chrome/browser/download/download_manager.h"
10 #include "chrome/browser/history/history.h" 10 #include "chrome/browser/history/history.h"
11 #include "chrome/browser/profile.h" 11 #include "chrome/browser/profile.h"
12 #include "chrome/browser/metrics/user_metrics.h" 12 #include "chrome/browser/metrics/user_metrics.h"
13 #include "chrome/browser/net/url_request_context_getter.h"
13 #include "chrome/browser/password_manager/password_store.h" 14 #include "chrome/browser/password_manager/password_store.h"
14 #include "chrome/browser/search_engines/template_url_model.h" 15 #include "chrome/browser/search_engines/template_url_model.h"
15 #include "chrome/browser/sessions/session_service.h" 16 #include "chrome/browser/sessions/session_service.h"
16 #include "chrome/browser/sessions/tab_restore_service.h" 17 #include "chrome/browser/sessions/tab_restore_service.h"
17 #include "chrome/browser/webdata/web_data_service.h" 18 #include "chrome/browser/webdata/web_data_service.h"
18 #include "chrome/common/notification_service.h" 19 #include "chrome/common/notification_service.h"
19 #include "net/base/cookie_monster.h" 20 #include "net/base/cookie_monster.h"
20 #include "net/disk_cache/disk_cache.h" 21 #include "net/disk_cache/disk_cache.h"
21 #include "net/http/http_cache.h" 22 #include "net/http/http_cache.h"
22 #include "net/url_request/url_request_context.h" 23 #include "net/url_request/url_request_context.h"
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 100
100 if (remove_mask & REMOVE_DOWNLOADS) { 101 if (remove_mask & REMOVE_DOWNLOADS) {
101 UserMetrics::RecordAction(L"ClearBrowsingData_Downloads", profile_); 102 UserMetrics::RecordAction(L"ClearBrowsingData_Downloads", profile_);
102 DownloadManager* download_manager = profile_->GetDownloadManager(); 103 DownloadManager* download_manager = profile_->GetDownloadManager();
103 download_manager->RemoveDownloadsBetween(delete_begin_, delete_end_); 104 download_manager->RemoveDownloadsBetween(delete_begin_, delete_end_);
104 download_manager->ClearLastDownloadPath(); 105 download_manager->ClearLastDownloadPath();
105 } 106 }
106 107
107 if (remove_mask & REMOVE_COOKIES) { 108 if (remove_mask & REMOVE_COOKIES) {
108 UserMetrics::RecordAction(L"ClearBrowsingData_Cookies", profile_); 109 UserMetrics::RecordAction(L"ClearBrowsingData_Cookies", profile_);
110 // Since we are running on the UI thread don't call GetURLRequestContext().
109 net::CookieMonster* cookie_monster = 111 net::CookieMonster* cookie_monster =
110 profile_->GetRequestContext()->cookie_store()->GetCookieMonster(); 112 profile_->GetRequestContext()->GetCookieStore()->GetCookieMonster();
111 if (cookie_monster) 113 if (cookie_monster)
112 cookie_monster->DeleteAllCreatedBetween(delete_begin_, delete_end_, true); 114 cookie_monster->DeleteAllCreatedBetween(delete_begin_, delete_end_, true);
113 } 115 }
114 116
115 if (remove_mask & REMOVE_PASSWORDS) { 117 if (remove_mask & REMOVE_PASSWORDS) {
116 UserMetrics::RecordAction(L"ClearBrowsingData_Passwords", profile_); 118 UserMetrics::RecordAction(L"ClearBrowsingData_Passwords", profile_);
117 PasswordStore* password_store = 119 PasswordStore* password_store =
118 profile_->GetPasswordStore(Profile::EXPLICIT_ACCESS); 120 profile_->GetPasswordStore(Profile::EXPLICIT_ACCESS);
119 121
120 password_store->RemoveLoginsCreatedBetween(delete_begin_, delete_end_); 122 password_store->RemoveLoginsCreatedBetween(delete_begin_, delete_end_);
(...skipping 10 matching lines...) Expand all
131 133
132 if (remove_mask & REMOVE_CACHE) { 134 if (remove_mask & REMOVE_CACHE) {
133 // Invoke ClearBrowsingDataView::ClearCache on the IO thread. 135 // Invoke ClearBrowsingDataView::ClearCache on the IO thread.
134 base::Thread* thread = g_browser_process->io_thread(); 136 base::Thread* thread = g_browser_process->io_thread();
135 if (thread) { 137 if (thread) {
136 waiting_for_clear_cache_ = true; 138 waiting_for_clear_cache_ = true;
137 UserMetrics::RecordAction(L"ClearBrowsingData_Cache", profile_); 139 UserMetrics::RecordAction(L"ClearBrowsingData_Cache", profile_);
138 thread->message_loop()->PostTask(FROM_HERE, NewRunnableMethod( 140 thread->message_loop()->PostTask(FROM_HERE, NewRunnableMethod(
139 this, 141 this,
140 &BrowsingDataRemover::ClearCacheOnIOThread, 142 &BrowsingDataRemover::ClearCacheOnIOThread,
143 profile_->GetRequestContext(),
141 delete_begin_, 144 delete_begin_,
142 delete_end_, 145 delete_end_,
143 MessageLoop::current())); 146 MessageLoop::current()));
144 } 147 }
145 } 148 }
146 149
147 NotifyAndDeleteIfDone(); 150 NotifyAndDeleteIfDone();
148 } 151 }
149 152
150 void BrowsingDataRemover::AddObserver(Observer* observer) { 153 void BrowsingDataRemover::AddObserver(Observer* observer) {
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 // As such, we do a delete later. 214 // As such, we do a delete later.
212 MessageLoop::current()->DeleteSoon(FROM_HERE, this); 215 MessageLoop::current()->DeleteSoon(FROM_HERE, this);
213 } 216 }
214 217
215 void BrowsingDataRemover::ClearedCache() { 218 void BrowsingDataRemover::ClearedCache() {
216 waiting_for_clear_cache_ = false; 219 waiting_for_clear_cache_ = false;
217 220
218 NotifyAndDeleteIfDone(); 221 NotifyAndDeleteIfDone();
219 } 222 }
220 223
221 void BrowsingDataRemover::ClearCacheOnIOThread(base::Time delete_begin, 224 void BrowsingDataRemover::ClearCacheOnIOThread(
222 base::Time delete_end, 225 URLRequestContextGetter* context_getter,
223 MessageLoop* ui_loop) { 226 base::Time delete_begin,
227 base::Time delete_end,
228 MessageLoop* ui_loop) {
224 // This function should be called on the IO thread. 229 // This function should be called on the IO thread.
225 DCHECK(MessageLoop::current() == 230 DCHECK(MessageLoop::current() ==
226 ChromeThread::GetMessageLoop(ChromeThread::IO)); 231 ChromeThread::GetMessageLoop(ChromeThread::IO));
227 232
228 // Get a pointer to the cache. 233 // Get a pointer to the cache.
229 net::HttpTransactionFactory* factory = 234 net::HttpTransactionFactory* factory =
230 profile_->GetRequestContext()->http_transaction_factory(); 235 context_getter->GetURLRequestContext()->http_transaction_factory();
231 disk_cache::Backend* cache = factory->GetCache()->disk_cache(); 236 disk_cache::Backend* cache = factory->GetCache()->disk_cache();
232 237
233 // |cache| can be null since it is lazily initialized, in this case we do 238 // |cache| can be null since it is lazily initialized, in this case we do
234 // nothing. 239 // nothing.
235 if (cache) { 240 if (cache) {
236 if (delete_begin.is_null()) 241 if (delete_begin.is_null())
237 cache->DoomAllEntries(); 242 cache->DoomAllEntries();
238 else 243 else
239 cache->DoomEntriesBetween(delete_begin, delete_end); 244 cache->DoomEntriesBetween(delete_begin, delete_end);
240 } 245 }
241 246
242 // Get a pointer to the media cache. 247 // Get a pointer to the media cache.
243 factory = profile_->GetRequestContextForMedia()->http_transaction_factory(); 248 factory = profile_->GetRequestContextForMedia()->GetURLRequestContext()->
249 http_transaction_factory();
244 cache = factory->GetCache()->disk_cache(); 250 cache = factory->GetCache()->disk_cache();
245 251
246 // |cache| can be null since it is lazily initialized, in this case we do 252 // |cache| can be null since it is lazily initialized, in this case we do
247 // nothing. 253 // nothing.
248 if (cache) { 254 if (cache) {
249 if (delete_begin.is_null()) 255 if (delete_begin.is_null())
250 cache->DoomAllEntries(); 256 cache->DoomAllEntries();
251 else 257 else
252 cache->DoomEntriesBetween(delete_begin, delete_end); 258 cache->DoomEntriesBetween(delete_begin, delete_end);
253 } 259 }
254 260
255 // Notify the UI thread that we are done. 261 // Notify the UI thread that we are done.
256 ui_loop->PostTask(FROM_HERE, NewRunnableMethod( 262 ui_loop->PostTask(FROM_HERE, NewRunnableMethod(
257 this, &BrowsingDataRemover::ClearedCache)); 263 this, &BrowsingDataRemover::ClearedCache));
258 } 264 }
OLDNEW
« no previous file with comments | « chrome/browser/browsing_data_remover.h ('k') | chrome/browser/chrome_plugin_host.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698