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

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

Issue 2399823002: Extract the SafeSearch client to a separate directory (Closed)
Patch Set: Renamed to safe_search_api Created 4 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
(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_SAFE_SEARCH_API_SAFE_SEARCH_URL_CHECKER_H_
6 #define CHROME_BROWSER_SAFE_SEARCH_API_SAFE_SEARCH_URL_CHECKER_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 "net/url_request/url_fetcher_delegate.h"
16 #include "url/gurl.h"
17
18 namespace net {
19 class URLFetcher;
20 class URLRequestContextGetter;
21 }
22
23 // 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 // via a callback.
26 class SafeSearchURLChecker : net::URLFetcherDelegate {
27 public:
28 enum class Classification { SAFE, UNSAFE };
29
30 // Returns whether |url| should be blocked. Called from CheckURL.
31 using CheckCallback = base::Callback<
32 void(const GURL&, Classification classification, bool /* uncertain */)>;
33
34 explicit SafeSearchURLChecker(net::URLRequestContextGetter* context);
35 SafeSearchURLChecker(net::URLRequestContextGetter* context,
36 size_t cache_size);
37 ~SafeSearchURLChecker() override;
38
39 // Returns whether |callback| was run synchronously.
40 bool CheckURL(const GURL& url, const CheckCallback& callback);
41
42 void SetCacheTimeoutForTesting(const base::TimeDelta& timeout) {
43 cache_timeout_ = timeout;
44 }
45
46 private:
47 struct Check;
48 struct CheckResult {
49 CheckResult(Classification classification, bool uncertain);
50 Classification classification;
51 bool uncertain;
52 base::TimeTicks timestamp;
53 };
54
55 // net::URLFetcherDelegate implementation.
56 void OnURLFetchComplete(const net::URLFetcher* source) override;
57
58 net::URLRequestContextGetter* context_;
59
60 ScopedVector<Check> checks_in_progress_;
61
62 base::MRUCache<GURL, CheckResult> cache_;
63 base::TimeDelta cache_timeout_;
64
65 DISALLOW_COPY_AND_ASSIGN(SafeSearchURLChecker);
66 };
67
68 #endif // CHROME_BROWSER_SAFE_SEARCH_API_SAFE_SEARCH_URL_CHECKER_H_
OLDNEW
« no previous file with comments | « chrome/browser/safe_search_api/OWNERS ('k') | 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