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