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

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

Issue 2868030: Add switches and apis in safebrowsing code to allow tests. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 10 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') | chrome/common/chrome_switches.h » ('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) 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/callback.h" 8 #include "base/callback.h"
9 #include "base/command_line.h"
9 #include "base/path_service.h" 10 #include "base/path_service.h"
10 #include "base/string_util.h" 11 #include "base/string_util.h"
11 #include "chrome/browser/browser_process.h" 12 #include "chrome/browser/browser_process.h"
12 #include "chrome/browser/metrics/metrics_service.h" 13 #include "chrome/browser/metrics/metrics_service.h"
13 #include "chrome/browser/pref_service.h" 14 #include "chrome/browser/pref_service.h"
14 #include "chrome/browser/profile_manager.h" 15 #include "chrome/browser/profile_manager.h"
15 #include "chrome/browser/safe_browsing/protocol_manager.h" 16 #include "chrome/browser/safe_browsing/protocol_manager.h"
16 #include "chrome/browser/safe_browsing/safe_browsing_blocking_page.h" 17 #include "chrome/browser/safe_browsing/safe_browsing_blocking_page.h"
17 #include "chrome/browser/safe_browsing/safe_browsing_database.h" 18 #include "chrome/browser/safe_browsing/safe_browsing_database.h"
18 #include "chrome/browser/tab_contents/tab_util.h" 19 #include "chrome/browser/tab_contents/tab_util.h"
19 #include "chrome/browser/tab_contents/tab_contents.h" 20 #include "chrome/browser/tab_contents/tab_contents.h"
20 #include "chrome/browser/chrome_thread.h" 21 #include "chrome/browser/chrome_thread.h"
21 #include "chrome/common/chrome_constants.h" 22 #include "chrome/common/chrome_constants.h"
22 #include "chrome/common/chrome_paths.h" 23 #include "chrome/common/chrome_paths.h"
24 #include "chrome/common/chrome_switches.h"
23 #include "chrome/common/net/url_request_context_getter.h" 25 #include "chrome/common/net/url_request_context_getter.h"
24 #include "chrome/common/pref_names.h" 26 #include "chrome/common/pref_names.h"
25 #include "chrome/common/url_constants.h" 27 #include "chrome/common/url_constants.h"
26 #include "net/base/registry_controlled_domain.h" 28 #include "net/base/registry_controlled_domain.h"
27 29
28 #if defined(OS_WIN) 30 #if defined(OS_WIN)
29 #include "chrome/installer/util/browser_distribution.h" 31 #include "chrome/installer/util/browser_distribution.h"
30 #endif 32 #endif
31 33
32 using base::Time; 34 using base::Time;
33 using base::TimeDelta; 35 using base::TimeDelta;
34 36
37 // The default URL prefix where browser fetches chunk updates, hashes,
38 // and reports malware.
39 static const char* const kSbDefaultInfoURLPrefix =
40 "http://safebrowsing.clients.google.com/safebrowsing";
41
42 // The default URL prefix where browser fetches MAC client key.
43 static const char* const kSbDefaultMacKeyURLPrefix =
44 "https://sb-ssl.google.com/safebrowsing";
45
35 static Profile* GetDefaultProfile() { 46 static Profile* GetDefaultProfile() {
36 FilePath user_data_dir; 47 FilePath user_data_dir;
37 PathService::Get(chrome::DIR_USER_DATA, &user_data_dir); 48 PathService::Get(chrome::DIR_USER_DATA, &user_data_dir);
38 ProfileManager* profile_manager = g_browser_process->profile_manager(); 49 ProfileManager* profile_manager = g_browser_process->profile_manager();
39 return profile_manager->GetDefaultProfile(user_data_dir); 50 return profile_manager->GetDefaultProfile(user_data_dir);
40 } 51 }
41 52
42 SafeBrowsingService::SafeBrowsingService() 53 SafeBrowsingService::SafeBrowsingService()
43 : database_(NULL), 54 : database_(NULL),
44 protocol_manager_(NULL), 55 protocol_manager_(NULL),
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
226 DCHECK(enabled_); 237 DCHECK(enabled_);
227 if (update_in_progress_) { 238 if (update_in_progress_) {
228 update_in_progress_ = false; 239 update_in_progress_ = false;
229 safe_browsing_thread_->message_loop()->PostTask(FROM_HERE, 240 safe_browsing_thread_->message_loop()->PostTask(FROM_HERE,
230 NewRunnableMethod(this, 241 NewRunnableMethod(this,
231 &SafeBrowsingService::DatabaseUpdateFinished, 242 &SafeBrowsingService::DatabaseUpdateFinished,
232 update_succeeded)); 243 update_succeeded));
233 } 244 }
234 } 245 }
235 246
247 bool SafeBrowsingService::IsUpdateInProgress() const {
248 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO));
249 return update_in_progress_;
250 }
251
236 void SafeBrowsingService::OnBlockingPageDone( 252 void SafeBrowsingService::OnBlockingPageDone(
237 const std::vector<UnsafeResource>& resources, 253 const std::vector<UnsafeResource>& resources,
238 bool proceed) { 254 bool proceed) {
239 for (std::vector<UnsafeResource>::const_iterator iter = resources.begin(); 255 for (std::vector<UnsafeResource>::const_iterator iter = resources.begin();
240 iter != resources.end(); ++iter) { 256 iter != resources.end(); ++iter) {
241 const UnsafeResource& resource = *iter; 257 const UnsafeResource& resource = *iter;
242 NotifyClientBlockingComplete(resource.client, proceed); 258 NotifyClientBlockingComplete(resource.client, proceed);
243 259
244 if (proceed) { 260 if (proceed) {
245 // Whitelist this domain and warning type for the given tab. 261 // Whitelist this domain and warning type for the given tab.
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
338 #if defined(OS_WIN) 354 #if defined(OS_WIN)
339 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); 355 BrowserDistribution* dist = BrowserDistribution::GetDistribution();
340 std::string client_name(dist->GetSafeBrowsingName()); 356 std::string client_name(dist->GetSafeBrowsingName());
341 #else 357 #else
342 #if defined(GOOGLE_CHROME_BUILD) 358 #if defined(GOOGLE_CHROME_BUILD)
343 std::string client_name("googlechrome"); 359 std::string client_name("googlechrome");
344 #else 360 #else
345 std::string client_name("chromium"); 361 std::string client_name("chromium");
346 #endif 362 #endif
347 #endif 363 #endif
364 CommandLine* cmdline = CommandLine::ForCurrentProcess();
365 bool disable_auto_update = cmdline->HasSwitch(switches::kSbDisableAutoUpdate);
366 std::string info_url_prefix =
367 cmdline->HasSwitch(switches::kSbInfoURLPrefix) ?
368 cmdline->GetSwitchValueASCII(switches::kSbInfoURLPrefix) :
369 kSbDefaultInfoURLPrefix;
370 std::string mackey_url_prefix =
371 cmdline->HasSwitch(switches::kSbMacKeyURLPrefix) ?
372 cmdline->GetSwitchValueASCII(switches::kSbMacKeyURLPrefix) :
373 kSbDefaultMacKeyURLPrefix;
348 374
349 protocol_manager_ = new SafeBrowsingProtocolManager(this, 375 protocol_manager_ = new SafeBrowsingProtocolManager(this,
350 client_name, 376 client_name,
351 client_key, 377 client_key,
352 wrapped_key, 378 wrapped_key,
353 request_context_getter); 379 request_context_getter,
380 info_url_prefix,
381 mackey_url_prefix,
382 disable_auto_update);
354 383
355 // Balance the reference added by Start(). 384 // Balance the reference added by Start().
356 request_context_getter->Release(); 385 request_context_getter->Release();
357 386
358 protocol_manager_->Initialize(); 387 protocol_manager_->Initialize();
359 } 388 }
360 389
361 void SafeBrowsingService::OnIOShutdown() { 390 void SafeBrowsingService::OnIOShutdown() {
362 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); 391 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO));
363 if (!enabled_) 392 if (!enabled_)
(...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after
755 std::vector<SBPrefix> prefix_hits; 784 std::vector<SBPrefix> prefix_hits;
756 std::vector<SBFullHashResult> full_hits; 785 std::vector<SBFullHashResult> full_hits;
757 database_->ContainsUrl(page_url, &list, &prefix_hits, &full_hits, 786 database_->ContainsUrl(page_url, &list, &prefix_hits, &full_hits,
758 protocol_manager_->last_update()); 787 protocol_manager_->last_update());
759 if (!full_hits.empty()) 788 if (!full_hits.empty())
760 return; 789 return;
761 } 790 }
762 791
763 protocol_manager_->ReportMalware(malware_url, page_url, referrer_url); 792 protocol_manager_->ReportMalware(malware_url, page_url, referrer_url);
764 } 793 }
OLDNEW
« no previous file with comments | « chrome/browser/safe_browsing/safe_browsing_service.h ('k') | chrome/common/chrome_switches.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698