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

Side by Side Diff: chrome/browser/supervised_user/experimental/supervised_user_async_url_checker.cc

Issue 690423003: Supervised user SafeSites: Expose & use API key from src-internal (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 6 years, 1 month 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/supervised_user/experimental/supervised_user_async_url_ checker.h" 5 #include "chrome/browser/supervised_user/experimental/supervised_user_async_url_ checker.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/callback.h" 9 #include "base/callback.h"
10 #include "base/json/json_reader.h" 10 #include "base/json/json_reader.h"
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 174
175 SupervisedUserAsyncURLChecker::Check::~Check() {} 175 SupervisedUserAsyncURLChecker::Check::~Check() {}
176 176
177 SupervisedUserAsyncURLChecker::CheckResult::CheckResult( 177 SupervisedUserAsyncURLChecker::CheckResult::CheckResult(
178 SupervisedUserURLFilter::FilteringBehavior behavior, bool uncertain) 178 SupervisedUserURLFilter::FilteringBehavior behavior, bool uncertain)
179 : behavior(behavior), uncertain(uncertain) { 179 : behavior(behavior), uncertain(uncertain) {
180 } 180 }
181 181
182 SupervisedUserAsyncURLChecker::SupervisedUserAsyncURLChecker( 182 SupervisedUserAsyncURLChecker::SupervisedUserAsyncURLChecker(
183 URLRequestContextGetter* context, 183 URLRequestContextGetter* context,
184 const std::string& cx, 184 const std::string& cx)
185 const std::string& api_key)
186 : context_(context), cx_(cx), cache_(kDefaultCacheSize) { 185 : context_(context), cx_(cx), cache_(kDefaultCacheSize) {
187 SetApiKey(api_key);
188 } 186 }
189 187
190 SupervisedUserAsyncURLChecker::SupervisedUserAsyncURLChecker( 188 SupervisedUserAsyncURLChecker::SupervisedUserAsyncURLChecker(
191 URLRequestContextGetter* context, 189 URLRequestContextGetter* context,
192 const std::string& cx, 190 const std::string& cx,
193 const std::string& api_key,
194 size_t cache_size) 191 size_t cache_size)
195 : context_(context), cx_(cx), cache_(cache_size) { 192 : context_(context), cx_(cx), cache_(cache_size) {
196 SetApiKey(api_key);
197 } 193 }
198 194
199 SupervisedUserAsyncURLChecker::~SupervisedUserAsyncURLChecker() {} 195 SupervisedUserAsyncURLChecker::~SupervisedUserAsyncURLChecker() {}
200 196
201 bool SupervisedUserAsyncURLChecker::CheckURL(const GURL& url, 197 bool SupervisedUserAsyncURLChecker::CheckURL(const GURL& url,
202 const CheckCallback& callback) { 198 const CheckCallback& callback) {
203 // TODO(treib): Hack: For now, allow all Google URLs to save search QPS. If we 199 // TODO(treib): Hack: For now, allow all Google URLs to save search QPS. If we
204 // ever remove this, we should find a way to allow at least the NTP. 200 // ever remove this, we should find a way to allow at least the NTP.
205 if (google_util::IsGoogleDomainUrl(url, 201 if (google_util::IsGoogleDomainUrl(url,
206 google_util::ALLOW_SUBDOMAIN, 202 google_util::ALLOW_SUBDOMAIN,
(...skipping 23 matching lines...) Expand all
230 // See if we already have a check in progress for this URL. 226 // See if we already have a check in progress for this URL.
231 for (Check* check : checks_in_progress_) { 227 for (Check* check : checks_in_progress_) {
232 if (check->url == url) { 228 if (check->url == url) {
233 DVLOG(1) << "Adding to pending check for " << url.spec(); 229 DVLOG(1) << "Adding to pending check for " << url.spec();
234 check->callbacks.push_back(callback); 230 check->callbacks.push_back(callback);
235 return false; 231 return false;
236 } 232 }
237 } 233 }
238 234
239 DVLOG(1) << "Checking URL " << url; 235 DVLOG(1) << "Checking URL " << url;
236 std::string api_key = google_apis::GetSafeSitesAPIKey();
240 scoped_ptr<URLFetcher> fetcher_safe( 237 scoped_ptr<URLFetcher> fetcher_safe(
241 CreateFetcher(this, context_, cx_, api_key_, url, true)); 238 CreateFetcher(this, context_, cx_, api_key, url, true));
242 scoped_ptr<URLFetcher> fetcher_unsafe( 239 scoped_ptr<URLFetcher> fetcher_unsafe(
243 CreateFetcher(this, context_, cx_, api_key_, url, false)); 240 CreateFetcher(this, context_, cx_, api_key, url, false));
244 fetcher_safe->Start(); 241 fetcher_safe->Start();
245 fetcher_unsafe->Start(); 242 fetcher_unsafe->Start();
246 checks_in_progress_.push_back( 243 checks_in_progress_.push_back(
247 new Check(url, fetcher_safe.Pass(), fetcher_unsafe.Pass(), callback)); 244 new Check(url, fetcher_safe.Pass(), fetcher_unsafe.Pass(), callback));
248 return false; 245 return false;
249 } 246 }
250 247
251 void SupervisedUserAsyncURLChecker::SetApiKey(const std::string& api_key) {
252 api_key_ = api_key.empty() ? google_apis::GetAPIKey() : api_key;
253 }
254
255 void SupervisedUserAsyncURLChecker::OnURLFetchComplete( 248 void SupervisedUserAsyncURLChecker::OnURLFetchComplete(
256 const net::URLFetcher* source) { 249 const net::URLFetcher* source) {
257 ScopedVector<Check>::iterator it = checks_in_progress_.begin(); 250 ScopedVector<Check>::iterator it = checks_in_progress_.begin();
258 bool is_safe_search_request = false; 251 bool is_safe_search_request = false;
259 while (it != checks_in_progress_.end()) { 252 while (it != checks_in_progress_.end()) {
260 if (source == (*it)->fetcher_safe.get()) { 253 if (source == (*it)->fetcher_safe.get()) {
261 is_safe_search_request = true; 254 is_safe_search_request = true;
262 (*it)->safe_done = true; 255 (*it)->safe_done = true;
263 break; 256 break;
264 } else if (source == (*it)->fetcher_unsafe.get()) { 257 } else if (source == (*it)->fetcher_unsafe.get()) {
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
323 316
324 UMA_HISTOGRAM_TIMES("ManagedUsers.SafeSitesDelay", 317 UMA_HISTOGRAM_TIMES("ManagedUsers.SafeSitesDelay",
325 base::Time::Now() - check->start_time); 318 base::Time::Now() - check->start_time);
326 319
327 cache_.Put(check->url, CheckResult(behavior, uncertain)); 320 cache_.Put(check->url, CheckResult(behavior, uncertain));
328 321
329 for (size_t i = 0; i < check->callbacks.size(); i++) 322 for (size_t i = 0; i < check->callbacks.size(); i++)
330 check->callbacks[i].Run(check->url, behavior, uncertain); 323 check->callbacks[i].Run(check->url, behavior, uncertain);
331 checks_in_progress_.erase(it); 324 checks_in_progress_.erase(it);
332 } 325 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698