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

Side by Side Diff: chrome/browser/safe_search_api/safe_search_url_checker.h

Issue 2743923002: Network traffic annotation added to safe_search_url_checker. (Closed)
Patch Set: Annotation updated. Created 3 years, 9 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
« no previous file with comments | « no previous file | chrome/browser/safe_search_api/safe_search_url_checker.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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_SAFE_SEARCH_API_SAFE_SEARCH_URL_CHECKER_H_ 5 #ifndef CHROME_BROWSER_SAFE_SEARCH_API_SAFE_SEARCH_URL_CHECKER_H_
6 #define CHROME_BROWSER_SAFE_SEARCH_API_SAFE_SEARCH_URL_CHECKER_H_ 6 #define CHROME_BROWSER_SAFE_SEARCH_API_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 "net/traffic_annotation/network_traffic_annotation.h"
15 #include "net/url_request/url_fetcher_delegate.h" 16 #include "net/url_request/url_fetcher_delegate.h"
16 #include "url/gurl.h" 17 #include "url/gurl.h"
17 18
18 namespace net { 19 namespace net {
19 class URLFetcher; 20 class URLFetcher;
20 class URLRequestContextGetter; 21 class URLRequestContextGetter;
21 } 22 }
22 23
23 // This class uses the SafeSearch API to check the SafeSearch classification 24 // This class uses the SafeSearch API to check the SafeSearch classification
24 // of the content on a given URL and returns the result asynchronously 25 // of the content on a given URL and returns the result asynchronously
25 // via a callback. 26 // via a callback.
26 class SafeSearchURLChecker : net::URLFetcherDelegate { 27 class SafeSearchURLChecker : net::URLFetcherDelegate {
27 public: 28 public:
28 enum class Classification { SAFE, UNSAFE }; 29 enum class Classification { SAFE, UNSAFE };
29 30
30 // Returns whether |url| should be blocked. Called from CheckURL. 31 // Returns whether |url| should be blocked. Called from CheckURL.
31 using CheckCallback = base::Callback< 32 using CheckCallback = base::Callback<
32 void(const GURL&, Classification classification, bool /* uncertain */)>; 33 void(const GURL&, Classification classification, bool /* uncertain */)>;
33 34
34 explicit SafeSearchURLChecker(net::URLRequestContextGetter* context); 35 explicit SafeSearchURLChecker(
35 SafeSearchURLChecker(net::URLRequestContextGetter* context, 36 net::URLRequestContextGetter* context,
36 size_t cache_size); 37 const net::NetworkTrafficAnnotationTag& traffic_annotation);
38 SafeSearchURLChecker(
39 net::URLRequestContextGetter* context,
40 const net::NetworkTrafficAnnotationTag& traffic_annotation,
41 size_t cache_size);
37 ~SafeSearchURLChecker() override; 42 ~SafeSearchURLChecker() override;
38 43
39 // Returns whether |callback| was run synchronously. 44 // Returns whether |callback| was run synchronously.
40 bool CheckURL(const GURL& url, const CheckCallback& callback); 45 bool CheckURL(const GURL& url, const CheckCallback& callback);
41 46
42 void SetCacheTimeoutForTesting(const base::TimeDelta& timeout) { 47 void SetCacheTimeoutForTesting(const base::TimeDelta& timeout) {
43 cache_timeout_ = timeout; 48 cache_timeout_ = timeout;
44 } 49 }
45 50
46 private: 51 private:
47 struct Check; 52 struct Check;
48 struct CheckResult { 53 struct CheckResult {
49 CheckResult(Classification classification, bool uncertain); 54 CheckResult(Classification classification, bool uncertain);
50 Classification classification; 55 Classification classification;
51 bool uncertain; 56 bool uncertain;
52 base::TimeTicks timestamp; 57 base::TimeTicks timestamp;
53 }; 58 };
54 59
55 // net::URLFetcherDelegate implementation. 60 // net::URLFetcherDelegate implementation.
56 void OnURLFetchComplete(const net::URLFetcher* source) override; 61 void OnURLFetchComplete(const net::URLFetcher* source) override;
57 62
58 net::URLRequestContextGetter* context_; 63 net::URLRequestContextGetter* context_;
64 const net::NetworkTrafficAnnotationTag traffic_annotation_;
59 65
60 ScopedVector<Check> checks_in_progress_; 66 ScopedVector<Check> checks_in_progress_;
61 67
62 base::MRUCache<GURL, CheckResult> cache_; 68 base::MRUCache<GURL, CheckResult> cache_;
63 base::TimeDelta cache_timeout_; 69 base::TimeDelta cache_timeout_;
64 70
65 DISALLOW_COPY_AND_ASSIGN(SafeSearchURLChecker); 71 DISALLOW_COPY_AND_ASSIGN(SafeSearchURLChecker);
66 }; 72 };
67 73
68 #endif // CHROME_BROWSER_SAFE_SEARCH_API_SAFE_SEARCH_URL_CHECKER_H_ 74 #endif // CHROME_BROWSER_SAFE_SEARCH_API_SAFE_SEARCH_URL_CHECKER_H_
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/safe_search_api/safe_search_url_checker.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698