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