Componentize kShortcutsDatabaseName into //components/omnibox.
[chromium-blink-merge.git] / chrome / browser / supervised_user / experimental / supervised_user_blacklist_downloader.h
blob871d4e0e42383d8a9dd25d3ae5a2b0c108a9c3d6
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_BLACKLIST_DOWNLOADER_H_
6 #define CHROME_BROWSER_SUPERVISED_USER_EXPERIMENTAL_SUPERVISED_USER_BLACKLIST_DOWNLOADER_H_
8 #include "base/callback.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "base/memory/weak_ptr.h"
11 #include "net/url_request/url_fetcher_delegate.h"
13 namespace base {
14 class FilePath;
15 } // namespace base
17 namespace net {
18 class URLFetcher;
19 class URLRequestContextGetter;
20 } // namespace net
22 class GURL;
24 // Helper class to download a blacklist file from a given URL and store it in a
25 // local file. If the local file already exists, reports success without
26 // downloading anything.
27 class SupervisedUserBlacklistDownloader : public net::URLFetcherDelegate {
28 public:
29 typedef base::Callback<void(bool /* success */)> DownloadFinishedCallback;
31 // Directly starts the download (if necessary) and runs |callback| when done.
32 // If the instance is destroyed before it is finished, |callback| is not run.
33 SupervisedUserBlacklistDownloader(
34 const GURL& url,
35 const base::FilePath& path,
36 net::URLRequestContextGetter* request_context,
37 const DownloadFinishedCallback& callback);
38 ~SupervisedUserBlacklistDownloader() override;
40 private:
41 // net::URLFetcherDelegate implementation.
42 void OnURLFetchComplete(const net::URLFetcher* source) override;
44 void OnFileExistsCheckDone(bool exists);
46 DownloadFinishedCallback callback_;
48 scoped_ptr<net::URLFetcher> fetcher_;
50 base::WeakPtrFactory<SupervisedUserBlacklistDownloader> weak_ptr_factory_;
52 DISALLOW_COPY_AND_ASSIGN(SupervisedUserBlacklistDownloader);
55 #endif // CHROME_BROWSER_SUPERVISED_USER_EXPERIMENTAL_SUPERVISED_USER_BLACKLIST_DOWNLOADER_H_