Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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 | |
|
noelutz
2011/10/18 00:33:42
What's the thought behind sending the model if the
| |
| 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 Loading... | |
| 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 Profile* profile = Profile::FromBrowserContext(process->browser_context()); |
| 213 process->Send(new SafeBrowsingMsg_SetPhishingModel(model_str_)); | 217 std::string model; |
| 218 if (profile->GetPrefs()->GetBoolean(prefs::kSafeBrowsingEnabled)) { | |
|
noelutz
2011/10/18 00:33:42
Why not simply wait until enabled_ is set in SetEn
| |
| 219 VLOG(2) << "Sending phishing model to RenderProcessHost @" << process; | |
| 220 model = model_str_; | |
| 221 } else { | |
| 222 VLOG(2) << "Disabling client-side phishing detection for " | |
| 223 << "RenderProcessHost @" << process; | |
| 224 } | |
| 225 process->Send(new SafeBrowsingMsg_SetPhishingModel(model)); | |
| 214 } | 226 } |
| 215 | 227 |
| 216 void ClientSideDetectionService::SendModelToRenderers() { | 228 void ClientSideDetectionService::SendModelToRenderers() { |
| 217 for (RenderProcessHost::iterator i(RenderProcessHost::AllHostsIterator()); | 229 for (RenderProcessHost::iterator i(RenderProcessHost::AllHostsIterator()); |
| 218 !i.IsAtEnd(); i.Advance()) { | 230 !i.IsAtEnd(); i.Advance()) { |
| 219 SendModelToProcess(i.GetCurrentValue()); | 231 SendModelToProcess(i.GetCurrentValue()); |
| 220 } | 232 } |
| 221 } | 233 } |
| 222 | 234 |
| 223 void ClientSideDetectionService::ScheduleFetchModel(int64 delay_ms) { | 235 void ClientSideDetectionService::ScheduleFetchModel(int64 delay_ms) { |
| (...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 556 &whitelist_patterns); | 568 &whitelist_patterns); |
| 557 for (size_t j = 0; j < whitelist_patterns.size(); ++j) { | 569 for (size_t j = 0; j < whitelist_patterns.size(); ++j) { |
| 558 if (whitelist_patterns[j] == canonical_url_as_pattern) { | 570 if (whitelist_patterns[j] == canonical_url_as_pattern) { |
| 559 return true; | 571 return true; |
| 560 } | 572 } |
| 561 } | 573 } |
| 562 } | 574 } |
| 563 return false; | 575 return false; |
| 564 } | 576 } |
| 565 } // namespace safe_browsing | 577 } // namespace safe_browsing |
| OLD | NEW |