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> | 8 #include <string> |
9 | 9 |
10 #include "base/callback_forward.h" | 10 #include "base/callback_forward.h" |
(...skipping 14 matching lines...) Expand all Loading... |
25 // supervised user, and returns the result asynchronously via a callback. | 25 // supervised user, and returns the result asynchronously via a callback. |
26 class SupervisedUserAsyncURLChecker : net::URLFetcherDelegate { | 26 class SupervisedUserAsyncURLChecker : net::URLFetcherDelegate { |
27 public: | 27 public: |
28 // Returns whether |url| should be blocked. Called from CheckURL. | 28 // Returns whether |url| should be blocked. Called from CheckURL. |
29 typedef base::Callback<void(const GURL&, | 29 typedef base::Callback<void(const GURL&, |
30 SupervisedUserURLFilter::FilteringBehavior, | 30 SupervisedUserURLFilter::FilteringBehavior, |
31 bool /* uncertain */)> | 31 bool /* uncertain */)> |
32 CheckCallback; | 32 CheckCallback; |
33 | 33 |
34 SupervisedUserAsyncURLChecker(net::URLRequestContextGetter* context, | 34 SupervisedUserAsyncURLChecker(net::URLRequestContextGetter* context, |
35 const std::string& cx, | 35 const std::string& cx); |
36 const std::string& api_key); | |
37 SupervisedUserAsyncURLChecker(net::URLRequestContextGetter* context, | 36 SupervisedUserAsyncURLChecker(net::URLRequestContextGetter* context, |
38 const std::string& cx, | 37 const std::string& cx, |
39 const std::string& api_key, | |
40 size_t cache_size); | 38 size_t cache_size); |
41 virtual ~SupervisedUserAsyncURLChecker(); | 39 virtual ~SupervisedUserAsyncURLChecker(); |
42 | 40 |
43 // Returns whether |callback| was run synchronously. | 41 // Returns whether |callback| was run synchronously. |
44 bool CheckURL(const GURL& url, const CheckCallback& callback); | 42 bool CheckURL(const GURL& url, const CheckCallback& callback); |
45 | 43 |
46 private: | 44 private: |
47 struct Check; | 45 struct Check; |
48 struct CheckResult { | 46 struct CheckResult { |
49 CheckResult(SupervisedUserURLFilter::FilteringBehavior behavior, | 47 CheckResult(SupervisedUserURLFilter::FilteringBehavior behavior, |
50 bool uncertain); | 48 bool uncertain); |
51 SupervisedUserURLFilter::FilteringBehavior behavior; | 49 SupervisedUserURLFilter::FilteringBehavior behavior; |
52 bool uncertain; | 50 bool uncertain; |
53 }; | 51 }; |
54 | 52 |
55 void SetApiKey(const std::string& api_key); | |
56 | |
57 // net::URLFetcherDelegate implementation. | 53 // net::URLFetcherDelegate implementation. |
58 virtual void OnURLFetchComplete(const net::URLFetcher* source) override; | 54 virtual void OnURLFetchComplete(const net::URLFetcher* source) override; |
59 | 55 |
60 net::URLRequestContextGetter* context_; | 56 net::URLRequestContextGetter* context_; |
61 std::string cx_; | 57 std::string cx_; |
62 std::string api_key_; | |
63 | 58 |
64 ScopedVector<Check> checks_in_progress_; | 59 ScopedVector<Check> checks_in_progress_; |
65 | 60 |
66 base::MRUCache<GURL, CheckResult> cache_; | 61 base::MRUCache<GURL, CheckResult> cache_; |
67 | 62 |
68 DISALLOW_COPY_AND_ASSIGN(SupervisedUserAsyncURLChecker); | 63 DISALLOW_COPY_AND_ASSIGN(SupervisedUserAsyncURLChecker); |
69 }; | 64 }; |
70 | 65 |
71 #endif // CHROME_BROWSER_SUPERVISED_USER_EXPERIMENTAL_SUPERVISED_USER_ASYNC_URL
_CHECKER_H_ | 66 #endif // CHROME_BROWSER_SUPERVISED_USER_EXPERIMENTAL_SUPERVISED_USER_ASYNC_URL
_CHECKER_H_ |
OLD | NEW |