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

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

Issue 2399823002: Extract the SafeSearch client to a separate directory (Closed)
Patch Set: Created 4 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 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>
11 #include <utility> 11 #include <utility>
12 12
13 #include "base/containers/hash_tables.h" 13 #include "base/containers/hash_tables.h"
14 #include "base/files/file_path.h" 14 #include "base/files/file_path.h"
15 #include "base/json/json_file_value_serializer.h" 15 #include "base/json/json_file_value_serializer.h"
16 #include "base/macros.h" 16 #include "base/macros.h"
17 #include "base/memory/ptr_util.h" 17 #include "base/memory/ptr_util.h"
18 #include "base/sha1.h" 18 #include "base/sha1.h"
19 #include "base/strings/string_number_conversions.h" 19 #include "base/strings/string_number_conversions.h"
20 #include "base/strings/string_util.h" 20 #include "base/strings/string_util.h"
21 #include "base/task_runner_util.h" 21 #include "base/task_runner_util.h"
22 #include "base/threading/sequenced_worker_pool.h" 22 #include "base/threading/sequenced_worker_pool.h"
23 #include "chrome/browser/supervised_user/experimental/supervised_user_async_url_ checker.h"
24 #include "chrome/browser/supervised_user/experimental/supervised_user_blacklist. h" 23 #include "chrome/browser/supervised_user/experimental/supervised_user_blacklist. h"
25 #include "components/policy/core/browser/url_blacklist_manager.h" 24 #include "components/policy/core/browser/url_blacklist_manager.h"
26 #include "components/url_formatter/url_fixer.h" 25 #include "components/url_formatter/url_fixer.h"
27 #include "components/url_matcher/url_matcher.h" 26 #include "components/url_matcher/url_matcher.h"
28 #include "content/public/browser/browser_thread.h" 27 #include "content/public/browser/browser_thread.h"
29 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" 28 #include "net/base/registry_controlled_domains/registry_controlled_domain.h"
30 #include "url/gurl.h" 29 #include "url/gurl.h"
31 30
32 using content::BrowserThread; 31 using content::BrowserThread;
33 using net::registry_controlled_domains::EXCLUDE_UNKNOWN_REGISTRIES; 32 using net::registry_controlled_domains::EXCLUDE_UNKNOWN_REGISTRIES;
34 using net::registry_controlled_domains::EXCLUDE_PRIVATE_REGISTRIES; 33 using net::registry_controlled_domains::EXCLUDE_PRIVATE_REGISTRIES;
35 using net::registry_controlled_domains::GetRegistryLength; 34 using net::registry_controlled_domains::GetRegistryLength;
36 using policy::URLBlacklist; 35 using policy::URLBlacklist;
37 using url_matcher::URLMatcher; 36 using url_matcher::URLMatcher;
38 using url_matcher::URLMatcherConditionSet; 37 using url_matcher::URLMatcherConditionSet;
39 38
40 using HostnameHash = SupervisedUserSiteList::HostnameHash; 39 using HostnameHash = SupervisedUserSiteList::HostnameHash;
41 40
42 namespace { 41 namespace {
43 42
44 struct HashHostnameHash { 43 struct HashHostnameHash {
45 size_t operator()(const HostnameHash& value) const { 44 size_t operator()(const HostnameHash& value) const {
46 return value.hash(); 45 return value.hash();
47 } 46 }
48 }; 47 };
49 48
49 SupervisedUserURLFilter::FilteringBehavior
50 GetBehaviorFromSafeSearchClassification(
51 SafeSearchURLChecker::Classification classification) {
52 switch (classification) {
53 case SafeSearchURLChecker::SAFE:
54 return SupervisedUserURLFilter::ALLOW;
55 case SafeSearchURLChecker::UNSAFE:
56 return SupervisedUserURLFilter::BLOCK;
57 }
58 NOTREACHED() << "Every SafeSearchURLChecker::Classification value must have "
59 "a FilteringBehavior interpretation.";
Marc Treib 2016/10/06 13:16:42 We'll get a compile error anyway if the switch doe
msramek 2016/10/06 15:08:41 I know :) I just meant it as a comment and felt li
Marc Treib 2016/10/06 15:17:15 Yes, please do keep the NOTREACHED!
60 return SupervisedUserURLFilter::BLOCK;
61 }
62
50 } // namespace 63 } // namespace
51 64
52 struct SupervisedUserURLFilter::Contents { 65 struct SupervisedUserURLFilter::Contents {
53 URLMatcher url_matcher; 66 URLMatcher url_matcher;
54 base::hash_multimap<HostnameHash, 67 base::hash_multimap<HostnameHash,
55 scoped_refptr<SupervisedUserSiteList>, 68 scoped_refptr<SupervisedUserSiteList>,
56 HashHostnameHash> hostname_hashes; 69 HashHostnameHash> hostname_hashes;
57 // This only tracks pattern lists. 70 // This only tracks pattern lists.
58 std::map<URLMatcherConditionSet::ID, scoped_refptr<SupervisedUserSiteList>> 71 std::map<URLMatcherConditionSet::ID, scoped_refptr<SupervisedUserSiteList>>
59 site_lists_by_matcher_id; 72 site_lists_by_matcher_id;
(...skipping 384 matching lines...) Expand 10 before | Expand all | Expand 10 after
444 } 457 }
445 458
446 void SupervisedUserURLFilter::SetManualURLs( 459 void SupervisedUserURLFilter::SetManualURLs(
447 const std::map<GURL, bool>* url_map) { 460 const std::map<GURL, bool>* url_map) {
448 DCHECK(CalledOnValidThread()); 461 DCHECK(CalledOnValidThread());
449 url_map_ = *url_map; 462 url_map_ = *url_map;
450 } 463 }
451 464
452 void SupervisedUserURLFilter::InitAsyncURLChecker( 465 void SupervisedUserURLFilter::InitAsyncURLChecker(
453 net::URLRequestContextGetter* context) { 466 net::URLRequestContextGetter* context) {
454 async_url_checker_.reset(new SupervisedUserAsyncURLChecker(context)); 467 async_url_checker_.reset(new SafeSearchURLChecker(context));
455 } 468 }
456 469
457 void SupervisedUserURLFilter::ClearAsyncURLChecker() { 470 void SupervisedUserURLFilter::ClearAsyncURLChecker() {
458 async_url_checker_.reset(); 471 async_url_checker_.reset();
459 } 472 }
460 473
461 bool SupervisedUserURLFilter::HasAsyncURLChecker() const { 474 bool SupervisedUserURLFilter::HasAsyncURLChecker() const {
462 return !!async_url_checker_; 475 return !!async_url_checker_;
463 } 476 }
464 477
(...skipping 21 matching lines...) Expand all
486 499
487 void SupervisedUserURLFilter::SetContents(std::unique_ptr<Contents> contents) { 500 void SupervisedUserURLFilter::SetContents(std::unique_ptr<Contents> contents) {
488 DCHECK(CalledOnValidThread()); 501 DCHECK(CalledOnValidThread());
489 contents_ = std::move(contents); 502 contents_ = std::move(contents);
490 FOR_EACH_OBSERVER(Observer, observers_, OnSiteListUpdated()); 503 FOR_EACH_OBSERVER(Observer, observers_, OnSiteListUpdated());
491 } 504 }
492 505
493 void SupervisedUserURLFilter::CheckCallback( 506 void SupervisedUserURLFilter::CheckCallback(
494 const FilteringBehaviorCallback& callback, 507 const FilteringBehaviorCallback& callback,
495 const GURL& url, 508 const GURL& url,
496 FilteringBehavior behavior, 509 SafeSearchURLChecker::Classification classification,
497 bool uncertain) const { 510 bool uncertain) const {
498 DCHECK(default_behavior_ != BLOCK); 511 DCHECK(default_behavior_ != BLOCK);
499 512
513 FilteringBehavior behavior =
514 GetBehaviorFromSafeSearchClassification(classification);
515
500 callback.Run(behavior, supervised_user_error_page::ASYNC_CHECKER, uncertain); 516 callback.Run(behavior, supervised_user_error_page::ASYNC_CHECKER, uncertain);
501 FOR_EACH_OBSERVER( 517 FOR_EACH_OBSERVER(
502 Observer, observers_, 518 Observer, observers_,
503 OnURLChecked(url, behavior, supervised_user_error_page::ASYNC_CHECKER, 519 OnURLChecked(url, behavior, supervised_user_error_page::ASYNC_CHECKER,
504 uncertain)); 520 uncertain));
505 } 521 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698