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

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

Issue 1924983002: Enable V4LocalDatabaseManager based on Finch. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 <stddef.h> 7 #include <stddef.h>
8 8
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/bind.h" 11 #include "base/bind.h"
12 #include "base/bind_helpers.h" 12 #include "base/bind_helpers.h"
13 #include "base/callback.h" 13 #include "base/callback.h"
14 #include "base/command_line.h" 14 #include "base/command_line.h"
15 #include "base/lazy_instance.h" 15 #include "base/lazy_instance.h"
16 #include "base/macros.h" 16 #include "base/macros.h"
17 #include "base/metrics/field_trial.h"
17 #include "base/metrics/histogram_macros.h" 18 #include "base/metrics/histogram_macros.h"
18 #include "base/path_service.h" 19 #include "base/path_service.h"
19 #include "base/stl_util.h" 20 #include "base/stl_util.h"
20 #include "base/strings/string_util.h" 21 #include "base/strings/string_util.h"
21 #include "base/threading/thread.h" 22 #include "base/threading/thread.h"
22 #include "base/threading/thread_restrictions.h" 23 #include "base/threading/thread_restrictions.h"
23 #include "base/trace_event/trace_event.h" 24 #include "base/trace_event/trace_event.h"
24 #include "build/build_config.h" 25 #include "build/build_config.h"
25 #include "chrome/browser/browser_process.h" 26 #include "chrome/browser/browser_process.h"
26 #include "chrome/browser/chrome_notification_types.h" 27 #include "chrome/browser/chrome_notification_types.h"
27 #include "chrome/browser/metrics/chrome_metrics_service_accessor.h" 28 #include "chrome/browser/metrics/chrome_metrics_service_accessor.h"
28 #include "chrome/browser/profiles/profile.h" 29 #include "chrome/browser/profiles/profile.h"
29 #include "chrome/browser/profiles/profile_manager.h" 30 #include "chrome/browser/profiles/profile_manager.h"
30 #include "chrome/browser/safe_browsing/ping_manager.h" 31 #include "chrome/browser/safe_browsing/ping_manager.h"
31 #include "chrome/browser/safe_browsing/ui_manager.h" 32 #include "chrome/browser/safe_browsing/ui_manager.h"
32 #include "chrome/common/chrome_constants.h" 33 #include "chrome/common/chrome_constants.h"
33 #include "chrome/common/chrome_paths.h" 34 #include "chrome/common/chrome_paths.h"
34 #include "chrome/common/chrome_switches.h" 35 #include "chrome/common/chrome_switches.h"
35 #include "chrome/common/pref_names.h" 36 #include "chrome/common/pref_names.h"
36 #include "chrome/common/url_constants.h" 37 #include "chrome/common/url_constants.h"
37 #include "components/prefs/pref_change_registrar.h" 38 #include "components/prefs/pref_change_registrar.h"
38 #include "components/prefs/pref_service.h" 39 #include "components/prefs/pref_service.h"
39 #include "components/safe_browsing_db/database_manager.h" 40 #include "components/safe_browsing_db/database_manager.h"
40 #include "components/safe_browsing_db/v4_get_hash_protocol_manager.h" 41 #include "components/safe_browsing_db/v4_get_hash_protocol_manager.h"
42 #include "components/safe_browsing_db/v4_local_database_manager.h"
41 #include "components/user_prefs/tracked/tracked_preference_validation_delegate.h " 43 #include "components/user_prefs/tracked/tracked_preference_validation_delegate.h "
42 #include "content/public/browser/browser_thread.h" 44 #include "content/public/browser/browser_thread.h"
43 #include "content/public/browser/cookie_store_factory.h" 45 #include "content/public/browser/cookie_store_factory.h"
44 #include "content/public/browser/notification_service.h" 46 #include "content/public/browser/notification_service.h"
45 #include "content/public/browser/resource_request_info.h" 47 #include "content/public/browser/resource_request_info.h"
46 #include "google_apis/google_api_keys.h" 48 #include "google_apis/google_api_keys.h"
47 #include "net/cookies/cookie_store.h" 49 #include "net/cookies/cookie_store.h"
48 #include "net/extras/sqlite/cookie_crypto_delegate.h" 50 #include "net/extras/sqlite/cookie_crypto_delegate.h"
49 #include "net/url_request/url_request_context.h" 51 #include "net/url_request/url_request_context.h"
50 #include "net/url_request/url_request_context_getter.h" 52 #include "net/url_request/url_request_context_getter.h"
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
254 } 256 }
255 257
256 void SafeBrowsingService::Initialize() { 258 void SafeBrowsingService::Initialize() {
257 url_request_context_getter_ = new SafeBrowsingURLRequestContextGetter( 259 url_request_context_getter_ = new SafeBrowsingURLRequestContextGetter(
258 g_browser_process->system_request_context()); 260 g_browser_process->system_request_context());
259 261
260 ui_manager_ = CreateUIManager(); 262 ui_manager_ = CreateUIManager();
261 263
262 database_manager_ = CreateDatabaseManager(); 264 database_manager_ = CreateDatabaseManager();
263 265
266 if (IsV4LocalDatabaseManagerEnabled()) {
267 v4_local_database_manager_ = CreateV4LocalDatabaseManager();
268 }
269
264 services_delegate_->InitializeCsdService(url_request_context_getter_.get()); 270 services_delegate_->InitializeCsdService(url_request_context_getter_.get());
265 services_delegate_->InitializeServices(); 271 services_delegate_->InitializeServices();
266 272
267 // Track the safe browsing preference of existing profiles. 273 // Track the safe browsing preference of existing profiles.
268 // The SafeBrowsingService will be started if any existing profile has the 274 // The SafeBrowsingService will be started if any existing profile has the
269 // preference enabled. It will also listen for updates to the preferences. 275 // preference enabled. It will also listen for updates to the preferences.
270 ProfileManager* profile_manager = g_browser_process->profile_manager(); 276 ProfileManager* profile_manager = g_browser_process->profile_manager();
271 if (profile_manager) { 277 if (profile_manager) {
272 std::vector<Profile*> profiles = profile_manager->GetLoadedProfiles(); 278 std::vector<Profile*> profiles = profile_manager->GetLoadedProfiles();
273 // TODO(felt): I believe this for-loop is dead code. Confirm this and 279 // TODO(felt): I believe this for-loop is dead code. Confirm this and
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
389 BrowserThread::PostTask( 395 BrowserThread::PostTask(
390 BrowserThread::UI, FROM_HERE, 396 BrowserThread::UI, FROM_HERE,
391 base::Bind(&SafeBrowsingService::ProcessResourceRequest, this, info)); 397 base::Bind(&SafeBrowsingService::ProcessResourceRequest, this, info));
392 #endif 398 #endif
393 } 399 }
394 400
395 SafeBrowsingUIManager* SafeBrowsingService::CreateUIManager() { 401 SafeBrowsingUIManager* SafeBrowsingService::CreateUIManager() {
396 return new SafeBrowsingUIManager(this); 402 return new SafeBrowsingUIManager(this);
397 } 403 }
398 404
405
406 V4LocalDatabaseManager* SafeBrowsingService::CreateV4LocalDatabaseManager() {
Nathan Parker 2016/04/28 17:33:21 This should probably go in the services_delegate[_
vakh (use Gerrit instead) 2016/04/29 18:06:47 Done.
407 return new V4LocalDatabaseManager();
408 }
409
399 SafeBrowsingDatabaseManager* SafeBrowsingService::CreateDatabaseManager() { 410 SafeBrowsingDatabaseManager* SafeBrowsingService::CreateDatabaseManager() {
400 #if defined(SAFE_BROWSING_DB_LOCAL) 411 #if defined(SAFE_BROWSING_DB_LOCAL)
401 return new LocalSafeBrowsingDatabaseManager(this); 412 return new LocalSafeBrowsingDatabaseManager(this);
402 #elif defined(SAFE_BROWSING_DB_REMOTE) 413 #elif defined(SAFE_BROWSING_DB_REMOTE)
403 return new RemoteSafeBrowsingDatabaseManager(); 414 return new RemoteSafeBrowsingDatabaseManager();
404 #else 415 #else
405 return NULL; 416 return NULL;
406 #endif 417 #endif
407 } 418 }
408 419
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
472 SafeBrowsingService::GetProtocolManagerDelegate() { 483 SafeBrowsingService::GetProtocolManagerDelegate() {
473 #if defined(SAFE_BROWSING_DB_LOCAL) 484 #if defined(SAFE_BROWSING_DB_LOCAL)
474 return static_cast<LocalSafeBrowsingDatabaseManager*>( 485 return static_cast<LocalSafeBrowsingDatabaseManager*>(
475 database_manager_.get()); 486 database_manager_.get());
476 #else 487 #else
477 NOTREACHED(); 488 NOTREACHED();
478 return NULL; 489 return NULL;
479 #endif 490 #endif
480 } 491 }
481 492
493 bool SafeBrowsingService::IsV4LocalDatabaseManagerEnabled() {
494 const std::string group_name = base::FieldTrialList::FindFullName(
495 "SafeBrowsingV4LocalDatabaseManagerEnabled");
496 return StartsWith(group_name, "Enabled", base::CompareCase::SENSITIVE);
497 }
498
482 void SafeBrowsingService::StartOnIOThread( 499 void SafeBrowsingService::StartOnIOThread(
483 net::URLRequestContextGetter* url_request_context_getter) { 500 net::URLRequestContextGetter* url_request_context_getter) {
484 DCHECK_CURRENTLY_ON(BrowserThread::IO); 501 DCHECK_CURRENTLY_ON(BrowserThread::IO);
485 if (enabled_) 502 if (enabled_)
486 return; 503 return;
487 enabled_ = true; 504 enabled_ = true;
488 505
489 SafeBrowsingProtocolConfig config = GetProtocolConfig(); 506 SafeBrowsingProtocolConfig config = GetProtocolConfig();
490 V4ProtocolConfig v4_config = GetV4ProtocolConfig(); 507 V4ProtocolConfig v4_config = GetV4ProtocolConfig();
491 508
492 #if defined(SAFE_BROWSING_DB_LOCAL) || defined(SAFE_BROWSING_DB_REMOTE) 509 #if defined(SAFE_BROWSING_DB_LOCAL) || defined(SAFE_BROWSING_DB_REMOTE)
493 DCHECK(database_manager_.get()); 510 DCHECK(database_manager_.get());
494 database_manager_->StartOnIOThread(url_request_context_getter, v4_config); 511 database_manager_->StartOnIOThread(url_request_context_getter, v4_config);
495 #endif 512 #endif
496 513
497 #if defined(SAFE_BROWSING_DB_LOCAL) 514 #if defined(SAFE_BROWSING_DB_LOCAL)
498 SafeBrowsingProtocolManagerDelegate* protocol_manager_delegate = 515 SafeBrowsingProtocolManagerDelegate* protocol_manager_delegate =
499 GetProtocolManagerDelegate(); 516 GetProtocolManagerDelegate();
500 if (protocol_manager_delegate) { 517 if (protocol_manager_delegate) {
501 protocol_manager_ = SafeBrowsingProtocolManager::Create( 518 protocol_manager_ = SafeBrowsingProtocolManager::Create(
502 protocol_manager_delegate, url_request_context_getter, config); 519 protocol_manager_delegate, url_request_context_getter, config);
503 protocol_manager_->Initialize(); 520 protocol_manager_->Initialize();
504 } 521 }
505 #endif 522 #endif
506 523
524 if (IsV4LocalDatabaseManagerEnabled()) {
Nathan Parker 2016/04/28 17:33:21 Rather than checking the field trial again (it sho
vakh (use Gerrit instead) 2016/04/29 18:06:47 Done.
525 DCHECK(v4_local_database_manager_.get());
526 v4_local_database_manager_->StartOnIOThread(url_request_context_getter,
527 v4_config);
528 }
529
507 DCHECK(!ping_manager_); 530 DCHECK(!ping_manager_);
508 ping_manager_ = SafeBrowsingPingManager::Create( 531 ping_manager_ = SafeBrowsingPingManager::Create(
509 url_request_context_getter, config); 532 url_request_context_getter, config);
510 } 533 }
511 534
512 void SafeBrowsingService::StopOnIOThread(bool shutdown) { 535 void SafeBrowsingService::StopOnIOThread(bool shutdown) {
513 DCHECK_CURRENTLY_ON(BrowserThread::IO); 536 DCHECK_CURRENTLY_ON(BrowserThread::IO);
514 537
515 #if defined(SAFE_BROWSING_DB_LOCAL) || defined(SAFE_BROWSING_DB_REMOTE) 538 #if defined(SAFE_BROWSING_DB_LOCAL) || defined(SAFE_BROWSING_DB_REMOTE)
516 database_manager_->StopOnIOThread(shutdown); 539 database_manager_->StopOnIOThread(shutdown);
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
650 ping_manager()->ReportThreatDetails(report); 673 ping_manager()->ReportThreatDetails(report);
651 } 674 }
652 675
653 void SafeBrowsingService::ProcessResourceRequest( 676 void SafeBrowsingService::ProcessResourceRequest(
654 const ResourceRequestInfo& request) { 677 const ResourceRequestInfo& request) {
655 DCHECK_CURRENTLY_ON(BrowserThread::UI); 678 DCHECK_CURRENTLY_ON(BrowserThread::UI);
656 services_delegate_->ProcessResourceRequest(&request); 679 services_delegate_->ProcessResourceRequest(&request);
657 } 680 }
658 681
659 } // namespace safe_browsing 682 } // namespace safe_browsing
OLDNEW
« no previous file with comments | « chrome/browser/safe_browsing/safe_browsing_service.h ('k') | components/safe_browsing_db/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698