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

Side by Side Diff: chrome/browser/supervised_user/experimental/supervised_user_async_url_checker.h

Issue 1403153004: Supervised user SafeSites: don't cache results for more than one hour (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 5 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 #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 const base::TimeDelta& cache_timeout() const { return cache_timeout_; }
Bernhard Bauer 2015/10/20 08:10:03 Do you actually need this method?
Marc Treib 2015/10/20 08:53:55 No. Removed.
42 void set_cache_timeout(const base::TimeDelta& timeout) {
Bernhard Bauer 2015/10/20 08:10:03 Name this method SetCacheTimeoutForTesting?
Marc Treib 2015/10/20 08:53:55 Done.
43 cache_timeout_ = timeout;
44 }
45
42 private: 46 private:
43 struct Check; 47 struct Check;
44 struct CheckResult { 48 struct CheckResult {
45 CheckResult(SupervisedUserURLFilter::FilteringBehavior behavior, 49 CheckResult(SupervisedUserURLFilter::FilteringBehavior behavior,
46 bool uncertain); 50 bool uncertain);
47 SupervisedUserURLFilter::FilteringBehavior behavior; 51 SupervisedUserURLFilter::FilteringBehavior behavior;
48 bool uncertain; 52 bool uncertain;
53 base::TimeTicks timestamp;
49 }; 54 };
50 55
51 // net::URLFetcherDelegate implementation. 56 // net::URLFetcherDelegate implementation.
52 void OnURLFetchComplete(const net::URLFetcher* source) override; 57 void OnURLFetchComplete(const net::URLFetcher* source) override;
53 58
54 net::URLRequestContextGetter* context_; 59 net::URLRequestContextGetter* context_;
55 60
56 ScopedVector<Check> checks_in_progress_; 61 ScopedVector<Check> checks_in_progress_;
57 62
58 base::MRUCache<GURL, CheckResult> cache_; 63 base::MRUCache<GURL, CheckResult> cache_;
64 base::TimeDelta cache_timeout_;
59 65
60 DISALLOW_COPY_AND_ASSIGN(SupervisedUserAsyncURLChecker); 66 DISALLOW_COPY_AND_ASSIGN(SupervisedUserAsyncURLChecker);
61 }; 67 };
62 68
63 #endif // CHROME_BROWSER_SUPERVISED_USER_EXPERIMENTAL_SUPERVISED_USER_ASYNC_URL _CHECKER_H_ 69 #endif // CHROME_BROWSER_SUPERVISED_USER_EXPERIMENTAL_SUPERVISED_USER_ASYNC_URL _CHECKER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698