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 SupervisedUserAsyncURLChecker(net::URLRequestContextGetter
* context
,
37 ~SupervisedUserAsyncURLChecker() override
;
39 // Returns whether |callback| was run synchronously.
40 bool CheckURL(const GURL
& url
, const CheckCallback
& callback
);
45 CheckResult(SupervisedUserURLFilter::FilteringBehavior behavior
,
47 SupervisedUserURLFilter::FilteringBehavior behavior
;
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_