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::OnCustomizedWallpaperDownloaded() is called on | |
24 // success. | |
25 class CustomizationWallpaperDownloader : public net::URLFetcherDelegate { | |
Daniel Erat
2014/04/16 15:35:41
i haven't seen a reply to this yet; maybe you miss
Alexander Alekseev
2014/04/16 23:19:59
I'll add tests in another CL. This one is already
| |
26 public: | |
27 // - |url_context_getter| - Context to initialize net::URLFetcher. | |
28 // - |wallpaper_url| - wallpaper URL to download. | |
29 // - |wallpaper_dir| - directory, where wallpaper will be downloaded | |
30 // (it will be created). | |
31 // - |wallpaper_downloaded_file| - full path to local file to store downloaded | |
32 // wallpaper file. File is downloaded to temporary location | |
33 // |wallpaper_downloaded_file| + ".tmp", so directory must be writable. | |
34 // After download is completed, temporary file will be renamed to | |
35 // |wallpaper_downloaded_file|. | |
36 CustomizationWallpaperDownloader( | |
37 net::URLRequestContextGetter* url_context_getter, | |
38 const GURL& wallpaper_url, | |
39 const base::FilePath& wallpaper_dir, | |
40 const base::FilePath& wallpaper_downloaded_file, | |
41 base::Callback<void(bool success, const GURL&)> | |
42 on_wallpaper_fetch_completed); | |
43 | |
44 virtual ~CustomizationWallpaperDownloader(); | |
45 | |
46 // Start download. | |
47 void Start(); | |
48 | |
49 // net::URLFetcherDelegate | |
50 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; | |
51 | |
52 private: | |
53 // Start new request. | |
54 void StartRequest(); | |
55 | |
56 // Schedules retry. | |
57 void Retry(); | |
58 | |
59 // Called on UI thread. | |
60 void OnWallpaperDirectoryCreated(scoped_ptr<bool> success); | |
61 | |
62 // Called on UI thread. | |
63 void OnTemporaryFileRenamed(scoped_ptr<bool> success); | |
64 | |
65 // This is used to initialize net::URLFetcher object. | |
66 scoped_refptr<net::URLRequestContextGetter> url_context_getter_; | |
67 | |
68 // This fetcher is used to download wallpaper file. | |
69 scoped_ptr<net::URLFetcher> url_fetcher_; | |
70 | |
71 // The wallpaper URL to fetch. | |
72 const GURL wallpaper_url_; | |
73 | |
74 // Wallpaper directory (to be created). | |
75 const base::FilePath wallpaper_dir_; | |
76 | |
77 // Full path to local file to save downloaded wallpaper. | |
78 const base::FilePath wallpaper_downloaded_file_; | |
79 | |
80 // Full path to temporary file to fetch downloaded wallpper. | |
81 const base::FilePath wallpaper_temporary_file_; | |
82 | |
83 // Pending retry. | |
84 base::OneShotTimer<CustomizationWallpaperDownloader> request_scheduled_; | |
85 | |
86 // Number of download retries (first attempt is not counted as retry). | |
87 size_t retries_; | |
88 | |
89 // Callback supplied by caller. | |
90 base::Callback<void(bool success, const GURL&)> on_wallpaper_fetch_completed_; | |
91 | |
92 base::WeakPtrFactory<CustomizationWallpaperDownloader> weak_factory_; | |
93 | |
94 DISALLOW_COPY_AND_ASSIGN(CustomizationWallpaperDownloader); | |
95 }; | |
96 | |
97 } // namespace chromeos | |
98 | |
99 #endif // CHROME_BROWSER_CHROMEOS_CUSTOMIZATION_WALLPAPER_DOWNLOADER_H_ | |
OLD | NEW |