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

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

Issue 1410853003: [Safe Browsing] Only check main frame and iframe URLs on Mobile, for speed. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rm unecessary thread restriction that interferes with tests Created 5 years, 2 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 "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/strings/string_number_conversions.h"
11 #include "base/strings/string_split.h"
10 #include "base/timer/elapsed_timer.h" 12 #include "base/timer/elapsed_timer.h"
11 #include "chrome/browser/safe_browsing/safe_browsing_api_handler.h" 13 #include "chrome/browser/safe_browsing/safe_browsing_api_handler.h"
14 #include "components/variations/variations_associated_data.h"
12 #include "content/public/browser/browser_thread.h" 15 #include "content/public/browser/browser_thread.h"
13 16
14 using content::BrowserThread; 17 using content::BrowserThread;
15 18
19 namespace {
20
21 // Android field trial
22 const char kAndroidFieldExperiment[] = "SafeBrowsingAndroid";
23 const char kAndroidFieldParam[] = "enabled";
24 const char kAndroidFieldParamEnabledValue[] = "true";
25 const char kAndroidTypesToCheckParam[] = "types_to_check";
26
27 } // namespace
28
16 // 29 //
17 // RemoteSafeBrowsingDatabaseManager::ClientRequest methods 30 // RemoteSafeBrowsingDatabaseManager::ClientRequest methods
18 // 31 //
19 class RemoteSafeBrowsingDatabaseManager::ClientRequest { 32 class RemoteSafeBrowsingDatabaseManager::ClientRequest {
20 public: 33 public:
21 ClientRequest(Client* client, 34 ClientRequest(Client* client,
22 RemoteSafeBrowsingDatabaseManager* db_manager, 35 RemoteSafeBrowsingDatabaseManager* db_manager,
23 const GURL& url); 36 const GURL& url);
24 37
25 static void OnRequestDoneWeak(const base::WeakPtr<ClientRequest>& req, 38 static void OnRequestDoneWeak(const base::WeakPtr<ClientRequest>& req,
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 client_->OnCheckBrowseUrlResult(url_, matched_threat_type, metadata); 82 client_->OnCheckBrowseUrlResult(url_, matched_threat_type, metadata);
70 UMA_HISTOGRAM_TIMES("SB2.RemoteCall.Elapsed", timer_.Elapsed()); 83 UMA_HISTOGRAM_TIMES("SB2.RemoteCall.Elapsed", timer_.Elapsed());
71 // CancelCheck() will delete *this. 84 // CancelCheck() will delete *this.
72 db_manager_->CancelCheck(client_); 85 db_manager_->CancelCheck(client_);
73 } 86 }
74 87
75 // 88 //
76 // RemoteSafeBrowsingDatabaseManager methods 89 // RemoteSafeBrowsingDatabaseManager methods
77 // 90 //
78 91
79 // TODO(nparker): Add tests for this class 92 // TODO(nparker): Add more tests for this class
80 RemoteSafeBrowsingDatabaseManager::RemoteSafeBrowsingDatabaseManager() 93 RemoteSafeBrowsingDatabaseManager::RemoteSafeBrowsingDatabaseManager()
81 : enabled_(false) { 94 : enabled_(false) {
82 DCHECK_CURRENTLY_ON(BrowserThread::UI); 95
96 // Check if the field trial is enabled.
97 const std::string enabled_param = variations::GetVariationParamValue(
98 kAndroidFieldExperiment, kAndroidFieldParam);
99 is_android_field_trial_enabled_ =
100 (enabled_param == kAndroidFieldParamEnabledValue);
101
102 // Decide which resource types to check. These two are the minimum.
103 resource_types_to_check_.insert(content::RESOURCE_TYPE_MAIN_FRAME);
104 resource_types_to_check_.insert(content::RESOURCE_TYPE_SUB_FRAME);
105
106 // The param is expected to be a comma-separated list of ints
107 // corresponding to the enum types.
108 const std::string ints_str = variations::GetVariationParamValue(
109 kAndroidFieldExperiment, kAndroidTypesToCheckParam);
110 for (const std::string& val_str : base::SplitString(
111 ints_str, ",", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL)) {
112 int i;
113 if (base::StringToInt(val_str, &i) && i >= 0 &&
114 i < content::RESOURCE_TYPE_LAST_TYPE) {
115 resource_types_to_check_.insert(static_cast<content::ResourceType>(i));
116 }
117 }
83 } 118 }
84 119
85 RemoteSafeBrowsingDatabaseManager::~RemoteSafeBrowsingDatabaseManager() { 120 RemoteSafeBrowsingDatabaseManager::~RemoteSafeBrowsingDatabaseManager() {
86 DCHECK(!enabled_); 121 DCHECK(!enabled_);
87 } 122 }
88 123
89 bool RemoteSafeBrowsingDatabaseManager::IsSupported() const { 124 bool RemoteSafeBrowsingDatabaseManager::IsSupported() const {
90 return SafeBrowsingApiHandler::GetInstance() != nullptr; 125 return SafeBrowsingApiHandler::GetInstance() != nullptr &&
126 is_android_field_trial_enabled_;
127 }
128
129 bool RemoteSafeBrowsingDatabaseManager::ChecksAreAlwaysAsync() const {
130 return true;
131 }
132
133 bool RemoteSafeBrowsingDatabaseManager::CanCheckResourceType(
134 content::ResourceType resource_type) const {
135 return resource_types_to_check_.count(resource_type) > 0;
91 } 136 }
92 137
93 bool RemoteSafeBrowsingDatabaseManager::CanCheckUrl(const GURL& url) const { 138 bool RemoteSafeBrowsingDatabaseManager::CanCheckUrl(const GURL& url) const {
94 return url.SchemeIs(url::kHttpsScheme) || url.SchemeIs(url::kHttpScheme) || 139 return url.SchemeIs(url::kHttpsScheme) || url.SchemeIs(url::kHttpScheme) ||
95 url.SchemeIs(url::kFtpScheme); 140 url.SchemeIs(url::kFtpScheme);
96 } 141 }
97 142
98 bool RemoteSafeBrowsingDatabaseManager::download_protection_enabled() 143 bool RemoteSafeBrowsingDatabaseManager::download_protection_enabled()
99 const { 144 const {
100 return false; 145 return false;
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 256
212 // Call back and delete any remaining clients. OnRequestDone() modifies 257 // Call back and delete any remaining clients. OnRequestDone() modifies
213 // |current_requests_|, so we make a copy first. 258 // |current_requests_|, so we make a copy first.
214 std::vector<ClientRequest*> to_callback(current_requests_); 259 std::vector<ClientRequest*> to_callback(current_requests_);
215 for (auto req : to_callback) { 260 for (auto req : to_callback) {
216 DVLOG(1) << "Stopping: Invoking unfinished req for URL " << req->url(); 261 DVLOG(1) << "Stopping: Invoking unfinished req for URL " << req->url();
217 req->OnRequestDone(SB_THREAT_TYPE_SAFE, std::string()); 262 req->OnRequestDone(SB_THREAT_TYPE_SAFE, std::string());
218 } 263 }
219 enabled_ = false; 264 enabled_ = false;
220 } 265 }
221
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698