Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(637)

Side by Side Diff: chrome/browser/chromeos/customization_wallpaper_downloader.h

Issue 236013002: Apply default wallpaper from customization manifest. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Moved call to EnsureCustomizationAppliedClosure() to a better place. Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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"
Daniel Erat 2014/04/17 16:24:22 remove this include
Alexander Alekseev 2014/04/17 20:02:56 Done.
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
Daniel Erat 2014/04/17 16:24:22 update this comment
Alexander Alekseev 2014/04/17 20:02:56 Done.
24 // success.
25 class CustomizationWallpaperDownloader : public net::URLFetcherDelegate {
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_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698