OLD | NEW |
---|---|
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 #ifndef CHROME_BROWSER_SUPERVISED_USER_EXPERIMENTAL_SUPERVISED_USER_ASYNC_URL_CH ECKER_H_ | 5 #ifndef CHROME_BROWSER_SAFE_SEARCH_SAFE_SEARCH_URL_CHECKER_H_ |
6 #define CHROME_BROWSER_SUPERVISED_USER_EXPERIMENTAL_SUPERVISED_USER_ASYNC_URL_CH ECKER_H_ | 6 #define CHROME_BROWSER_SAFE_SEARCH_SAFE_SEARCH_URL_CHECKER_H_ |
7 | 7 |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 | 9 |
10 #include "base/callback_forward.h" | 10 #include "base/callback_forward.h" |
11 #include "base/containers/mru_cache.h" | 11 #include "base/containers/mru_cache.h" |
12 #include "base/macros.h" | 12 #include "base/macros.h" |
13 #include "base/memory/scoped_vector.h" | 13 #include "base/memory/scoped_vector.h" |
14 #include "base/time/time.h" | 14 #include "base/time/time.h" |
15 #include "chrome/browser/supervised_user/supervised_user_url_filter.h" | |
16 #include "net/url_request/url_fetcher_delegate.h" | 15 #include "net/url_request/url_fetcher_delegate.h" |
17 #include "url/gurl.h" | 16 #include "url/gurl.h" |
18 | 17 |
19 namespace net { | 18 namespace net { |
20 class URLFetcher; | 19 class URLFetcher; |
21 class URLRequestContextGetter; | 20 class URLRequestContextGetter; |
22 } | 21 } |
23 | 22 |
24 // This class checks against an online service (the SafeSearch API) whether a | 23 // This class uses the SafeSearch API to check the SafeSearch classification |
25 // given URL is safe to visit for a supervised user, and returns the result | 24 // of the content on a given URL and returns the result asynchronously |
26 // asynchronously via a callback. | 25 // via a callback. |
27 class SupervisedUserAsyncURLChecker : net::URLFetcherDelegate { | 26 class SafeSearchURLChecker : net::URLFetcherDelegate { |
28 public: | 27 public: |
28 enum Classification { | |
Marc Treib
2016/10/06 13:16:42
optional: Make this an enum class?
msramek
2016/10/06 15:08:41
Done.
| |
29 SAFE, | |
30 UNSAFE | |
31 }; | |
32 | |
29 // Returns whether |url| should be blocked. Called from CheckURL. | 33 // Returns whether |url| should be blocked. Called from CheckURL. |
30 using CheckCallback = | 34 using CheckCallback = |
31 base::Callback<void(const GURL&, | 35 base::Callback<void(const GURL&, |
32 SupervisedUserURLFilter::FilteringBehavior, | 36 Classification classification, |
33 bool /* uncertain */)>; | 37 bool /* uncertain */)>; |
34 | 38 |
35 SupervisedUserAsyncURLChecker(net::URLRequestContextGetter* context); | 39 explicit SafeSearchURLChecker(net::URLRequestContextGetter* context); |
36 SupervisedUserAsyncURLChecker(net::URLRequestContextGetter* context, | 40 SafeSearchURLChecker(net::URLRequestContextGetter* context, |
37 size_t cache_size); | 41 size_t cache_size); |
38 ~SupervisedUserAsyncURLChecker() override; | 42 ~SafeSearchURLChecker() override; |
39 | 43 |
40 // Returns whether |callback| was run synchronously. | 44 // Returns whether |callback| was run synchronously. |
41 bool CheckURL(const GURL& url, const CheckCallback& callback); | 45 bool CheckURL(const GURL& url, const CheckCallback& callback); |
42 | 46 |
43 void SetCacheTimeoutForTesting(const base::TimeDelta& timeout) { | 47 void SetCacheTimeoutForTesting(const base::TimeDelta& timeout) { |
44 cache_timeout_ = timeout; | 48 cache_timeout_ = timeout; |
45 } | 49 } |
46 | 50 |
47 private: | 51 private: |
48 struct Check; | 52 struct Check; |
49 struct CheckResult { | 53 struct CheckResult { |
50 CheckResult(SupervisedUserURLFilter::FilteringBehavior behavior, | 54 CheckResult(Classification classification, bool uncertain); |
51 bool uncertain); | 55 Classification classification; |
52 SupervisedUserURLFilter::FilteringBehavior behavior; | |
53 bool uncertain; | 56 bool uncertain; |
54 base::TimeTicks timestamp; | 57 base::TimeTicks timestamp; |
55 }; | 58 }; |
56 | 59 |
57 // net::URLFetcherDelegate implementation. | 60 // net::URLFetcherDelegate implementation. |
58 void OnURLFetchComplete(const net::URLFetcher* source) override; | 61 void OnURLFetchComplete(const net::URLFetcher* source) override; |
59 | 62 |
60 net::URLRequestContextGetter* context_; | 63 net::URLRequestContextGetter* context_; |
61 | 64 |
62 ScopedVector<Check> checks_in_progress_; | 65 ScopedVector<Check> checks_in_progress_; |
63 | 66 |
64 base::MRUCache<GURL, CheckResult> cache_; | 67 base::MRUCache<GURL, CheckResult> cache_; |
65 base::TimeDelta cache_timeout_; | 68 base::TimeDelta cache_timeout_; |
66 | 69 |
67 DISALLOW_COPY_AND_ASSIGN(SupervisedUserAsyncURLChecker); | 70 DISALLOW_COPY_AND_ASSIGN(SafeSearchURLChecker); |
68 }; | 71 }; |
69 | 72 |
70 #endif // CHROME_BROWSER_SUPERVISED_USER_EXPERIMENTAL_SUPERVISED_USER_ASYNC_URL _CHECKER_H_ | 73 #endif // CHROME_BROWSER_SAFE_SEARCH_SAFE_SEARCH_URL_CHECKER_H_ |
OLD | NEW |