OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2010 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 |
| 6 #ifndef CHROME_BROWSER_CHROMEOS_DOM_UI_IMAGEBURNER_UI_H_ |
| 7 #define CHROME_BROWSER_CHROMEOS_DOM_UI_IMAGEBURNER_UI_H_ |
| 8 |
| 9 #include <string> |
| 10 #include <vector> |
| 11 |
| 12 #include "app/download_file_interface.h" |
| 13 #include "base/file_path.h" |
| 14 #include "base/file_util.h" |
| 15 #include "base/scoped_ptr.h" |
| 16 #include "base/values.h" |
| 17 #include "chrome/browser/chromeos/cros/burn_library.h" |
| 18 #include "chrome/browser/chromeos/cros/cros_library.h" |
| 19 #include "chrome/browser/chromeos/cros/mount_library.h" |
| 20 #include "chrome/browser/dom_ui/chrome_url_data_manager.h" |
| 21 #include "chrome/browser/dom_ui/dom_ui.h" |
| 22 #include "chrome/browser/download/download_item.h" |
| 23 #include "chrome/browser/download/download_manager.h" |
| 24 #include "chrome/browser/download/download_util.h" |
| 25 #include "chrome/browser/tab_contents/tab_contents.h" |
| 26 #include "googleurl/src/gurl.h" |
| 27 #include "net/base/file_stream.h" |
| 28 |
| 29 static const std::string kPropertyPath = "path"; |
| 30 static const std::string kPropertyTitle = "title"; |
| 31 static const std::string kPropertyDirectory = "isDirectory"; |
| 32 static const std::string kImageBaseURL = |
| 33 "http://chrome-master.mtv.corp.google.com/chromeos/dev-channel/"; |
| 34 static const std::string kImageFetcherName = "LATEST-x86-generic"; |
| 35 static const std::string kImageFileName = "chromeos_image.bin.gz"; |
| 36 static const std::string kTempImageFolderName = "chromeos_image"; |
| 37 |
| 38 class ImageBurnResourceManager; |
| 39 |
| 40 class ImageBurnUIHTMLSource : public ChromeURLDataManager::DataSource { |
| 41 public: |
| 42 ImageBurnUIHTMLSource(); |
| 43 |
| 44 // Called when the network layer has requested a resource underneath |
| 45 // the path we registered. |
| 46 virtual void StartDataRequest(const std::string& path, |
| 47 bool is_off_the_record, |
| 48 int request_id); |
| 49 virtual std::string GetMimeType(const std::string&) const { |
| 50 return "text/html"; |
| 51 } |
| 52 |
| 53 private: |
| 54 ~ImageBurnUIHTMLSource() {} |
| 55 |
| 56 DISALLOW_COPY_AND_ASSIGN(ImageBurnUIHTMLSource); |
| 57 }; |
| 58 |
| 59 class ImageBurnHandler : public DOMMessageHandler, |
| 60 public chromeos::MountLibrary::Observer, |
| 61 public chromeos::BurnLibrary::Observer, |
| 62 public DownloadManager::Observer, |
| 63 public DownloadItem::Observer, |
| 64 public base::SupportsWeakPtr<ImageBurnHandler> { |
| 65 public: |
| 66 explicit ImageBurnHandler(TabContents* contents); |
| 67 virtual ~ImageBurnHandler(); |
| 68 |
| 69 // DOMMessageHandler implementation. |
| 70 virtual DOMMessageHandler* Attach(DOMUI* dom_ui); |
| 71 virtual void RegisterMessages(); |
| 72 |
| 73 // chromeos::MountLibrary::Observer interface |
| 74 virtual void MountChanged(chromeos::MountLibrary* obj, |
| 75 chromeos::MountEventType evt, |
| 76 const std::string& path); |
| 77 |
| 78 // chromeos::BurnLibrary::Observer interface |
| 79 virtual void ProgressUpdated(chromeos::BurnLibrary* object, |
| 80 chromeos::BurnEventType evt, |
| 81 const ImageBurnStatus& status); |
| 82 |
| 83 // DownloadItem::Observer interface |
| 84 virtual void OnDownloadUpdated(DownloadItem* download); |
| 85 virtual void OnDownloadFileCompleted(DownloadItem* download); |
| 86 virtual void OnDownloadOpened(DownloadItem* download); |
| 87 |
| 88 // DownloadManager::Observer interface |
| 89 virtual void ModelChanged(); |
| 90 |
| 91 void CreateImageUrlCallback(GURL* image_url); |
| 92 |
| 93 |
| 94 private: |
| 95 // Callback for the "getRoots" message. |
| 96 void HandleGetRoots(const ListValue* args); |
| 97 |
| 98 // Callback for the "downloadImage" message. |
| 99 void HandleDownloadImage(const ListValue* args); |
| 100 |
| 101 // Callback for the "burnImage" message. |
| 102 void HandleBurnImage(const ListValue* args); |
| 103 |
| 104 // Callback for the "cancelBurnImage" message. |
| 105 void HandleCancelBurnImage(const ListValue* args); |
| 106 |
| 107 void DownloadCompleted(bool success); |
| 108 |
| 109 void BurnImage(); |
| 110 void FinalizeBurn(bool successful); |
| 111 |
| 112 void UpdateBurnProgress(int64 total_burnt, int64 image_size, |
| 113 const std::string& path, chromeos::BurnEventType evt); |
| 114 std::wstring GetBurnProgressText(int64 total_burnt, int64 image_size); |
| 115 |
| 116 // helper functions |
| 117 void CreateImageUrl(); |
| 118 void ExtractTargetedDeviceSystemPath(const ListValue* list_value); |
| 119 void CreateLocalImagePath(); |
| 120 |
| 121 private: |
| 122 // file path |
| 123 FilePath local_image_file_path_; |
| 124 FilePath image_target_; |
| 125 GURL* image_download_url_; |
| 126 TabContents* tab_contents_; |
| 127 DownloadManager* download_manager_; |
| 128 bool download_item_observer_added_; |
| 129 DownloadItem* active_download_item_; |
| 130 ImageBurnResourceManager* burn_resource_manager_; |
| 131 |
| 132 friend class ImageBurnTaskProxy; |
| 133 |
| 134 DISALLOW_COPY_AND_ASSIGN(ImageBurnHandler); |
| 135 }; |
| 136 |
| 137 class ImageBurnTaskProxy |
| 138 : public base::RefCountedThreadSafe<ImageBurnTaskProxy> { |
| 139 public: |
| 140 explicit ImageBurnTaskProxy(const base::WeakPtr<ImageBurnHandler>& handler); |
| 141 |
| 142 bool ReportDownloadInitialized(); |
| 143 bool CheckDownloadFinished(); |
| 144 void BurnImage(); |
| 145 void FinalizeBurn(bool success); |
| 146 |
| 147 void CreateImageUrl(TabContents* tab_contents, ImageBurnHandler* downloader); |
| 148 |
| 149 private: |
| 150 base::WeakPtr<ImageBurnHandler> handler_; |
| 151 ImageBurnResourceManager* resource_manager_; |
| 152 |
| 153 friend class base::RefCountedThreadSafe<ImageBurnTaskProxy>; |
| 154 |
| 155 DISALLOW_COPY_AND_ASSIGN(ImageBurnTaskProxy); |
| 156 }; |
| 157 |
| 158 class ImageBurnResourceManager : public DownloadManager::Observer, |
| 159 public DownloadItem::Observer { |
| 160 public: |
| 161 ImageBurnResourceManager(); |
| 162 ~ImageBurnResourceManager(); |
| 163 |
| 164 // DownloadItem::Observer interface |
| 165 virtual void OnDownloadUpdated(DownloadItem* download); |
| 166 virtual void OnDownloadFileCompleted(DownloadItem* download); |
| 167 virtual void OnDownloadOpened(DownloadItem* download); |
| 168 |
| 169 // DownloadManager::Observer interface |
| 170 virtual void ModelChanged(); |
| 171 |
| 172 FilePath GetLocalImageDirPath(); |
| 173 |
| 174 bool CheckImageDownloadStarted(); |
| 175 |
| 176 void ReportImageDownloadStarted(); |
| 177 |
| 178 bool CheckDownloadFinished(); |
| 179 |
| 180 bool CheckBurnInProgress(); |
| 181 |
| 182 void SetBurnInProgress(bool value); |
| 183 |
| 184 void ReportDownloadFinished(bool success); |
| 185 |
| 186 void CreateImageUrl(TabContents* tab_content, ImageBurnHandler* downloader); |
| 187 |
| 188 void ImageUrlFetched(bool success); |
| 189 |
| 190 net::FileStream* CreateFileStream(FilePath* file_path); |
| 191 |
| 192 private: |
| 193 FilePath local_image_dir_file_path_; |
| 194 FilePath image_fecher_local_path_; |
| 195 bool image_download_started_; |
| 196 bool image_download_finished_; |
| 197 bool burn_in_progress_; |
| 198 DownloadManager* download_manager_; |
| 199 bool download_item_observer_added_; |
| 200 DownloadItem* active_download_item_; |
| 201 scoped_ptr<GURL> image_url_; |
| 202 GURL image_fetcher_url_; |
| 203 bool image_url_fetching_requested_; |
| 204 bool image_url_fetched_; |
| 205 std::vector<ImageBurnHandler*> downloaders_; |
| 206 |
| 207 |
| 208 DISALLOW_COPY_AND_ASSIGN(ImageBurnResourceManager); |
| 209 }; |
| 210 |
| 211 class ImageBurnUI : public DOMUI { |
| 212 public: |
| 213 explicit ImageBurnUI(TabContents* contents); |
| 214 |
| 215 private: |
| 216 DISALLOW_COPY_AND_ASSIGN(ImageBurnUI); |
| 217 }; |
| 218 #endif // CHROME_BROWSER_CHROMEOS_DOM_UI_IMAGEBURNER_UI_H_ |
| 219 |
OLD | NEW |