Give names to all utility processes.
[chromium-blink-merge.git] / chrome / browser / supervised_user / experimental / supervised_user_async_url_checker.h
blob47b76d876b8e920719d45b197da4c8f5a428fda2
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.
5 #ifndef CHROME_BROWSER_SUPERVISED_USER_EXPERIMENTAL_SUPERVISED_USER_ASYNC_URL_CHECKER_H_
6 #define CHROME_BROWSER_SUPERVISED_USER_EXPERIMENTAL_SUPERVISED_USER_ASYNC_URL_CHECKER_H_
8 #include <string>
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 "chrome/browser/supervised_user/supervised_user_url_filter.h"
15 #include "net/url_request/url_fetcher_delegate.h"
16 #include "url/gurl.h"
18 namespace net {
19 class URLFetcher;
20 class URLRequestContextGetter;
23 // This class checks against an online service (currently a Custom Search
24 // Engine using SafeSearch) whether a given URL is safe to visit for a
25 // supervised user, and returns the result asynchronously via a callback.
26 class SupervisedUserAsyncURLChecker : net::URLFetcherDelegate {
27 public:
28 // Returns whether |url| should be blocked. Called from CheckURL.
29 typedef base::Callback<void(const GURL&,
30 SupervisedUserURLFilter::FilteringBehavior,
31 bool /* uncertain */)>
32 CheckCallback;
34 SupervisedUserAsyncURLChecker(net::URLRequestContextGetter* context,
35 const std::string& cx);
36 SupervisedUserAsyncURLChecker(net::URLRequestContextGetter* context,
37 const std::string& cx,
38 size_t cache_size);
39 ~SupervisedUserAsyncURLChecker() override;
41 // Returns whether |callback| was run synchronously.
42 bool CheckURL(const GURL& url, const CheckCallback& callback);
44 private:
45 struct Check;
46 struct CheckResult {
47 CheckResult(SupervisedUserURLFilter::FilteringBehavior behavior,
48 bool uncertain);
49 SupervisedUserURLFilter::FilteringBehavior behavior;
50 bool uncertain;
53 // net::URLFetcherDelegate implementation.
54 void OnURLFetchComplete(const net::URLFetcher* source) override;
56 net::URLRequestContextGetter* context_;
57 std::string cx_;
59 ScopedVector<Check> checks_in_progress_;
61 base::MRUCache<GURL, CheckResult> cache_;
63 DISALLOW_COPY_AND_ASSIGN(SupervisedUserAsyncURLChecker);
66 #endif // CHROME_BROWSER_SUPERVISED_USER_EXPERIMENTAL_SUPERVISED_USER_ASYNC_URL_CHECKER_H_