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 "chrome/browser/safe_browsing/remote_database_manager.h" | 5 #include "chrome/browser/safe_browsing/remote_database_manager.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/metrics/histogram_macros.h" | 9 #include "base/metrics/histogram_macros.h" |
10 #include "base/timer/elapsed_timer.h" | 10 #include "base/timer/elapsed_timer.h" |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 // TODO(nparker): Add tests for this class | 79 // TODO(nparker): Add tests for this class |
80 RemoteSafeBrowsingDatabaseManager::RemoteSafeBrowsingDatabaseManager() | 80 RemoteSafeBrowsingDatabaseManager::RemoteSafeBrowsingDatabaseManager() |
81 : enabled_(false) { | 81 : enabled_(false) { |
82 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 82 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
83 } | 83 } |
84 | 84 |
85 RemoteSafeBrowsingDatabaseManager::~RemoteSafeBrowsingDatabaseManager() { | 85 RemoteSafeBrowsingDatabaseManager::~RemoteSafeBrowsingDatabaseManager() { |
86 DCHECK(!enabled_); | 86 DCHECK(!enabled_); |
87 } | 87 } |
88 | 88 |
| 89 bool RemoteSafeBrowsingDatabaseManager::IsSupported() const { |
| 90 return SafeBrowsingApiHandler::GetInstance() != nullptr; |
| 91 } |
| 92 |
89 bool RemoteSafeBrowsingDatabaseManager::CanCheckUrl(const GURL& url) const { | 93 bool RemoteSafeBrowsingDatabaseManager::CanCheckUrl(const GURL& url) const { |
90 return url.SchemeIs(url::kHttpsScheme) || url.SchemeIs(url::kHttpScheme) || | 94 return url.SchemeIs(url::kHttpsScheme) || url.SchemeIs(url::kHttpScheme) || |
91 url.SchemeIs(url::kFtpScheme); | 95 url.SchemeIs(url::kFtpScheme); |
92 } | 96 } |
93 | 97 |
94 bool RemoteSafeBrowsingDatabaseManager::download_protection_enabled() | 98 bool RemoteSafeBrowsingDatabaseManager::download_protection_enabled() |
95 const { | 99 const { |
96 return false; | 100 return false; |
97 } | 101 } |
98 | 102 |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
158 bool can_check_url = CanCheckUrl(url); | 162 bool can_check_url = CanCheckUrl(url); |
159 UMA_HISTOGRAM_BOOLEAN("SB2.RemoteCall.CanCheckUrl", can_check_url); | 163 UMA_HISTOGRAM_BOOLEAN("SB2.RemoteCall.CanCheckUrl", can_check_url); |
160 if (!can_check_url) | 164 if (!can_check_url) |
161 return true; // Safe, continue right away. | 165 return true; // Safe, continue right away. |
162 | 166 |
163 scoped_ptr<ClientRequest> req(new ClientRequest(client, this, url)); | 167 scoped_ptr<ClientRequest> req(new ClientRequest(client, this, url)); |
164 std::vector<SBThreatType> threat_types; // Not currently used. | 168 std::vector<SBThreatType> threat_types; // Not currently used. |
165 | 169 |
166 DVLOG(1) << "Checking for client " << client << " and URL " << url; | 170 DVLOG(1) << "Checking for client " << client << " and URL " << url; |
167 SafeBrowsingApiHandler* api_handler = SafeBrowsingApiHandler::GetInstance(); | 171 SafeBrowsingApiHandler* api_handler = SafeBrowsingApiHandler::GetInstance(); |
168 // If your build hits this at run time, then you should have either not built | 172 // This shouldn't happen since SafeBrowsingResourceThrottle checks |
169 // with safe_browsing=3, or set a SafeBrowingApiHandler singleton at startup. | 173 // IsSupported() ealier. |
170 DCHECK(api_handler) << "SafeBrowsingApiHandler was never constructed"; | 174 DCHECK(api_handler) << "SafeBrowsingApiHandler was never constructed"; |
171 api_handler->StartURLCheck( | 175 api_handler->StartURLCheck( |
172 base::Bind(&ClientRequest::OnRequestDoneWeak, req->GetWeakPtr()), url, | 176 base::Bind(&ClientRequest::OnRequestDoneWeak, req->GetWeakPtr()), url, |
173 threat_types); | 177 threat_types); |
174 | 178 |
175 UMA_HISTOGRAM_COUNTS_10000("SB2.RemoteCall.ChecksPending", | 179 UMA_HISTOGRAM_COUNTS_10000("SB2.RemoteCall.ChecksPending", |
176 current_requests_.size()); | 180 current_requests_.size()); |
177 current_requests_.push_back(req.release()); | 181 current_requests_.push_back(req.release()); |
178 | 182 |
179 // Defer the resource load. | 183 // Defer the resource load. |
(...skipping 28 matching lines...) Expand all Loading... |
208 // Call back and delete any remaining clients. OnRequestDone() modifies | 212 // Call back and delete any remaining clients. OnRequestDone() modifies |
209 // |current_requests_|, so we make a copy first. | 213 // |current_requests_|, so we make a copy first. |
210 std::vector<ClientRequest*> to_callback(current_requests_); | 214 std::vector<ClientRequest*> to_callback(current_requests_); |
211 for (auto req : to_callback) { | 215 for (auto req : to_callback) { |
212 DVLOG(1) << "Stopping: Invoking unfinished req for URL " << req->url(); | 216 DVLOG(1) << "Stopping: Invoking unfinished req for URL " << req->url(); |
213 req->OnRequestDone(SB_THREAT_TYPE_SAFE, std::string()); | 217 req->OnRequestDone(SB_THREAT_TYPE_SAFE, std::string()); |
214 } | 218 } |
215 enabled_ = false; | 219 enabled_ = false; |
216 } | 220 } |
217 | 221 |
OLD | NEW |