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

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

Issue 8310014: Only send the client-side phishing model to a renderer if its profile has SafeBrowsing enabled. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add a comment as Noe suggested Created 9 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
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/client_side_detection_service.h" 5 #include "chrome/browser/safe_browsing/client_side_detection_service.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/time.h" 9 #include "base/time.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
11 #include "base/message_loop.h" 11 #include "base/message_loop.h"
12 #include "base/metrics/histogram.h" 12 #include "base/metrics/histogram.h"
13 #include "base/string_util.h" 13 #include "base/string_util.h"
14 #include "base/stl_util.h" 14 #include "base/stl_util.h"
15 #include "base/task.h" 15 #include "base/task.h"
16 #include "base/time.h" 16 #include "base/time.h"
17 #include "chrome/browser/browser_process.h" 17 #include "chrome/browser/browser_process.h"
18 #include "chrome/browser/prefs/pref_service.h"
19 #include "chrome/browser/profiles/profile.h"
18 #include "chrome/browser/safe_browsing/safe_browsing_util.h" 20 #include "chrome/browser/safe_browsing/safe_browsing_util.h"
19 #include "chrome/common/net/http_return.h" 21 #include "chrome/common/net/http_return.h"
22 #include "chrome/common/pref_names.h"
20 #include "chrome/common/safe_browsing/client_model.pb.h" 23 #include "chrome/common/safe_browsing/client_model.pb.h"
21 #include "chrome/common/safe_browsing/csd.pb.h" 24 #include "chrome/common/safe_browsing/csd.pb.h"
22 #include "chrome/common/safe_browsing/safebrowsing_messages.h" 25 #include "chrome/common/safe_browsing/safebrowsing_messages.h"
23 #include "content/browser/browser_thread.h" 26 #include "content/browser/browser_thread.h"
24 #include "content/browser/renderer_host/render_process_host.h" 27 #include "content/browser/renderer_host/render_process_host.h"
25 #include "content/common/notification_service.h" 28 #include "content/common/notification_service.h"
26 #include "crypto/sha2.h" 29 #include "crypto/sha2.h"
27 #include "googleurl/src/gurl.h" 30 #include "googleurl/src/gurl.h"
28 #include "net/base/load_flags.h" 31 #include "net/base/load_flags.h"
29 #include "net/http/http_response_headers.h" 32 #include "net/http/http_response_headers.h"
(...skipping 29 matching lines...) Expand all
59 ClientSideDetectionService::CacheState::CacheState(bool phish, base::Time time) 62 ClientSideDetectionService::CacheState::CacheState(bool phish, base::Time time)
60 : is_phishing(phish), 63 : is_phishing(phish),
61 timestamp(time) {} 64 timestamp(time) {}
62 65
63 ClientSideDetectionService::ClientSideDetectionService( 66 ClientSideDetectionService::ClientSideDetectionService(
64 net::URLRequestContextGetter* request_context_getter) 67 net::URLRequestContextGetter* request_context_getter)
65 : enabled_(false), 68 : enabled_(false),
66 ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)), 69 ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)),
67 request_context_getter_(request_context_getter) { 70 request_context_getter_(request_context_getter) {
68 registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_CREATED, 71 registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_CREATED,
69 NotificationService::AllSources()); 72 NotificationService::AllBrowserContextsAndSources());
70 } 73 }
71 74
72 ClientSideDetectionService::~ClientSideDetectionService() { 75 ClientSideDetectionService::~ClientSideDetectionService() {
73 method_factory_.RevokeAll(); 76 method_factory_.RevokeAll();
74 STLDeleteContainerPairPointers(client_phishing_reports_.begin(), 77 STLDeleteContainerPairPointers(client_phishing_reports_.begin(),
75 client_phishing_reports_.end()); 78 client_phishing_reports_.end());
76 client_phishing_reports_.clear(); 79 client_phishing_reports_.clear();
77 } 80 }
78 81
79 // static 82 // static
80 ClientSideDetectionService* ClientSideDetectionService::Create( 83 ClientSideDetectionService* ClientSideDetectionService::Create(
81 net::URLRequestContextGetter* request_context_getter) { 84 net::URLRequestContextGetter* request_context_getter) {
82 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 85 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
83 scoped_ptr<ClientSideDetectionService> service( 86 scoped_ptr<ClientSideDetectionService> service(
84 new ClientSideDetectionService(request_context_getter)); 87 new ClientSideDetectionService(request_context_getter));
85 if (!service->InitializePrivateNetworks()) { 88 if (!service->InitializePrivateNetworks()) {
86 UMA_HISTOGRAM_COUNTS("SBClientPhishing.InitPrivateNetworksFailed", 1); 89 UMA_HISTOGRAM_COUNTS("SBClientPhishing.InitPrivateNetworksFailed", 1);
87 return NULL; 90 return NULL;
88 } 91 }
89 return service.release(); 92 return service.release();
90 } 93 }
91 94
92 void ClientSideDetectionService::SetEnabled(bool enabled) { 95 void ClientSideDetectionService::SetEnabledAndRefreshState(bool enabled) {
93 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 96 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
97 SendModelToRenderers(); // always refresh the renderer state
94 if (enabled == enabled_) 98 if (enabled == enabled_)
95 return; 99 return;
96 enabled_ = enabled; 100 enabled_ = enabled;
97 if (enabled_) { 101 if (enabled_) {
98 // Refresh the model when the service is enabled. This can happen when the 102 // Refresh the model when the service is enabled. This can happen when the
99 // preference is toggled, or early during startup if the preference is 103 // preference is toggled, or early during startup if the preference is
100 // already enabled. In a lot of cases the model will be in the cache so it 104 // already enabled. In a lot of cases the model will be in the cache so it
101 // won't actually be fetched from the network. 105 // won't actually be fetched from the network.
102 // We delay the first model fetch to avoid slowing down browser startup. 106 // We delay the first model fetch to avoid slowing down browser startup.
103 ScheduleFetchModel(kInitialClientModelFetchDelayMs); 107 ScheduleFetchModel(kInitialClientModelFetchDelayMs);
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 DCHECK(type == content::NOTIFICATION_RENDERER_PROCESS_CREATED); 206 DCHECK(type == content::NOTIFICATION_RENDERER_PROCESS_CREATED);
203 if (!model_.get()) { 207 if (!model_.get()) {
204 // Model might not be ready or maybe there was an error. 208 // Model might not be ready or maybe there was an error.
205 return; 209 return;
206 } 210 }
207 SendModelToProcess(Source<RenderProcessHost>(source).ptr()); 211 SendModelToProcess(Source<RenderProcessHost>(source).ptr());
208 } 212 }
209 213
210 void ClientSideDetectionService::SendModelToProcess( 214 void ClientSideDetectionService::SendModelToProcess(
211 RenderProcessHost* process) { 215 RenderProcessHost* process) {
212 VLOG(2) << "Sending phishing model to renderer"; 216 // The ClientSideDetectionService is enabled if _any_ active profile has
213 process->Send(new SafeBrowsingMsg_SetPhishingModel(model_str_)); 217 // SafeBrowsing turned on. Here we check the profile for each renderer
218 // process and only send the model to those that have SafeBrowsing enabled.
219 Profile* profile = Profile::FromBrowserContext(process->browser_context());
220 std::string model;
221 if (profile->GetPrefs()->GetBoolean(prefs::kSafeBrowsingEnabled)) {
222 VLOG(2) << "Sending phishing model to RenderProcessHost @" << process;
223 model = model_str_;
224 } else {
225 VLOG(2) << "Disabling client-side phishing detection for "
226 << "RenderProcessHost @" << process;
227 }
228 process->Send(new SafeBrowsingMsg_SetPhishingModel(model));
214 } 229 }
215 230
216 void ClientSideDetectionService::SendModelToRenderers() { 231 void ClientSideDetectionService::SendModelToRenderers() {
217 for (RenderProcessHost::iterator i(RenderProcessHost::AllHostsIterator()); 232 for (RenderProcessHost::iterator i(RenderProcessHost::AllHostsIterator());
218 !i.IsAtEnd(); i.Advance()) { 233 !i.IsAtEnd(); i.Advance()) {
219 SendModelToProcess(i.GetCurrentValue()); 234 SendModelToProcess(i.GetCurrentValue());
220 } 235 }
221 } 236 }
222 237
223 void ClientSideDetectionService::ScheduleFetchModel(int64 delay_ms) { 238 void ClientSideDetectionService::ScheduleFetchModel(int64 delay_ms) {
(...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after
556 &whitelist_patterns); 571 &whitelist_patterns);
557 for (size_t j = 0; j < whitelist_patterns.size(); ++j) { 572 for (size_t j = 0; j < whitelist_patterns.size(); ++j) {
558 if (whitelist_patterns[j] == canonical_url_as_pattern) { 573 if (whitelist_patterns[j] == canonical_url_as_pattern) {
559 return true; 574 return true;
560 } 575 }
561 } 576 }
562 } 577 }
563 return false; 578 return false;
564 } 579 }
565 } // namespace safe_browsing 580 } // namespace safe_browsing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698