Chromium Code Reviews| Index: chrome/browser/chromeos/customization_wallpaper_downloader.h |
| diff --git a/chrome/browser/chromeos/customization_wallpaper_downloader.h b/chrome/browser/chromeos/customization_wallpaper_downloader.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..bd38aa0a4d60c5887e01dcd9b2492296e3d0ca59 |
| --- /dev/null |
| +++ b/chrome/browser/chromeos/customization_wallpaper_downloader.h |
| @@ -0,0 +1,93 @@ |
| +// Copyright 2014 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef CHROME_BROWSER_CHROMEOS_CUSTOMIZATION_WALLPAPER_DOWNLOADER_H_ |
| +#define CHROME_BROWSER_CHROMEOS_CUSTOMIZATION_WALLPAPER_DOWNLOADER_H_ |
| + |
| +#include <string> |
| + |
| +#include "base/bind.h" |
| +#include "base/files/file_path.h" |
| +#include "base/macros.h" |
| +#include "base/memory/weak_ptr.h" |
| +#include "base/time/time.h" |
| +#include "base/timer/timer.h" |
| +#include "chrome/browser/chromeos/customization_document.h" |
| +#include "net/url_request/url_fetcher.h" |
| +#include "url/gurl.h" |
| + |
| +namespace chromeos { |
| + |
| +// Download customized wallpaper. |
| +// ServicesCustomizationDocument::OnCustomizedWallpaperDownloaded() in called on |
|
Daniel Erat
2014/04/14 15:26:15
nit: s/in/is/
Alexander Alekseev
2014/04/15 01:57:16
Done.
|
| +// success. |
| +class CustomizationWallpaperDownloader : public net::URLFetcherDelegate { |
| + public: |
| + CustomizationWallpaperDownloader( |
| + net::URLRequestContextGetter* url_context_getter, |
| + const GURL& wallpaper_url, |
| + const base::FilePath& wallpaper_dir, |
| + const base::FilePath& wallpaper_downloaded_file, |
| + base::Callback<void(const GURL&)> on_url_fetched); |
| + |
| + virtual ~CustomizationWallpaperDownloader(); |
| + |
| + // Start download. |
| + void Start(); |
| + |
| + // net::URLFetcherDelegate |
| + virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; |
| + |
| + private: |
| + // Start new request. |
| + void StartRequest(); |
| + |
| + // Schedules retry. |
| + void Retry(); |
| + |
| + // Create wallpaper cache directory and analyze result. |
| + // Called on BlockingPool. |
| + static void CreateWallpaperDirectory(const base::FilePath& wallpaper_dir, |
| + bool* success); |
| + // Called on UI thread. |
| + void OnWallpaperDirectoryCreated(scoped_ptr<bool> success); |
| + |
| + // Rename temporary file to wallpaper file and analyze result. |
| + // Called on BlockingPool. |
| + static void RenameTemporaryFile(const base::FilePath& from, |
| + const base::FilePath& to, |
| + bool* success); |
| + |
| + // Called on UI thread. |
| + void OnTemporaryFileRenamed(scoped_ptr<bool> success); |
| + |
| + scoped_refptr<net::URLRequestContextGetter> url_context_getter_; |
|
Daniel Erat
2014/04/14 15:26:15
add comments to all members describing what they'r
Alexander Alekseev
2014/04/15 01:57:16
Done.
|
| + |
| + scoped_ptr<net::URLFetcher> url_fetcher_; |
| + |
| + const GURL wallpaper_url_; |
| + |
| + const base::FilePath wallpaper_dir_; |
| + |
| + const base::FilePath wallpaper_downloaded_file_; |
| + |
| + const base::FilePath wallpaper_temporary_file_; |
| + |
| + // Pending retry. |
| + base::OneShotTimer<CustomizationWallpaperDownloader> request_scheduled_; |
| + |
| + // Number of retry attempts. |
| + unsigned retries_; |
|
Daniel Erat
2014/04/14 15:26:15
just make this be an int
Alexander Alekseev
2014/04/15 01:57:16
Done.
|
| + |
| + // Callback supplied by caller. |
| + base::Callback<void(const GURL&)> on_url_fetched_; |
| + |
| + base::WeakPtrFactory<CustomizationWallpaperDownloader> weak_factory_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(CustomizationWallpaperDownloader); |
| +}; |
| + |
| +} // namespace chromeos |
| + |
| +#endif // CHROME_BROWSER_CHROMEOS_CUSTOMIZATION_WALLPAPER_DOWNLOADER_H_ |