OLD | NEW |
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 "content/public/browser/browser_thread.h" | 10 #include "content/public/browser/browser_thread.h" |
10 #include "net/url_request/url_request_context_getter.h" | 11 #include "net/url_request/url_request_context_getter.h" |
11 #include "url/gurl.h" | 12 #include "url/gurl.h" |
12 | 13 |
13 using content::BrowserThread; | 14 using content::BrowserThread; |
14 | 15 |
15 namespace safe_browsing { | 16 namespace safe_browsing { |
16 | 17 |
17 SafeBrowsingDatabaseManager::SafeBrowsingDatabaseManager() {} | 18 SafeBrowsingDatabaseManager::SafeBrowsingDatabaseManager() {} |
18 | 19 |
19 SafeBrowsingDatabaseManager::~SafeBrowsingDatabaseManager() { | 20 SafeBrowsingDatabaseManager::~SafeBrowsingDatabaseManager() { |
20 DCHECK(!v4_get_hash_protocol_manager_); | 21 DCHECK(!v4_get_hash_protocol_manager_); |
21 } | 22 } |
22 | 23 |
23 void SafeBrowsingDatabaseManager::StartOnIOThread( | 24 void SafeBrowsingDatabaseManager::StartOnIOThread( |
24 net::URLRequestContextGetter* request_context_getter, | 25 net::URLRequestContextGetter* request_context_getter, |
25 const V4ProtocolConfig& config) { | 26 const V4ProtocolConfig& config) { |
26 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 27 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
27 | 28 |
28 base::hash_set<UpdateListIdentifier> stores_to_look({GetChromeUrlApiId()}); | |
29 v4_get_hash_protocol_manager_ = V4GetHashProtocolManager::Create( | 29 v4_get_hash_protocol_manager_ = V4GetHashProtocolManager::Create( |
30 request_context_getter, stores_to_look, config); | 30 request_context_getter, GetStoresForFullHashRequests(), config); |
31 } | 31 } |
32 | 32 |
33 // |shutdown| not used. Destroys the v4 protocol managers. This may be called | 33 // |shutdown| not used. Destroys the v4 protocol managers. This may be called |
34 // multiple times during the life of the DatabaseManager. | 34 // multiple times during the life of the DatabaseManager. |
35 // Must be called on IO thread. | 35 // Must be called on IO thread. |
36 void SafeBrowsingDatabaseManager::StopOnIOThread(bool shutdown) { | 36 void SafeBrowsingDatabaseManager::StopOnIOThread(bool shutdown) { |
37 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 37 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
38 | 38 |
39 // Delete pending checks, calling back any clients with empty metadata. | 39 // Delete pending checks, calling back any clients with empty metadata. |
40 for (const SafeBrowsingApiCheck* check : api_checks_) { | 40 for (const SafeBrowsingApiCheck* check : api_checks_) { |
(...skipping 23 matching lines...) Expand all Loading... |
64 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 64 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
65 ApiCheckSet::iterator it = FindClientApiCheck(client); | 65 ApiCheckSet::iterator it = FindClientApiCheck(client); |
66 if (it != api_checks_.end()) { | 66 if (it != api_checks_.end()) { |
67 api_checks_.erase(it); | 67 api_checks_.erase(it); |
68 return true; | 68 return true; |
69 } | 69 } |
70 NOTREACHED(); | 70 NOTREACHED(); |
71 return false; | 71 return false; |
72 } | 72 } |
73 | 73 |
| 74 std::unordered_set<UpdateListIdentifier> |
| 75 SafeBrowsingDatabaseManager::GetStoresForFullHashRequests() { |
| 76 return std::unordered_set<UpdateListIdentifier>({GetChromeUrlApiId()}); |
| 77 } |
| 78 |
74 bool SafeBrowsingDatabaseManager::CheckApiBlacklistUrl(const GURL& url, | 79 bool SafeBrowsingDatabaseManager::CheckApiBlacklistUrl(const GURL& url, |
75 Client* client) { | 80 Client* client) { |
76 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 81 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
77 DCHECK(v4_get_hash_protocol_manager_); | 82 DCHECK(v4_get_hash_protocol_manager_); |
78 | 83 |
79 // Make sure we can check this url. | 84 // Make sure we can check this url. |
80 if (!(url.SchemeIs(url::kHttpScheme) || url.SchemeIs(url::kHttpsScheme))) { | 85 if (!(url.SchemeIs(url::kHttpScheme) || url.SchemeIs(url::kHttpsScheme))) { |
81 return true; | 86 return true; |
82 } | 87 } |
83 | 88 |
(...skipping 27 matching lines...) Expand all Loading... |
111 } | 116 } |
112 | 117 |
113 SafeBrowsingDatabaseManager::SafeBrowsingApiCheck::SafeBrowsingApiCheck( | 118 SafeBrowsingDatabaseManager::SafeBrowsingApiCheck::SafeBrowsingApiCheck( |
114 const GURL& url, | 119 const GURL& url, |
115 Client* client) | 120 Client* client) |
116 : url_(url), client_(client) {} | 121 : url_(url), client_(client) {} |
117 | 122 |
118 SafeBrowsingDatabaseManager::SafeBrowsingApiCheck::~SafeBrowsingApiCheck() {} | 123 SafeBrowsingDatabaseManager::SafeBrowsingApiCheck::~SafeBrowsingApiCheck() {} |
119 | 124 |
120 } // namespace safe_browsing | 125 } // namespace safe_browsing |
OLD | NEW |