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

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

Issue 7313003: Separate memory purger from safe browsing. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 5 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/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) 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/safe_browsing/safe_browsing_service.h" 5 #include "chrome/browser/safe_browsing/safe_browsing_service.h"
6 6
7 #include "base/callback.h" 7 #include "base/callback.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/lazy_instance.h" 9 #include "base/lazy_instance.h"
10 #include "base/path_service.h" 10 #include "base/path_service.h"
11 #include "base/stl_util-inl.h" 11 #include "base/stl_util-inl.h"
12 #include "base/string_util.h" 12 #include "base/string_util.h"
13 #include "base/threading/thread_restrictions.h" 13 #include "base/threading/thread_restrictions.h"
14 #include "chrome/browser/browser_process.h" 14 #include "chrome/browser/browser_process.h"
15 #include "chrome/browser/metrics/metrics_service.h" 15 #include "chrome/browser/metrics/metrics_service.h"
16 #include "chrome/browser/prefs/pref_service.h" 16 #include "chrome/browser/prefs/pref_service.h"
17 #include "chrome/browser/profiles/profile_manager.h" 17 #include "chrome/browser/profiles/profile_manager.h"
18 #include "chrome/browser/safe_browsing/malware_details.h" 18 #include "chrome/browser/safe_browsing/malware_details.h"
19 #include "chrome/browser/safe_browsing/protocol_manager.h" 19 #include "chrome/browser/safe_browsing/protocol_manager.h"
20 #include "chrome/browser/safe_browsing/safe_browsing_blocking_page.h" 20 #include "chrome/browser/safe_browsing/safe_browsing_blocking_page.h"
21 #include "chrome/browser/safe_browsing/safe_browsing_database.h" 21 #include "chrome/browser/safe_browsing/safe_browsing_database.h"
22 #include "chrome/browser/tab_contents/tab_util.h" 22 #include "chrome/browser/tab_contents/tab_util.h"
23 #include "chrome/common/chrome_constants.h" 23 #include "chrome/common/chrome_constants.h"
24 #include "chrome/common/chrome_paths.h" 24 #include "chrome/common/chrome_paths.h"
25 #include "chrome/common/chrome_switches.h" 25 #include "chrome/common/chrome_switches.h"
26 #include "chrome/common/pref_names.h" 26 #include "chrome/common/pref_names.h"
27 #include "chrome/common/url_constants.h" 27 #include "chrome/common/url_constants.h"
28 #include "content/browser/browser_thread.h" 28 #include "content/browser/browser_thread.h"
29 #include "content/browser/tab_contents/tab_contents.h" 29 #include "content/browser/tab_contents/tab_contents.h"
30 #include "content/common/notification_service.h"
30 #include "net/base/registry_controlled_domain.h" 31 #include "net/base/registry_controlled_domain.h"
31 #include "net/url_request/url_request_context_getter.h" 32 #include "net/url_request/url_request_context_getter.h"
32 33
33 #if defined(OS_WIN) 34 #if defined(OS_WIN)
34 #include "chrome/installer/util/browser_distribution.h" 35 #include "chrome/installer/util/browser_distribution.h"
35 #endif 36 #endif
36 37
37 namespace { 38 namespace {
38 39
39 // The default URL prefix where browser fetches chunk updates, hashes, 40 // The default URL prefix where browser fetches chunk updates, hashes,
(...skipping 476 matching lines...) Expand 10 before | Expand all | Expand 10 after
516 DCHECK(!enabled_); 517 DCHECK(!enabled_);
517 } 518 }
518 519
519 void SafeBrowsingService::OnIOInitialize( 520 void SafeBrowsingService::OnIOInitialize(
520 const std::string& client_key, 521 const std::string& client_key,
521 const std::string& wrapped_key, 522 const std::string& wrapped_key,
522 net::URLRequestContextGetter* request_context_getter) { 523 net::URLRequestContextGetter* request_context_getter) {
523 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 524 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
524 enabled_ = true; 525 enabled_ = true;
525 526
527 registrar_.Add(
Peter Kasting 2011/07/06 18:18:37 Nit: Put as many args on this line as will fit
Torne 2011/07/07 09:29:35 Done.
528 this, NotificationType::PURGE_MEMORY, NotificationService::AllSources());
529
526 MakeDatabaseAvailable(); 530 MakeDatabaseAvailable();
527 531
528 // On Windows, get the safe browsing client name from the browser 532 // On Windows, get the safe browsing client name from the browser
529 // distribution classes in installer util. These classes don't yet have 533 // distribution classes in installer util. These classes don't yet have
530 // an analog on non-Windows builds so just keep the name specified here. 534 // an analog on non-Windows builds so just keep the name specified here.
531 #if defined(OS_WIN) 535 #if defined(OS_WIN)
532 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); 536 BrowserDistribution* dist = BrowserDistribution::GetDistribution();
533 std::string client_name(dist->GetSafeBrowsingName()); 537 std::string client_name(dist->GetSafeBrowsingName());
534 #else 538 #else
535 #if defined(GOOGLE_CHROME_BUILD) 539 #if defined(GOOGLE_CHROME_BUILD)
(...skipping 29 matching lines...) Expand all
565 protocol_manager_->Initialize(); 569 protocol_manager_->Initialize();
566 } 570 }
567 571
568 void SafeBrowsingService::OnIOShutdown() { 572 void SafeBrowsingService::OnIOShutdown() {
569 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 573 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
570 if (!enabled_) 574 if (!enabled_)
571 return; 575 return;
572 576
573 enabled_ = false; 577 enabled_ = false;
574 578
579 registrar_.RemoveAll();
580
575 // This cancels all in-flight GetHash requests. 581 // This cancels all in-flight GetHash requests.
576 delete protocol_manager_; 582 delete protocol_manager_;
577 protocol_manager_ = NULL; 583 protocol_manager_ = NULL;
578 584
579 // Delete queued checks, calling back any clients with 'SAFE'. 585 // Delete queued checks, calling back any clients with 'SAFE'.
580 // If we don't do this here we may fail to close the database below. 586 // If we don't do this here we may fail to close the database below.
581 while (!queued_checks_.empty()) { 587 while (!queued_checks_.empty()) {
582 QueuedCheck queued = queued_checks_.front(); 588 QueuedCheck queued = queued_checks_.front();
583 if (queued.client) { 589 if (queued.client) {
584 SafeBrowsingCheck sb_check; 590 SafeBrowsingCheck sb_check;
(...skipping 610 matching lines...) Expand 10 before | Expand all | Expand 10 after
1195 // Whitelist this domain and warning type for the given tab. 1201 // Whitelist this domain and warning type for the given tab.
1196 WhiteListedEntry entry; 1202 WhiteListedEntry entry;
1197 entry.render_process_host_id = resource.render_process_host_id; 1203 entry.render_process_host_id = resource.render_process_host_id;
1198 entry.render_view_id = resource.render_view_id; 1204 entry.render_view_id = resource.render_view_id;
1199 entry.domain = net::RegistryControlledDomainService::GetDomainAndRegistry( 1205 entry.domain = net::RegistryControlledDomainService::GetDomainAndRegistry(
1200 resource.url); 1206 resource.url);
1201 entry.result = resource.threat_type; 1207 entry.result = resource.threat_type;
1202 white_listed_entries_.push_back(entry); 1208 white_listed_entries_.push_back(entry);
1203 } 1209 }
1204 1210
1211 void SafeBrowsingService::Observe(NotificationType type,
1212 const NotificationSource& source,
1213 const NotificationDetails& details) {
1214 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
1215 DCHECK(type == NotificationType::PURGE_MEMORY);
Scott Hess - ex-Googler 2011/07/06 17:01:28 Prefer DCHECK_EQ() for the improved diagnostic out
Peter Kasting 2011/07/06 18:18:37 I don't think DCHECK_EQ() works for this argument
Torne 2011/07/07 09:29:35 It doesn't, no; there's no ostream::operator<< def
1216 CloseDatabase();
Peter Kasting 2011/07/06 18:18:37 Nit: Is this now only called from within the class
Torne 2011/07/07 09:29:35 Done.
1217 }
1218
1205 bool SafeBrowsingService::IsWhitelisted(const UnsafeResource& resource) { 1219 bool SafeBrowsingService::IsWhitelisted(const UnsafeResource& resource) {
1206 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 1220 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1207 // Check if the user has already ignored our warning for this render_view 1221 // Check if the user has already ignored our warning for this render_view
1208 // and domain. 1222 // and domain.
1209 for (size_t i = 0; i < white_listed_entries_.size(); ++i) { 1223 for (size_t i = 0; i < white_listed_entries_.size(); ++i) {
1210 const WhiteListedEntry& entry = white_listed_entries_[i]; 1224 const WhiteListedEntry& entry = white_listed_entries_[i];
1211 if (entry.render_process_host_id == resource.render_process_host_id && 1225 if (entry.render_process_host_id == resource.render_process_host_id &&
1212 entry.render_view_id == resource.render_view_id && 1226 entry.render_view_id == resource.render_view_id &&
1213 // Threat type must be the same or in the case of phishing they can 1227 // Threat type must be the same or in the case of phishing they can
1214 // either be client-side phishing URL or a SafeBrowsing phishing URL. 1228 // either be client-side phishing URL or a SafeBrowsing phishing URL.
1215 // If we show one type of phishing warning we don't want to show a 1229 // If we show one type of phishing warning we don't want to show a
1216 // second phishing warning. 1230 // second phishing warning.
1217 (entry.result == resource.threat_type || 1231 (entry.result == resource.threat_type ||
1218 (entry.result == URL_PHISHING && 1232 (entry.result == URL_PHISHING &&
1219 resource.threat_type == CLIENT_SIDE_PHISHING_URL) || 1233 resource.threat_type == CLIENT_SIDE_PHISHING_URL) ||
1220 (entry.result == CLIENT_SIDE_PHISHING_URL && 1234 (entry.result == CLIENT_SIDE_PHISHING_URL &&
1221 resource.threat_type == URL_PHISHING)) && 1235 resource.threat_type == URL_PHISHING)) &&
1222 entry.domain == 1236 entry.domain ==
1223 net::RegistryControlledDomainService::GetDomainAndRegistry( 1237 net::RegistryControlledDomainService::GetDomainAndRegistry(
1224 resource.url)) { 1238 resource.url)) {
1225 return true; 1239 return true;
1226 } 1240 }
1227 } 1241 }
1228 return false; 1242 return false;
1229 } 1243 }
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