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

Side by Side Diff: chrome/browser/safe_browsing/safe_browsing_service.cc

Issue 348037: Fourth patch in getting rid of caching MessageLoop pointers. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 1 month 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/safe_browsing/safe_browsing_service.h ('k') | no next file » | 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) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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 5
6 #include "chrome/browser/safe_browsing/safe_browsing_service.h" 6 #include "chrome/browser/safe_browsing/safe_browsing_service.h"
7 7
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/histogram.h" 9 #include "base/histogram.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 13 matching lines...) Expand all
24 #include "chrome/common/chrome_paths.h" 24 #include "chrome/common/chrome_paths.h"
25 #include "chrome/common/pref_names.h" 25 #include "chrome/common/pref_names.h"
26 #include "chrome/common/pref_service.h" 26 #include "chrome/common/pref_service.h"
27 #include "chrome/common/url_constants.h" 27 #include "chrome/common/url_constants.h"
28 #include "net/base/registry_controlled_domain.h" 28 #include "net/base/registry_controlled_domain.h"
29 29
30 using base::Time; 30 using base::Time;
31 using base::TimeDelta; 31 using base::TimeDelta;
32 32
33 SafeBrowsingService::SafeBrowsingService() 33 SafeBrowsingService::SafeBrowsingService()
34 : io_loop_(NULL), 34 : database_(NULL),
35 database_(NULL),
36 protocol_manager_(NULL), 35 protocol_manager_(NULL),
37 enabled_(false), 36 enabled_(false),
38 resetting_(false), 37 resetting_(false),
39 database_loaded_(false), 38 database_loaded_(false),
40 update_in_progress_(false) { 39 update_in_progress_(false) {
41 } 40 }
42 41
43 SafeBrowsingService::~SafeBrowsingService() { 42 SafeBrowsingService::~SafeBrowsingService() {
44 } 43 }
45 44
46 // Only called on the UI thread. 45 // Only called on the UI thread.
47 void SafeBrowsingService::Initialize(MessageLoop* io_loop) { 46 void SafeBrowsingService::Initialize() {
48 io_loop_ = io_loop;
49
50 // Get the profile's preference for SafeBrowsing. 47 // Get the profile's preference for SafeBrowsing.
51 FilePath user_data_dir; 48 FilePath user_data_dir;
52 PathService::Get(chrome::DIR_USER_DATA, &user_data_dir); 49 PathService::Get(chrome::DIR_USER_DATA, &user_data_dir);
53 ProfileManager* profile_manager = g_browser_process->profile_manager(); 50 ProfileManager* profile_manager = g_browser_process->profile_manager();
54 Profile* profile = profile_manager->GetDefaultProfile(user_data_dir); 51 Profile* profile = profile_manager->GetDefaultProfile(user_data_dir);
55 PrefService* pref_service = profile->GetPrefs(); 52 PrefService* pref_service = profile->GetPrefs();
56 if (pref_service->GetBoolean(prefs::kSafeBrowsingEnabled)) 53 if (pref_service->GetBoolean(prefs::kSafeBrowsingEnabled))
57 Start(); 54 Start();
58 } 55 }
59 56
60 // Start up SafeBrowsing objects. This can be called at browser start, or when 57 // Start up SafeBrowsing objects. This can be called at browser start, or when
61 // the user checks the "Enable SafeBrowsing" option in the Advanced options UI. 58 // the user checks the "Enable SafeBrowsing" option in the Advanced options UI.
62 void SafeBrowsingService::Start() { 59 void SafeBrowsingService::Start() {
63 DCHECK(!safe_browsing_thread_.get()); 60 DCHECK(!safe_browsing_thread_.get());
64 safe_browsing_thread_.reset(new base::Thread("Chrome_SafeBrowsingThread")); 61 safe_browsing_thread_.reset(new base::Thread("Chrome_SafeBrowsingThread"));
65 if (!safe_browsing_thread_->Start()) 62 if (!safe_browsing_thread_->Start())
66 return; 63 return;
67 64
68 // Retrieve client MAC keys. 65 // Retrieve client MAC keys.
69 PrefService* local_state = g_browser_process->local_state(); 66 PrefService* local_state = g_browser_process->local_state();
70 std::string client_key, wrapped_key; 67 std::string client_key, wrapped_key;
71 if (local_state) { 68 if (local_state) {
72 client_key = 69 client_key =
73 WideToASCII(local_state->GetString(prefs::kSafeBrowsingClientKey)); 70 WideToASCII(local_state->GetString(prefs::kSafeBrowsingClientKey));
74 wrapped_key = 71 wrapped_key =
75 WideToASCII(local_state->GetString(prefs::kSafeBrowsingWrappedKey)); 72 WideToASCII(local_state->GetString(prefs::kSafeBrowsingWrappedKey));
76 } 73 }
77 74
78 io_loop_->PostTask(FROM_HERE, NewRunnableMethod( 75 ChromeThread::PostTask(
79 this, &SafeBrowsingService::OnIOInitialize, MessageLoop::current(), 76 ChromeThread::IO, FROM_HERE,
80 client_key, wrapped_key)); 77 NewRunnableMethod(
78 this, &SafeBrowsingService::OnIOInitialize, client_key, wrapped_key));
81 79
82 safe_browsing_thread_->message_loop()->PostTask(FROM_HERE, NewRunnableMethod( 80 safe_browsing_thread_->message_loop()->PostTask(FROM_HERE, NewRunnableMethod(
83 this, &SafeBrowsingService::OnDBInitialize)); 81 this, &SafeBrowsingService::OnDBInitialize));
84 } 82 }
85 83
86 void SafeBrowsingService::ShutDown() { 84 void SafeBrowsingService::ShutDown() {
87 io_loop_->PostTask(FROM_HERE, NewRunnableMethod( 85 ChromeThread::PostTask(
88 this, &SafeBrowsingService::OnIOShutdown)); 86 ChromeThread::IO, FROM_HERE,
87 NewRunnableMethod(this, &SafeBrowsingService::OnIOShutdown));
89 } 88 }
90 89
91 void SafeBrowsingService::OnIOInitialize(MessageLoop* notify_loop, 90 void SafeBrowsingService::OnIOInitialize(const std::string& client_key,
92 const std::string& client_key,
93 const std::string& wrapped_key) { 91 const std::string& wrapped_key) {
94 DCHECK(MessageLoop::current() == io_loop_); 92 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO));
95 enabled_ = true; 93 enabled_ = true;
96 protocol_manager_ = new SafeBrowsingProtocolManager(this, 94 protocol_manager_ = new SafeBrowsingProtocolManager(this,
97 notify_loop,
98 client_key, 95 client_key,
99 wrapped_key); 96 wrapped_key);
100 // We want to initialize the protocol manager only after the database has 97 // We want to initialize the protocol manager only after the database has
101 // loaded, which we'll receive asynchronously (DatabaseLoadComplete). If 98 // loaded, which we'll receive asynchronously (DatabaseLoadComplete). If
102 // database_loaded_ isn't true, we'll wait for that notification to do the 99 // database_loaded_ isn't true, we'll wait for that notification to do the
103 // init. 100 // init.
104 if (database_loaded_) 101 if (database_loaded_)
105 protocol_manager_->Initialize(); 102 protocol_manager_->Initialize();
106 } 103 }
107 104
108 void SafeBrowsingService::OnDBInitialize() { 105 void SafeBrowsingService::OnDBInitialize() {
109 DCHECK(MessageLoop::current() == safe_browsing_thread_->message_loop()); 106 DCHECK(MessageLoop::current() == safe_browsing_thread_->message_loop());
110 GetDatabase(); 107 GetDatabase();
111 } 108 }
112 109
113 void SafeBrowsingService::OnIOShutdown() { 110 void SafeBrowsingService::OnIOShutdown() {
114 DCHECK(MessageLoop::current() == io_loop_); 111 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO));
115 if (!enabled_) 112 if (!enabled_)
116 return; 113 return;
117 114
118 enabled_ = false; 115 enabled_ = false;
119 resetting_ = false; 116 resetting_ = false;
120 117
121 // This cancels all in-flight GetHash requests. 118 // This cancels all in-flight GetHash requests.
122 delete protocol_manager_; 119 delete protocol_manager_;
123 protocol_manager_ = NULL; 120 protocol_manager_ = NULL;
124 121
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 else 156 else
160 ShutDown(); 157 ShutDown();
161 } 158 }
162 159
163 bool SafeBrowsingService::CanCheckUrl(const GURL& url) const { 160 bool SafeBrowsingService::CanCheckUrl(const GURL& url) const {
164 return url.SchemeIs(chrome::kHttpScheme) || 161 return url.SchemeIs(chrome::kHttpScheme) ||
165 url.SchemeIs(chrome::kHttpsScheme); 162 url.SchemeIs(chrome::kHttpsScheme);
166 } 163 }
167 164
168 bool SafeBrowsingService::CheckUrl(const GURL& url, Client* client) { 165 bool SafeBrowsingService::CheckUrl(const GURL& url, Client* client) {
169 DCHECK(MessageLoop::current() == io_loop_); 166 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO));
170 if (!enabled_ || !database_) 167 if (!enabled_ || !database_)
171 return true; 168 return true;
172 169
173 if (resetting_ || !database_loaded_) { 170 if (resetting_ || !database_loaded_) {
174 QueuedCheck check; 171 QueuedCheck check;
175 check.client = client; 172 check.client = client;
176 check.url = url; 173 check.url = url;
177 queued_checks_.push_back(check); 174 queued_checks_.push_back(check);
178 return false; 175 return false;
179 } 176 }
(...skipping 15 matching lines...) Expand all
195 // ResourceDispatcherHost event handler which can't pause there. 192 // ResourceDispatcherHost event handler which can't pause there.
196 SafeBrowsingCheck* check = new SafeBrowsingCheck(); 193 SafeBrowsingCheck* check = new SafeBrowsingCheck();
197 check->url = url; 194 check->url = url;
198 check->client = client; 195 check->client = client;
199 check->result = URL_SAFE; 196 check->result = URL_SAFE;
200 check->need_get_hash = full_hits.empty(); 197 check->need_get_hash = full_hits.empty();
201 check->prefix_hits.swap(prefix_hits); 198 check->prefix_hits.swap(prefix_hits);
202 check->full_hits.swap(full_hits); 199 check->full_hits.swap(full_hits);
203 checks_.insert(check); 200 checks_.insert(check);
204 201
205 io_loop_->PostTask(FROM_HERE, NewRunnableMethod( 202 ChromeThread::PostTask(
206 this, &SafeBrowsingService::OnCheckDone, check)); 203 ChromeThread::IO, FROM_HERE,
204 NewRunnableMethod(this, &SafeBrowsingService::OnCheckDone, check));
207 205
208 return false; 206 return false;
209 } 207 }
210 208
211 void SafeBrowsingService::DisplayBlockingPage(const GURL& url, 209 void SafeBrowsingService::DisplayBlockingPage(const GURL& url,
212 ResourceType::Type resource_type, 210 ResourceType::Type resource_type,
213 UrlCheckResult result, 211 UrlCheckResult result,
214 Client* client, 212 Client* client,
215 MessageLoop* ui_loop, 213 MessageLoop* ui_loop,
216 int render_process_host_id, 214 int render_process_host_id,
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
271 PrefService* prefs = g_browser_process->local_state(); 269 PrefService* prefs = g_browser_process->local_state();
272 DCHECK(prefs); 270 DCHECK(prefs);
273 if (prefs && prefs->GetBoolean(prefs::kMetricsReportingEnabled) && 271 if (prefs && prefs->GetBoolean(prefs::kMetricsReportingEnabled) &&
274 resource.resource_type != ResourceType::MAIN_FRAME && 272 resource.resource_type != ResourceType::MAIN_FRAME &&
275 resource.threat_type == SafeBrowsingService::URL_MALWARE) { 273 resource.threat_type == SafeBrowsingService::URL_MALWARE) {
276 GURL page_url = wc->GetURL(); 274 GURL page_url = wc->GetURL();
277 GURL referrer_url; 275 GURL referrer_url;
278 NavigationEntry* entry = wc->controller().GetActiveEntry(); 276 NavigationEntry* entry = wc->controller().GetActiveEntry();
279 if (entry) 277 if (entry)
280 referrer_url = entry->referrer(); 278 referrer_url = entry->referrer();
281 io_loop_->PostTask(FROM_HERE, 279 ChromeThread::PostTask(
280 ChromeThread::IO, FROM_HERE,
282 NewRunnableMethod(this, 281 NewRunnableMethod(this,
283 &SafeBrowsingService::ReportMalware, 282 &SafeBrowsingService::ReportMalware,
284 resource.url, 283 resource.url,
285 page_url, 284 page_url,
286 referrer_url)); 285 referrer_url));
287 } 286 }
288 287
289 SafeBrowsingBlockingPage::ShowBlockingPage(this, resource); 288 SafeBrowsingBlockingPage::ShowBlockingPage(this, resource);
290 } 289 }
291 290
292 void SafeBrowsingService::CancelCheck(Client* client) { 291 void SafeBrowsingService::CancelCheck(Client* client) {
293 DCHECK(MessageLoop::current() == io_loop_); 292 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO));
294 293
295 for (CurrentChecks::iterator i = checks_.begin(); i != checks_.end(); ++i) { 294 for (CurrentChecks::iterator i = checks_.begin(); i != checks_.end(); ++i) {
296 if ((*i)->client == client) 295 if ((*i)->client == client)
297 (*i)->client = NULL; 296 (*i)->client = NULL;
298 } 297 }
299 298
300 // Scan the queued clients store. Clients may be here if they requested a URL 299 // Scan the queued clients store. Clients may be here if they requested a URL
301 // check before the database has finished loading or resetting. 300 // check before the database has finished loading or resetting.
302 if (!database_loaded_ || resetting_) { 301 if (!database_loaded_ || resetting_) {
303 std::deque<QueuedCheck>::iterator it = queued_checks_.begin(); 302 std::deque<QueuedCheck>::iterator it = queued_checks_.begin();
304 for (; it != queued_checks_.end(); ++it) { 303 for (; it != queued_checks_.end(); ++it) {
305 if (it->client == client) 304 if (it->client == client)
306 it->client = NULL; 305 it->client = NULL;
307 } 306 }
308 } 307 }
309 } 308 }
310 309
311 void SafeBrowsingService::OnCheckDone(SafeBrowsingCheck* check) { 310 void SafeBrowsingService::OnCheckDone(SafeBrowsingCheck* check) {
312 DCHECK(MessageLoop::current() == io_loop_); 311 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO));
313 312
314 // If we've been shutdown during the database lookup, this check will already 313 // If we've been shutdown during the database lookup, this check will already
315 // have been deleted (in OnIOShutdown). 314 // have been deleted (in OnIOShutdown).
316 if (!enabled_ || checks_.find(check) == checks_.end()) 315 if (!enabled_ || checks_.find(check) == checks_.end())
317 return; 316 return;
318 317
319 if (check->client && check->need_get_hash) { 318 if (check->client && check->need_get_hash) {
320 // We have a partial match so we need to query Google for the full hash. 319 // We have a partial match so we need to query Google for the full hash.
321 // Clean up will happen in HandleGetHashResults. 320 // Clean up will happen in HandleGetHashResults.
322 321
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
360 DCHECK(result); 359 DCHECK(result);
361 path = path.Append(chrome::kSafeBrowsingFilename); 360 path = path.Append(chrome::kSafeBrowsingFilename);
362 361
363 Time before = Time::Now(); 362 Time before = Time::Now();
364 SafeBrowsingDatabase* database = SafeBrowsingDatabase::Create(); 363 SafeBrowsingDatabase* database = SafeBrowsingDatabase::Create();
365 Callback0::Type* chunk_callback = 364 Callback0::Type* chunk_callback =
366 NewCallback(this, &SafeBrowsingService::ChunkInserted); 365 NewCallback(this, &SafeBrowsingService::ChunkInserted);
367 database->Init(path, chunk_callback); 366 database->Init(path, chunk_callback);
368 database_ = database; 367 database_ = database;
369 368
370 io_loop_->PostTask(FROM_HERE, NewRunnableMethod( 369 ChromeThread::PostTask(
371 this, &SafeBrowsingService::DatabaseLoadComplete)); 370 ChromeThread::IO, FROM_HERE,
371 NewRunnableMethod(this, &SafeBrowsingService::DatabaseLoadComplete));
372 372
373 TimeDelta open_time = Time::Now() - before; 373 TimeDelta open_time = Time::Now() - before;
374 SB_DLOG(INFO) << "SafeBrowsing database open took " << 374 SB_DLOG(INFO) << "SafeBrowsing database open took " <<
375 open_time.InMilliseconds() << " ms."; 375 open_time.InMilliseconds() << " ms.";
376 376
377 return database_; 377 return database_;
378 } 378 }
379 379
380 // Public API called only on the IO thread. 380 // Public API called only on the IO thread.
381 // The SafeBrowsingProtocolManager has received the full hash results for 381 // The SafeBrowsingProtocolManager has received the full hash results for
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
438 438
439 // Let the client continue handling the original request. 439 // Let the client continue handling the original request.
440 check->client->OnUrlCheckResult(check->url, result); 440 check->client->OnUrlCheckResult(check->url, result);
441 } 441 }
442 442
443 checks_.erase(check); 443 checks_.erase(check);
444 delete check; 444 delete check;
445 } 445 }
446 446
447 void SafeBrowsingService::UpdateStarted() { 447 void SafeBrowsingService::UpdateStarted() {
448 DCHECK(MessageLoop::current() == io_loop_); 448 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO));
449 DCHECK(enabled_); 449 DCHECK(enabled_);
450 DCHECK(!update_in_progress_); 450 DCHECK(!update_in_progress_);
451 update_in_progress_ = true; 451 update_in_progress_ = true;
452 safe_browsing_thread_->message_loop()->PostTask(FROM_HERE, NewRunnableMethod( 452 safe_browsing_thread_->message_loop()->PostTask(FROM_HERE, NewRunnableMethod(
453 this, &SafeBrowsingService::GetAllChunksFromDatabase)); 453 this, &SafeBrowsingService::GetAllChunksFromDatabase));
454 } 454 }
455 455
456 void SafeBrowsingService::UpdateFinished(bool update_succeeded) { 456 void SafeBrowsingService::UpdateFinished(bool update_succeeded) {
457 DCHECK(MessageLoop::current() == io_loop_); 457 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO));
458 DCHECK(enabled_); 458 DCHECK(enabled_);
459 if (update_in_progress_) { 459 if (update_in_progress_) {
460 update_in_progress_ = false; 460 update_in_progress_ = false;
461 safe_browsing_thread_->message_loop()->PostTask(FROM_HERE, 461 safe_browsing_thread_->message_loop()->PostTask(FROM_HERE,
462 NewRunnableMethod(this, 462 NewRunnableMethod(this,
463 &SafeBrowsingService::DatabaseUpdateFinished, 463 &SafeBrowsingService::DatabaseUpdateFinished,
464 update_succeeded)); 464 update_succeeded));
465 } 465 }
466 } 466 }
467 467
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
502 const std::string& wrapped_key) { 502 const std::string& wrapped_key) {
503 PrefService* prefs = g_browser_process->local_state(); 503 PrefService* prefs = g_browser_process->local_state();
504 if (prefs) { 504 if (prefs) {
505 prefs->SetString(prefs::kSafeBrowsingClientKey, ASCIIToWide(client_key)); 505 prefs->SetString(prefs::kSafeBrowsingClientKey, ASCIIToWide(client_key));
506 prefs->SetString(prefs::kSafeBrowsingWrappedKey, ASCIIToWide(wrapped_key)); 506 prefs->SetString(prefs::kSafeBrowsingWrappedKey, ASCIIToWide(wrapped_key));
507 } 507 }
508 } 508 }
509 509
510 void SafeBrowsingService::ChunkInserted() { 510 void SafeBrowsingService::ChunkInserted() {
511 DCHECK(MessageLoop::current() == safe_browsing_thread_->message_loop()); 511 DCHECK(MessageLoop::current() == safe_browsing_thread_->message_loop());
512 io_loop_->PostTask(FROM_HERE, NewRunnableMethod( 512 ChromeThread::PostTask(
513 this, &SafeBrowsingService::OnChunkInserted)); 513 ChromeThread::IO, FROM_HERE,
514 NewRunnableMethod(this, &SafeBrowsingService::OnChunkInserted));
514 } 515 }
515 516
516 void SafeBrowsingService::OnChunkInserted() { 517 void SafeBrowsingService::OnChunkInserted() {
517 DCHECK(MessageLoop::current() == io_loop_); 518 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO));
518 if (enabled_) 519 if (enabled_)
519 protocol_manager_->OnChunkInserted(); 520 protocol_manager_->OnChunkInserted();
520 } 521 }
521 522
522 void SafeBrowsingService::DatabaseLoadComplete() { 523 void SafeBrowsingService::DatabaseLoadComplete() {
523 DCHECK(MessageLoop::current() == io_loop_); 524 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO));
524 if (!enabled_) 525 if (!enabled_)
525 return; 526 return;
526 527
527 database_loaded_ = true; 528 database_loaded_ = true;
528 529
529 if (protocol_manager_) 530 if (protocol_manager_)
530 protocol_manager_->Initialize(); 531 protocol_manager_->Initialize();
531 532
532 // If we have any queued requests, we can now check them. 533 // If we have any queued requests, we can now check them.
533 if (!resetting_) 534 if (!resetting_)
534 RunQueuedClients(); 535 RunQueuedClients();
535 } 536 }
536 537
537 // static 538 // static
538 void SafeBrowsingService::RegisterPrefs(PrefService* prefs) { 539 void SafeBrowsingService::RegisterPrefs(PrefService* prefs) {
539 prefs->RegisterStringPref(prefs::kSafeBrowsingClientKey, L""); 540 prefs->RegisterStringPref(prefs::kSafeBrowsingClientKey, L"");
540 prefs->RegisterStringPref(prefs::kSafeBrowsingWrappedKey, L""); 541 prefs->RegisterStringPref(prefs::kSafeBrowsingWrappedKey, L"");
541 } 542 }
542 543
543 void SafeBrowsingService::ResetDatabase() { 544 void SafeBrowsingService::ResetDatabase() {
544 DCHECK(MessageLoop::current() == io_loop_); 545 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO));
545 resetting_ = true; 546 resetting_ = true;
546 safe_browsing_thread_->message_loop()->PostTask(FROM_HERE, NewRunnableMethod( 547 safe_browsing_thread_->message_loop()->PostTask(FROM_HERE, NewRunnableMethod(
547 this, &SafeBrowsingService::OnResetDatabase)); 548 this, &SafeBrowsingService::OnResetDatabase));
548 } 549 }
549 550
550 void SafeBrowsingService::OnResetDatabase() { 551 void SafeBrowsingService::OnResetDatabase() {
551 DCHECK(MessageLoop::current() == safe_browsing_thread_->message_loop()); 552 DCHECK(MessageLoop::current() == safe_browsing_thread_->message_loop());
552 GetDatabase()->ResetDatabase(); 553 GetDatabase()->ResetDatabase();
553 io_loop_->PostTask(FROM_HERE, NewRunnableMethod( 554 ChromeThread::PostTask(
554 this, &SafeBrowsingService::OnResetComplete)); 555 ChromeThread::IO, FROM_HERE,
556 NewRunnableMethod(this, &SafeBrowsingService::OnResetComplete));
555 } 557 }
556 558
557 void SafeBrowsingService::OnResetComplete() { 559 void SafeBrowsingService::OnResetComplete() {
558 DCHECK(MessageLoop::current() == io_loop_); 560 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO));
559 if (enabled_) { 561 if (enabled_) {
560 resetting_ = false; 562 resetting_ = false;
561 database_loaded_ = true; 563 database_loaded_ = true;
562 RunQueuedClients(); 564 RunQueuedClients();
563 } 565 }
564 } 566 }
565 567
566 void SafeBrowsingService::HandleChunk(const std::string& list, 568 void SafeBrowsingService::HandleChunk(const std::string& list,
567 std::deque<SBChunk>* chunks) { 569 std::deque<SBChunk>* chunks) {
568 DCHECK(MessageLoop::current() == io_loop_); 570 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO));
569 DCHECK(enabled_); 571 DCHECK(enabled_);
570 safe_browsing_thread_->message_loop()->PostTask(FROM_HERE, NewRunnableMethod( 572 safe_browsing_thread_->message_loop()->PostTask(FROM_HERE, NewRunnableMethod(
571 this, &SafeBrowsingService::HandleChunkForDatabase, list, chunks)); 573 this, &SafeBrowsingService::HandleChunkForDatabase, list, chunks));
572 } 574 }
573 575
574 void SafeBrowsingService::HandleChunkForDatabase( 576 void SafeBrowsingService::HandleChunkForDatabase(
575 const std::string& list_name, 577 const std::string& list_name,
576 std::deque<SBChunk>* chunks) { 578 std::deque<SBChunk>* chunks) {
577 DCHECK(MessageLoop::current() == safe_browsing_thread_->message_loop()); 579 DCHECK(MessageLoop::current() == safe_browsing_thread_->message_loop());
578 580
579 GetDatabase()->InsertChunks(list_name, chunks); 581 GetDatabase()->InsertChunks(list_name, chunks);
580 } 582 }
581 583
582 void SafeBrowsingService::HandleChunkDelete( 584 void SafeBrowsingService::HandleChunkDelete(
583 std::vector<SBChunkDelete>* chunk_deletes) { 585 std::vector<SBChunkDelete>* chunk_deletes) {
584 DCHECK(MessageLoop::current() == io_loop_); 586 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO));
585 DCHECK(enabled_); 587 DCHECK(enabled_);
586 safe_browsing_thread_->message_loop()->PostTask(FROM_HERE, NewRunnableMethod( 588 safe_browsing_thread_->message_loop()->PostTask(FROM_HERE, NewRunnableMethod(
587 this, &SafeBrowsingService::DeleteChunks, chunk_deletes)); 589 this, &SafeBrowsingService::DeleteChunks, chunk_deletes));
588 } 590 }
589 591
590 void SafeBrowsingService::DeleteChunks( 592 void SafeBrowsingService::DeleteChunks(
591 std::vector<SBChunkDelete>* chunk_deletes) { 593 std::vector<SBChunkDelete>* chunk_deletes) {
592 DCHECK(MessageLoop::current() == safe_browsing_thread_->message_loop()); 594 DCHECK(MessageLoop::current() == safe_browsing_thread_->message_loop());
593 595
594 GetDatabase()->DeleteChunks(chunk_deletes); 596 GetDatabase()->DeleteChunks(chunk_deletes);
595 } 597 }
596 598
597 // Database worker function. 599 // Database worker function.
598 void SafeBrowsingService::GetAllChunksFromDatabase() { 600 void SafeBrowsingService::GetAllChunksFromDatabase() {
599 DCHECK(MessageLoop::current() == safe_browsing_thread_->message_loop()); 601 DCHECK(MessageLoop::current() == safe_browsing_thread_->message_loop());
600 bool database_error = true; 602 bool database_error = true;
601 std::vector<SBListChunkRanges> lists; 603 std::vector<SBListChunkRanges> lists;
602 if (GetDatabase()) { 604 if (GetDatabase()) {
603 if (GetDatabase()->UpdateStarted()) { 605 if (GetDatabase()->UpdateStarted()) {
604 GetDatabase()->GetListsInfo(&lists); 606 GetDatabase()->GetListsInfo(&lists);
605 database_error = false; 607 database_error = false;
606 } else { 608 } else {
607 GetDatabase()->UpdateFinished(false); 609 GetDatabase()->UpdateFinished(false);
608 } 610 }
609 } 611 }
610 612
611 io_loop_->PostTask(FROM_HERE, NewRunnableMethod( 613 ChromeThread::PostTask(
612 this, &SafeBrowsingService::OnGetAllChunksFromDatabase, lists, 614 ChromeThread::IO, FROM_HERE,
613 database_error)); 615 NewRunnableMethod(
616 this, &SafeBrowsingService::OnGetAllChunksFromDatabase, lists,
617 database_error));
614 } 618 }
615 619
616 // Called on the io thread with the results of all chunks. 620 // Called on the io thread with the results of all chunks.
617 void SafeBrowsingService::OnGetAllChunksFromDatabase( 621 void SafeBrowsingService::OnGetAllChunksFromDatabase(
618 const std::vector<SBListChunkRanges>& lists, bool database_error) { 622 const std::vector<SBListChunkRanges>& lists, bool database_error) {
619 DCHECK(MessageLoop::current() == io_loop_); 623 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO));
620 if (enabled_) 624 if (enabled_)
621 protocol_manager_->OnGetChunksComplete(lists, database_error); 625 protocol_manager_->OnGetChunksComplete(lists, database_error);
622 } 626 }
623 627
624 SafeBrowsingService::UrlCheckResult SafeBrowsingService::GetResultFromListname( 628 SafeBrowsingService::UrlCheckResult SafeBrowsingService::GetResultFromListname(
625 const std::string& list_name) { 629 const std::string& list_name) {
626 if (safe_browsing_util::IsPhishingList(list_name)) { 630 if (safe_browsing_util::IsPhishingList(list_name)) {
627 return URL_PHISHING; 631 return URL_PHISHING;
628 } 632 }
629 633
(...skipping 10 matching lines...) Expand all
640 } 644 }
641 645
642 void SafeBrowsingService::CacheHashResults( 646 void SafeBrowsingService::CacheHashResults(
643 const std::vector<SBPrefix>& prefixes, 647 const std::vector<SBPrefix>& prefixes,
644 const std::vector<SBFullHashResult>& full_hashes) { 648 const std::vector<SBFullHashResult>& full_hashes) {
645 DCHECK(MessageLoop::current() == safe_browsing_thread_->message_loop()); 649 DCHECK(MessageLoop::current() == safe_browsing_thread_->message_loop());
646 GetDatabase()->CacheHashResults(prefixes, full_hashes); 650 GetDatabase()->CacheHashResults(prefixes, full_hashes);
647 } 651 }
648 652
649 void SafeBrowsingService::RunQueuedClients() { 653 void SafeBrowsingService::RunQueuedClients() {
650 DCHECK(MessageLoop::current() == io_loop_); 654 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO));
651 HISTOGRAM_COUNTS("SB.QueueDepth", queued_checks_.size()); 655 HISTOGRAM_COUNTS("SB.QueueDepth", queued_checks_.size());
652 while (!queued_checks_.empty()) { 656 while (!queued_checks_.empty()) {
653 QueuedCheck check = queued_checks_.front(); 657 QueuedCheck check = queued_checks_.front();
654 HISTOGRAM_TIMES("SB.QueueDelay", Time::Now() - check.start); 658 HISTOGRAM_TIMES("SB.QueueDelay", Time::Now() - check.start);
655 CheckUrl(check.url, check.client); 659 CheckUrl(check.url, check.client);
656 queued_checks_.pop_front(); 660 queued_checks_.pop_front();
657 } 661 }
658 } 662 }
659 663
660 void SafeBrowsingService::ReportMalware(const GURL& malware_url, 664 void SafeBrowsingService::ReportMalware(const GURL& malware_url,
661 const GURL& page_url, 665 const GURL& page_url,
662 const GURL& referrer_url) { 666 const GURL& referrer_url) {
663 DCHECK(MessageLoop::current() == io_loop_); 667 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO));
664 668
665 if (!enabled_ || !database_) 669 if (!enabled_ || !database_)
666 return; 670 return;
667 671
668 // Check if 'page_url' is already blacklisted (exists in our cache). Only 672 // Check if 'page_url' is already blacklisted (exists in our cache). Only
669 // report if it's not there. 673 // report if it's not there.
670 std::string list; 674 std::string list;
671 std::vector<SBPrefix> prefix_hits; 675 std::vector<SBPrefix> prefix_hits;
672 std::vector<SBFullHashResult> full_hits; 676 std::vector<SBFullHashResult> full_hits;
673 database_->ContainsUrl(page_url, &list, &prefix_hits, &full_hits, 677 database_->ContainsUrl(page_url, &list, &prefix_hits, &full_hits,
674 protocol_manager_->last_update()); 678 protocol_manager_->last_update());
675 679
676 if (full_hits.empty()) 680 if (full_hits.empty())
677 protocol_manager_->ReportMalware(malware_url, page_url, referrer_url); 681 protocol_manager_->ReportMalware(malware_url, page_url, referrer_url);
678 } 682 }
OLDNEW
« no previous file with comments | « chrome/browser/safe_browsing/safe_browsing_service.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698