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_
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"
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
{
28 // Returns whether |url| should be blocked. Called from CheckURL.
29 typedef base::Callback
<void(const GURL
&,
30 SupervisedUserURLFilter::FilteringBehavior
,
31 bool /* uncertain */)>
34 SupervisedUserAsyncURLChecker(net::URLRequestContextGetter
* context
,
35 const std::string
& cx
);
36 SupervisedUserAsyncURLChecker(net::URLRequestContextGetter
* context
,
37 const std::string
& cx
,
39 ~SupervisedUserAsyncURLChecker() override
;
41 // Returns whether |callback| was run synchronously.
42 bool CheckURL(const GURL
& url
, const CheckCallback
& callback
);
47 CheckResult(SupervisedUserURLFilter::FilteringBehavior behavior
,
49 SupervisedUserURLFilter::FilteringBehavior behavior
;
53 // net::URLFetcherDelegate implementation.
54 void OnURLFetchComplete(const net::URLFetcher
* source
) override
;
56 net::URLRequestContextGetter
* context_
;
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_