Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / chrome / browser / supervised_user / experimental / supervised_user_async_url_checker.h
blobbf8907cd50abed2589a69517933604f9616c5cac
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 SupervisedUserAsyncURLChecker(net::URLRequestContextGetter* context,
36 size_t cache_size);
37 ~SupervisedUserAsyncURLChecker() override;
39 // Returns whether |callback| was run synchronously.
40 bool CheckURL(const GURL& url, const CheckCallback& callback);
42 private:
43 struct Check;
44 struct CheckResult {
45 CheckResult(SupervisedUserURLFilter::FilteringBehavior behavior,
46 bool uncertain);
47 SupervisedUserURLFilter::FilteringBehavior behavior;
48 bool uncertain;
51 // net::URLFetcherDelegate implementation.
52 void OnURLFetchComplete(const net::URLFetcher* source) override;
54 net::URLRequestContextGetter* context_;
56 ScopedVector<Check> checks_in_progress_;
58 base::MRUCache<GURL, CheckResult> cache_;
60 DISALLOW_COPY_AND_ASSIGN(SupervisedUserAsyncURLChecker);
63 #endif // CHROME_BROWSER_SUPERVISED_USER_EXPERIMENTAL_SUPERVISED_USER_ASYNC_URL_CHECKER_H_