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

Side by Side Diff: components/safe_browsing_db/database_manager.cc

Issue 2648193002: SafeBrowsing: Move enabled_ to base class DB Manager (Closed)
Patch Set: Fix compile error Created 3 years, 11 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "components/safe_browsing_db/database_manager.h" 5 #include "components/safe_browsing_db/database_manager.h"
6 6
7 #include "base/metrics/histogram_macros.h" 7 #include "base/metrics/histogram_macros.h"
8 #include "components/safe_browsing_db/v4_get_hash_protocol_manager.h" 8 #include "components/safe_browsing_db/v4_get_hash_protocol_manager.h"
9 #include "components/safe_browsing_db/v4_protocol_manager_util.h" 9 #include "components/safe_browsing_db/v4_protocol_manager_util.h"
10 #include "content/public/browser/browser_thread.h" 10 #include "content/public/browser/browser_thread.h"
11 #include "net/url_request/url_request_context_getter.h" 11 #include "net/url_request/url_request_context_getter.h"
12 #include "url/gurl.h" 12 #include "url/gurl.h"
13 13
14 using content::BrowserThread; 14 using content::BrowserThread;
15 15
16 namespace safe_browsing { 16 namespace safe_browsing {
17 17
18 SafeBrowsingDatabaseManager::SafeBrowsingDatabaseManager() {} 18 SafeBrowsingDatabaseManager::SafeBrowsingDatabaseManager() : enabled_(false) {}
19 19
20 SafeBrowsingDatabaseManager::~SafeBrowsingDatabaseManager() { 20 SafeBrowsingDatabaseManager::~SafeBrowsingDatabaseManager() {
21 DCHECK(!v4_get_hash_protocol_manager_); 21 DCHECK(!v4_get_hash_protocol_manager_);
22 } 22 }
23 23
24 bool SafeBrowsingDatabaseManager::CancelApiCheck(Client* client) { 24 bool SafeBrowsingDatabaseManager::CancelApiCheck(Client* client) {
25 DCHECK_CURRENTLY_ON(BrowserThread::IO); 25 DCHECK_CURRENTLY_ON(BrowserThread::IO);
26 ApiCheckSet::iterator it = FindClientApiCheck(client); 26 ApiCheckSet::iterator it = FindClientApiCheck(client);
27 if (it != api_checks_.end()) { 27 if (it != api_checks_.end()) {
28 api_checks_.erase(it); 28 api_checks_.erase(it);
29 return true; 29 return true;
30 } 30 }
31 NOTREACHED(); 31 NOTREACHED();
32 return false; 32 return false;
33 } 33 }
34 34
35 bool SafeBrowsingDatabaseManager::CheckApiBlacklistUrl(const GURL& url, 35 bool SafeBrowsingDatabaseManager::CheckApiBlacklistUrl(const GURL& url,
36 Client* client) { 36 Client* client) {
37 DCHECK_CURRENTLY_ON(BrowserThread::IO); 37 DCHECK_CURRENTLY_ON(BrowserThread::IO);
38 DCHECK(v4_get_hash_protocol_manager_); 38 DCHECK(v4_get_hash_protocol_manager_);
39 39
40 // Make sure we can check this url. 40 // Make sure we can check this url and that the service is enabled.
41 if (!(url.SchemeIs(url::kHttpScheme) || url.SchemeIs(url::kHttpsScheme))) { 41 if (!enabled_ ||
42 !(url.SchemeIs(url::kHttpScheme) || url.SchemeIs(url::kHttpsScheme))) {
42 return true; 43 return true;
43 } 44 }
44 45
45 // There can only be one in-progress check for the same client at a time. 46 // There can only be one in-progress check for the same client at a time.
46 DCHECK(FindClientApiCheck(client) == api_checks_.end()); 47 DCHECK(FindClientApiCheck(client) == api_checks_.end());
47 48
48 std::unique_ptr<SafeBrowsingApiCheck> check( 49 std::unique_ptr<SafeBrowsingApiCheck> check(
49 new SafeBrowsingApiCheck(url, client)); 50 new SafeBrowsingApiCheck(url, client));
50 api_checks_.insert(check.get()); 51 api_checks_.insert(check.get());
51 v4_get_hash_protocol_manager_->GetFullHashesWithApis( 52 v4_get_hash_protocol_manager_->GetFullHashesWithApis(
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 api_checks_.erase(it); 88 api_checks_.erase(it);
88 } 89 }
89 90
90 void SafeBrowsingDatabaseManager::StartOnIOThread( 91 void SafeBrowsingDatabaseManager::StartOnIOThread(
91 net::URLRequestContextGetter* request_context_getter, 92 net::URLRequestContextGetter* request_context_getter,
92 const V4ProtocolConfig& config) { 93 const V4ProtocolConfig& config) {
93 DCHECK_CURRENTLY_ON(BrowserThread::IO); 94 DCHECK_CURRENTLY_ON(BrowserThread::IO);
94 95
95 v4_get_hash_protocol_manager_ = V4GetHashProtocolManager::Create( 96 v4_get_hash_protocol_manager_ = V4GetHashProtocolManager::Create(
96 request_context_getter, GetStoresForFullHashRequests(), config); 97 request_context_getter, GetStoresForFullHashRequests(), config);
98
99 enabled_ = true;
97 } 100 }
98 101
99 // |shutdown| not used. Destroys the v4 protocol managers. This may be called 102 // |shutdown| not used. Destroys the v4 protocol managers. This may be called
100 // multiple times during the life of the DatabaseManager. 103 // multiple times during the life of the DatabaseManager.
101 // Must be called on IO thread. 104 // Must be called on IO thread.
102 void SafeBrowsingDatabaseManager::StopOnIOThread(bool shutdown) { 105 void SafeBrowsingDatabaseManager::StopOnIOThread(bool shutdown) {
103 DCHECK_CURRENTLY_ON(BrowserThread::IO); 106 DCHECK_CURRENTLY_ON(BrowserThread::IO);
104 107
108 enabled_ = false;
109
105 // Delete pending checks, calling back any clients with empty metadata. 110 // Delete pending checks, calling back any clients with empty metadata.
106 for (const SafeBrowsingApiCheck* check : api_checks_) { 111 for (const SafeBrowsingApiCheck* check : api_checks_) {
107 if (check->client()) { 112 if (check->client()) {
108 check->client()->OnCheckApiBlacklistUrlResult(check->url(), 113 check->client()->OnCheckApiBlacklistUrlResult(check->url(),
109 ThreatMetadata()); 114 ThreatMetadata());
110 } 115 }
111 } 116 }
112 117
113 // This cancels all in-flight GetHash requests. 118 // This cancels all in-flight GetHash requests.
114 v4_get_hash_protocol_manager_.reset(); 119 v4_get_hash_protocol_manager_.reset();
115 } 120 }
116 121
117 SafeBrowsingDatabaseManager::SafeBrowsingApiCheck::SafeBrowsingApiCheck( 122 SafeBrowsingDatabaseManager::SafeBrowsingApiCheck::SafeBrowsingApiCheck(
118 const GURL& url, 123 const GURL& url,
119 Client* client) 124 Client* client)
120 : url_(url), client_(client) {} 125 : url_(url), client_(client) {}
121 126
122 SafeBrowsingDatabaseManager::SafeBrowsingApiCheck::~SafeBrowsingApiCheck() {} 127 SafeBrowsingDatabaseManager::SafeBrowsingApiCheck::~SafeBrowsingApiCheck() {}
123 128
124 } // namespace safe_browsing 129 } // namespace safe_browsing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698