Chromium Code Reviews| 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 "base/timer/timer.h" | |
| 16 #include "chrome/browser/chromeos/customization_document.h" | |
| 17 #include "net/url_request/url_fetcher.h" | |
| 18 #include "url/gurl.h" | |
| 19 | |
| 20 namespace chromeos { | |
| 21 | |
| 22 // Download customized wallpaper. | |
| 23 // ServicesCustomizationDocument::SetDefaultWallpaperPath() in called on | |
| 24 // success. | |
| 25 class CustomizationWallpaperDownloader : public net::URLFetcherDelegate { | |
|
Dmitry Polukhin
2014/03/27 04:36:32
It is very sad that we have no code re-use with ex
Alexander Alekseev
2014/03/31 14:15:40
Actually we reuse all possible code from Wallpaper
| |
| 26 public: | |
| 27 CustomizationWallpaperDownloader( | |
| 28 net::URLRequestContextGetter* url_context_getter, | |
| 29 const GURL& wallpaper_url, | |
| 30 const base::FilePath& wallpaper_dir, | |
| 31 const base::FilePath& wallpaper_downloaded_file); | |
| 32 | |
| 33 virtual ~CustomizationWallpaperDownloader(); | |
| 34 | |
| 35 // Start download. | |
| 36 void Start(); | |
| 37 | |
| 38 // net::URLFetcherDelegate | |
| 39 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; | |
| 40 | |
| 41 private: | |
| 42 // Start new request. | |
| 43 void StartRequest(); | |
| 44 | |
| 45 // Schedules retry. | |
| 46 void Retry(); | |
| 47 | |
| 48 // Create wallpaper cache directory and analyze result. | |
| 49 // Called on BlockingPool. | |
| 50 static void CreateWallpaperDirectory(const base::FilePath& wallpaper_dir, | |
| 51 bool* success); | |
| 52 // Called on UI thread. | |
| 53 void OnWallpaperDirectoryCreated(scoped_ptr<bool> success); | |
|
Dmitry Polukhin
2014/03/27 04:36:32
Why do you need scoped_ptr<bool> again it seems th
Alexander Alekseev
2014/03/31 14:15:40
It's the same: to never pass WeakPointer to other
| |
| 54 | |
| 55 // Rename temporary file to wallpaper file and analyze result. | |
| 56 // Called on BlockingPool. | |
| 57 static void RenameTemporaryFile(const base::FilePath& from, | |
| 58 const base::FilePath& to, | |
| 59 bool* success); | |
| 60 | |
| 61 // Called on UI thread. | |
| 62 void OnTemporaryFileRenamed(scoped_ptr<bool> success); | |
| 63 | |
| 64 scoped_refptr<net::URLRequestContextGetter> url_context_getter_; | |
| 65 | |
| 66 scoped_ptr<net::URLFetcher> url_fetcher_; | |
| 67 | |
| 68 const GURL wallpaper_url_; | |
| 69 | |
| 70 const base::FilePath wallpaper_dir_; | |
| 71 | |
| 72 const base::FilePath wallpaper_downloaded_file_; | |
| 73 | |
| 74 const base::FilePath wallpaper_temporary_file_; | |
| 75 | |
| 76 // Pending retry. | |
| 77 base::OneShotTimer<CustomizationWallpaperDownloader> request_scheduled_; | |
| 78 | |
| 79 // Number of retry attempts. | |
| 80 unsigned retries_; | |
| 81 | |
| 82 base::WeakPtrFactory<CustomizationWallpaperDownloader> weak_factory_; | |
| 83 | |
| 84 DISALLOW_COPY_AND_ASSIGN(CustomizationWallpaperDownloader); | |
| 85 }; | |
| 86 | |
| 87 } // namespace chromeos | |
| 88 | |
| 89 #endif // CHROME_BROWSER_CHROMEOS_CUSTOMIZATION_WALLPAPER_DOWNLOADER_H_ | |
| OLD | NEW |