OLD | NEW |
(Empty) | |
| 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. |
| 4 |
| 5 #ifndef CHROME_BROWSER_CHROMEOS_CUSTOMIZATION_WALLPAPER_DOWNLOADER_H_ |
| 6 #define CHROME_BROWSER_CHROMEOS_CUSTOMIZATION_WALLPAPER_DOWNLOADER_H_ |
| 7 |
| 8 #include <string> |
| 9 |
| 10 #include "base/bind.h" |
| 11 #include "base/files/file_path.h" |
| 12 #include "base/macros.h" |
| 13 #include "base/memory/weak_ptr.h" |
| 14 #include "base/time/time.h" |
| 15 #include "chrome/browser/chromeos/customization_document.h" |
| 16 #include "net/url_request/url_fetcher.h" |
| 17 #include "url/gurl.h" |
| 18 |
| 19 namespace chromeos { |
| 20 |
| 21 // Download customized wallpaper. |
| 22 // ServicesCustomizationDocument::SetDefaultWallpaperPath() in called on |
| 23 // success. |
| 24 class CustomizationWallpaperDownloader : public net::URLFetcherDelegate { |
| 25 public: |
| 26 CustomizationWallpaperDownloader( |
| 27 net::URLRequestContextGetter* url_context_getter, |
| 28 const GURL& wallpaper_url, |
| 29 const base::FilePath& wallpaper_dir, |
| 30 const base::FilePath& wallpaper_downloaded_file); |
| 31 |
| 32 virtual ~CustomizationWallpaperDownloader(); |
| 33 |
| 34 // Start download. |
| 35 void Start(); |
| 36 |
| 37 // net::URLFetcherDelegate |
| 38 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; |
| 39 |
| 40 private: |
| 41 // Start new request. |
| 42 void StartRequest(); |
| 43 |
| 44 // Schedules retry. |
| 45 void Retry(); |
| 46 |
| 47 // Create wallpaper cache directory and analyze result. |
| 48 // Called on BlockingPool. |
| 49 static void CreateWallpaperDirectory(const base::FilePath& wallpaper_dir, |
| 50 bool* success); |
| 51 // Called on UI thread. |
| 52 void OnWallpaperDirectoryCreated(scoped_ptr<bool> success); |
| 53 |
| 54 // Rename temporary file to wallpaper file and analyze result. |
| 55 // Called on BlockingPool. |
| 56 static void RenameTemporaryFile(const base::FilePath& from, |
| 57 const base::FilePath& to, |
| 58 bool* success); |
| 59 |
| 60 // Called on UI thread. |
| 61 void OnTemporaryFileRenamed(scoped_ptr<bool> success); |
| 62 |
| 63 scoped_refptr<net::URLRequestContextGetter> url_context_getter_; |
| 64 |
| 65 scoped_ptr<net::URLFetcher> url_fetcher_; |
| 66 |
| 67 const GURL wallpaper_url_; |
| 68 |
| 69 const base::FilePath wallpaper_dir_; |
| 70 |
| 71 const base::FilePath wallpaper_downloaded_file_; |
| 72 |
| 73 const base::FilePath wallpaper_temporary_file_; |
| 74 |
| 75 // Pending retry. |
| 76 base::OneShotTimer<CustomizationWallpaperDownloader> request_scheduled_; |
| 77 |
| 78 // Number of retry attempts. |
| 79 unsigned retries_; |
| 80 |
| 81 base::WeakPtrFactory<CustomizationWallpaperDownloader> weak_factory_; |
| 82 |
| 83 DISALLOW_COPY_AND_ASSIGN(CustomizationWallpaperDownloader); |
| 84 }; |
| 85 |
| 86 } // namespace chromeos |
| 87 |
| 88 #endif // CHROME_BROWSER_CHROMEOS_CUSTOMIZATION_WALLPAPER_DOWNLOADER_H_ |
OLD | NEW |