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

Side by Side Diff: chrome/browser/supervised_user/supervised_user_url_filter.cc

Issue 2776493005: Convert SupervisedUserResourceThrottle to a NavigationThrottle. (Closed)
Patch Set: Response to comments Created 3 years, 8 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 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/supervised_user_url_filter.h" 5 #include "chrome/browser/supervised_user/supervised_user_url_filter.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <set> 10 #include <set>
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after
234 : default_behavior_(ALLOW), 234 : default_behavior_(ALLOW),
235 contents_(new Contents()), 235 contents_(new Contents()),
236 blacklist_(nullptr), 236 blacklist_(nullptr),
237 amp_cache_path_regex_(kAmpCachePathPattern), 237 amp_cache_path_regex_(kAmpCachePathPattern),
238 google_amp_viewer_path_regex_(kGoogleAmpViewerPathPattern), 238 google_amp_viewer_path_regex_(kGoogleAmpViewerPathPattern),
239 google_web_cache_query_regex_(kGoogleWebCacheQueryPattern), 239 google_web_cache_query_regex_(kGoogleWebCacheQueryPattern),
240 blocking_task_runner_( 240 blocking_task_runner_(
241 BrowserThread::GetBlockingPool() 241 BrowserThread::GetBlockingPool()
242 ->GetTaskRunnerWithShutdownBehavior( 242 ->GetTaskRunnerWithShutdownBehavior(
243 base::SequencedWorkerPool::CONTINUE_ON_SHUTDOWN) 243 base::SequencedWorkerPool::CONTINUE_ON_SHUTDOWN)
244 .get()) { 244 .get()),
245 weak_ptr_factory_(this) {
245 DCHECK(amp_cache_path_regex_.ok()); 246 DCHECK(amp_cache_path_regex_.ok());
246 DCHECK(google_amp_viewer_path_regex_.ok()); 247 DCHECK(google_amp_viewer_path_regex_.ok());
247 DCHECK(google_web_cache_query_regex_.ok()); 248 DCHECK(google_web_cache_query_regex_.ok());
248 // Detach from the current thread so we can be constructed on a different 249 // Detach from the current thread so we can be constructed on a different
249 // thread than the one where we're used. 250 // thread than the one where we're used.
250 DetachFromThread(); 251 DetachFromThread();
251 } 252 }
252 253
253 SupervisedUserURLFilter::~SupervisedUserURLFilter() { 254 SupervisedUserURLFilter::~SupervisedUserURLFilter() {}
254 DCHECK(CalledOnValidThread());
255 }
256 255
257 // static 256 // static
258 SupervisedUserURLFilter::FilteringBehavior 257 SupervisedUserURLFilter::FilteringBehavior
259 SupervisedUserURLFilter::BehaviorFromInt(int behavior_value) { 258 SupervisedUserURLFilter::BehaviorFromInt(int behavior_value) {
260 DCHECK_GE(behavior_value, ALLOW); 259 DCHECK_GE(behavior_value, ALLOW);
261 DCHECK_LE(behavior_value, BLOCK); 260 DCHECK_LE(behavior_value, BLOCK);
262 return static_cast<FilteringBehavior>(behavior_value); 261 return static_cast<FilteringBehavior>(behavior_value);
263 } 262 }
264 263
265 // static 264 // static
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after
474 SupervisedUserURLFilter::FilteringBehavior 473 SupervisedUserURLFilter::FilteringBehavior
475 SupervisedUserURLFilter::GetDefaultFilteringBehavior() const { 474 SupervisedUserURLFilter::GetDefaultFilteringBehavior() const {
476 return default_behavior_; 475 return default_behavior_;
477 } 476 }
478 477
479 void SupervisedUserURLFilter::LoadWhitelists( 478 void SupervisedUserURLFilter::LoadWhitelists(
480 const std::vector<scoped_refptr<SupervisedUserSiteList>>& site_lists) { 479 const std::vector<scoped_refptr<SupervisedUserSiteList>>& site_lists) {
481 DCHECK(CalledOnValidThread()); 480 DCHECK(CalledOnValidThread());
482 481
483 base::PostTaskAndReplyWithResult( 482 base::PostTaskAndReplyWithResult(
484 blocking_task_runner_.get(), 483 blocking_task_runner_.get(), FROM_HERE,
485 FROM_HERE,
486 base::Bind(&LoadWhitelistsOnBlockingPoolThread, site_lists), 484 base::Bind(&LoadWhitelistsOnBlockingPoolThread, site_lists),
487 base::Bind(&SupervisedUserURLFilter::SetContents, this)); 485 base::Bind(&SupervisedUserURLFilter::SetContents,
486 weak_ptr_factory_.GetWeakPtr()));
488 } 487 }
489 488
490 void SupervisedUserURLFilter::SetBlacklist( 489 void SupervisedUserURLFilter::SetBlacklist(
491 const SupervisedUserBlacklist* blacklist) { 490 const SupervisedUserBlacklist* blacklist) {
492 blacklist_ = blacklist; 491 blacklist_ = blacklist;
493 } 492 }
494 493
495 bool SupervisedUserURLFilter::HasBlacklist() const { 494 bool SupervisedUserURLFilter::HasBlacklist() const {
496 return !!blacklist_; 495 return !!blacklist_;
497 } 496 }
498 497
499 void SupervisedUserURLFilter::SetFromPatternsForTesting( 498 void SupervisedUserURLFilter::SetFromPatternsForTesting(
500 const std::vector<std::string>& patterns) { 499 const std::vector<std::string>& patterns) {
501 DCHECK(CalledOnValidThread()); 500 DCHECK(CalledOnValidThread());
502 501
503 base::PostTaskAndReplyWithResult( 502 base::PostTaskAndReplyWithResult(
504 blocking_task_runner_.get(), 503 blocking_task_runner_.get(), FROM_HERE,
505 FROM_HERE,
506 base::Bind(&CreateWhitelistFromPatternsForTesting, patterns), 504 base::Bind(&CreateWhitelistFromPatternsForTesting, patterns),
507 base::Bind(&SupervisedUserURLFilter::SetContents, this)); 505 base::Bind(&SupervisedUserURLFilter::SetContents,
506 weak_ptr_factory_.GetWeakPtr()));
508 } 507 }
509 508
510 void SupervisedUserURLFilter::SetFromSiteListsForTesting( 509 void SupervisedUserURLFilter::SetFromSiteListsForTesting(
511 const std::vector<scoped_refptr<SupervisedUserSiteList>>& site_lists) { 510 const std::vector<scoped_refptr<SupervisedUserSiteList>>& site_lists) {
512 DCHECK(CalledOnValidThread()); 511 DCHECK(CalledOnValidThread());
513 512
514 base::PostTaskAndReplyWithResult( 513 base::PostTaskAndReplyWithResult(
515 blocking_task_runner_.get(), FROM_HERE, 514 blocking_task_runner_.get(), FROM_HERE,
516 base::Bind(&CreateWhitelistsFromSiteListsForTesting, site_lists), 515 base::Bind(&CreateWhitelistsFromSiteListsForTesting, site_lists),
517 base::Bind(&SupervisedUserURLFilter::SetContents, this)); 516 base::Bind(&SupervisedUserURLFilter::SetContents,
517 weak_ptr_factory_.GetWeakPtr()));
518 } 518 }
519 519
520 void SupervisedUserURLFilter::SetManualHosts( 520 void SupervisedUserURLFilter::SetManualHosts(
521 const std::map<std::string, bool>* host_map) { 521 std::map<std::string, bool> host_map) {
522 DCHECK(CalledOnValidThread()); 522 DCHECK(CalledOnValidThread());
523 host_map_ = *host_map; 523 host_map_ = std::move(host_map);
524 } 524 }
525 525
526 void SupervisedUserURLFilter::SetManualURLs( 526 void SupervisedUserURLFilter::SetManualURLs(std::map<GURL, bool> url_map) {
527 const std::map<GURL, bool>* url_map) {
528 DCHECK(CalledOnValidThread()); 527 DCHECK(CalledOnValidThread());
529 url_map_ = *url_map; 528 url_map_ = std::move(url_map);
530 } 529 }
531 530
532 void SupervisedUserURLFilter::InitAsyncURLChecker( 531 void SupervisedUserURLFilter::InitAsyncURLChecker(
533 net::URLRequestContextGetter* context) { 532 net::URLRequestContextGetter* context) {
534 net::NetworkTrafficAnnotationTag traffic_annotation = 533 net::NetworkTrafficAnnotationTag traffic_annotation =
535 net::DefineNetworkTrafficAnnotation("supervised_user_url_filter", R"( 534 net::DefineNetworkTrafficAnnotation("supervised_user_url_filter", R"(
536 semantics { 535 semantics {
537 sender: "Supervised Users" 536 sender: "Supervised Users"
538 description: 537 description:
539 "Checks whether a given URL (or set of URLs) is considered safe by " 538 "Checks whether a given URL (or set of URLs) is considered safe by "
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
680 679
681 FilteringBehavior behavior = 680 FilteringBehavior behavior =
682 GetBehaviorFromSafeSearchClassification(classification); 681 GetBehaviorFromSafeSearchClassification(classification);
683 682
684 callback.Run(behavior, supervised_user_error_page::ASYNC_CHECKER, uncertain); 683 callback.Run(behavior, supervised_user_error_page::ASYNC_CHECKER, uncertain);
685 for (Observer& observer : observers_) { 684 for (Observer& observer : observers_) {
686 observer.OnURLChecked(url, behavior, 685 observer.OnURLChecked(url, behavior,
687 supervised_user_error_page::ASYNC_CHECKER, uncertain); 686 supervised_user_error_page::ASYNC_CHECKER, uncertain);
688 } 687 }
689 } 688 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698