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

Side by Side Diff: chrome/browser/chromeos/imageburner/burn_manager.h

Issue 9568001: Use URLFetcher to download ChromeOS recovery image config file (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: _ Created 8 years, 9 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CHROME_BROWSER_CHROMEOS_IMAGEBURNER_BURN_MANAGER_H_ 5 #ifndef CHROME_BROWSER_CHROMEOS_IMAGEBURNER_BURN_MANAGER_H_
6 #define CHROME_BROWSER_CHROMEOS_IMAGEBURNER_BURN_MANAGER_H_ 6 #define CHROME_BROWSER_CHROMEOS_IMAGEBURNER_BURN_MANAGER_H_
7 7
8 #include <list> 8 #include <list>
9 #include <map> 9 #include <map>
10 #include <set> 10 #include <set>
11 #include <string> 11 #include <string>
12 #include <vector> 12 #include <vector>
13 13
14 #include "base/file_path.h" 14 #include "base/file_path.h"
15 #include "base/memory/scoped_ptr.h"
15 #include "base/observer_list.h" 16 #include "base/observer_list.h"
16 #include "content/public/browser/download_item.h" 17 #include "content/public/common/url_fetcher_delegate.h"
17 #include "content/public/browser/download_manager.h"
18 #include "googleurl/src/gurl.h" 18 #include "googleurl/src/gurl.h"
19 #include "net/base/file_stream.h" 19
20 namespace content {
21 class WebContents;
22 }
23
24 namespace net {
25 class FileStream;
26 }
20 27
21 namespace chromeos { 28 namespace chromeos {
22 namespace imageburner { 29 namespace imageburner {
23 30
24 // Config file properties. 31 // Config file properties.
25 extern const char kName[]; 32 extern const char kName[];
26 extern const char kHwid[]; 33 extern const char kHwid[];
27 extern const char kFileName[]; 34 extern const char kFileName[];
28 extern const char kUrl[]; 35 extern const char kUrl[];
29 36
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 bool download_started_; 197 bool download_started_;
191 bool download_finished_; 198 bool download_finished_;
192 199
193 State state_; 200 State state_;
194 201
195 ObserverList<Observer> observers_; 202 ObserverList<Observer> observers_;
196 203
197 DISALLOW_COPY_AND_ASSIGN(StateMachine); 204 DISALLOW_COPY_AND_ASSIGN(StateMachine);
198 }; 205 };
199 206
200 class BurnManager 207 class BurnManager : content::URLFetcherDelegate {
201 : public content::DownloadManager::Observer,
202 public content::DownloadItem::Observer,
203 public Downloader::Listener {
204 public: 208 public:
205 209
206 class Delegate : public base::SupportsWeakPtr<Delegate> { 210 class Delegate : public base::SupportsWeakPtr<Delegate> {
207 public: 211 public:
208 virtual void OnImageDirCreated(bool success) = 0; 212 virtual void OnImageDirCreated(bool success) = 0;
209 virtual void OnConfigFileFetched(const ConfigFile& config_file, 213 virtual void OnConfigFileFetched(const ConfigFile& config_file,
210 bool success) = 0; 214 bool success) = 0;
211 }; 215 };
212 216
213 // Creates the global BurnManager instance. 217 // Creates the global BurnManager instance.
214 static void Initialize(); 218 static void Initialize();
215 219
216 // Destroys the global BurnManager instance if it exists. 220 // Destroys the global BurnManager instance if it exists.
217 static void Shutdown(); 221 static void Shutdown();
218 222
219 // Returns the global BurnManager instance. 223 // Returns the global BurnManager instance.
220 // Initialize() should already have been called. 224 // Initialize() should already have been called.
221 static BurnManager* GetInstance(); 225 static BurnManager* GetInstance();
222 226
223 // content::DownloadItem::Observer interface.
224 virtual void OnDownloadUpdated(content::DownloadItem* download) OVERRIDE;
225 virtual void OnDownloadOpened(content::DownloadItem* download) OVERRIDE {}
226
227 // content::DownloadManager::Observer interface.
228 virtual void ModelChanged(content::DownloadManager* manager) OVERRIDE;
229
230 // Downloader::Listener interface.
231 virtual void OnBurnDownloadStarted(bool success) OVERRIDE;
232
233 // Creates URL image should be fetched from. 227 // Creates URL image should be fetched from.
234 // Must be called from UI thread. 228 // Must be called from UI thread.
235 void FetchConfigFile(content::WebContents* web_content, 229 void FetchConfigFile(Delegate* delegate);
236 Delegate* delegate); 230
231 // URLFetcherDelegate override.
232 virtual void OnURLFetchComplete(const content::URLFetcher* source) OVERRIDE;
237 233
238 // Creates directory image will be downloaded to. 234 // Creates directory image will be downloaded to.
239 // Must be called from FILE thread. 235 // Must be called from FILE thread.
240 void CreateImageDir(Delegate* delegate); 236 void CreateImageDir(Delegate* delegate);
241 237
242 // Returns directory image should be dopwnloaded to. 238 // Returns directory image should be dopwnloaded to.
243 // The directory has to be previously created. 239 // The directory has to be previously created.
244 const FilePath& GetImageDir(); 240 const FilePath& GetImageDir();
245 241
246 const FilePath& target_device_path() { return target_device_path_; } 242 const FilePath& target_device_path() { return target_device_path_; }
(...skipping 17 matching lines...) Expand all
264 if (!downloader_.get()) 260 if (!downloader_.get())
265 downloader_.reset(new Downloader()); 261 downloader_.reset(new Downloader());
266 return downloader_.get(); 262 return downloader_.get();
267 } 263 }
268 264
269 private: 265 private:
270 BurnManager(); 266 BurnManager();
271 virtual ~BurnManager(); 267 virtual ~BurnManager();
272 268
273 void OnImageDirCreated(Delegate* delegate, bool success); 269 void OnImageDirCreated(Delegate* delegate, bool success);
274 void OnConfigFileDownloaded();
275 void ConfigFileFetched(bool fetched, const std::string& content); 270 void ConfigFileFetched(bool fetched, const std::string& content);
276 271
272 bool config_file_fetched() const { return !config_file_.empty(); }
273
277 base::WeakPtrFactory<BurnManager> weak_ptr_factory_; 274 base::WeakPtrFactory<BurnManager> weak_ptr_factory_;
278 275
279 FilePath image_dir_; 276 FilePath image_dir_;
280 FilePath target_device_path_; 277 FilePath target_device_path_;
281 FilePath target_file_path_; 278 FilePath target_file_path_;
282 FilePath config_file_path_;
283
284 content::DownloadManager* download_manager_;
285 bool download_item_observer_added_;
286 content::DownloadItem* active_download_item_;
287 279
288 ConfigFile config_file_; 280 ConfigFile config_file_;
289 GURL config_file_url_; 281 GURL config_file_url_;
290 bool config_file_requested_;
291 bool config_file_fetched_;
292 std::vector<base::WeakPtr<Delegate> > downloaders_; 282 std::vector<base::WeakPtr<Delegate> > downloaders_;
293 283
294 scoped_ptr<StateMachine> state_machine_; 284 scoped_ptr<StateMachine> state_machine_;
295 285
296 scoped_ptr<Downloader> downloader_; 286 scoped_ptr<Downloader> downloader_;
287 scoped_ptr<content::URLFetcher> config_fetcher_;
297 288
298 DISALLOW_COPY_AND_ASSIGN(BurnManager); 289 DISALLOW_COPY_AND_ASSIGN(BurnManager);
299 }; 290 };
300 291
301 } // namespace imageburner 292 } // namespace imageburner
302 293
303 } // namespace chromeos 294 } // namespace chromeos
304 295
305 #endif // CHROME_BROWSER_CHROMEOS_IMAGEBURNER_BURN_MANAGER_H_ 296 #endif // CHROME_BROWSER_CHROMEOS_IMAGEBURNER_BURN_MANAGER_H_
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/imageburner/burn_controller.cc ('k') | chrome/browser/chromeos/imageburner/burn_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698