| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 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 | 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 #include "chrome/browser/chromeos/dom_ui/imageburner_ui.h" | 5 #include "chrome/browser/chromeos/dom_ui/imageburner_ui.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/i18n/rtl.h" | 9 #include "base/i18n/rtl.h" |
| 10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 #include "chrome/browser/tab_contents/tab_contents.h" | 21 #include "chrome/browser/tab_contents/tab_contents.h" |
| 22 #include "chrome/common/chrome_paths.h" | 22 #include "chrome/common/chrome_paths.h" |
| 23 #include "chrome/common/jstemplate_builder.h" | 23 #include "chrome/common/jstemplate_builder.h" |
| 24 #include "chrome/common/url_constants.h" | 24 #include "chrome/common/url_constants.h" |
| 25 #include "grit/browser_resources.h" | 25 #include "grit/browser_resources.h" |
| 26 #include "grit/generated_resources.h" | 26 #include "grit/generated_resources.h" |
| 27 #include "grit/locale_settings.h" | 27 #include "grit/locale_settings.h" |
| 28 #include "ui/base/l10n/l10n_util.h" | 28 #include "ui/base/l10n/l10n_util.h" |
| 29 #include "ui/base/resource/resource_bundle.h" | 29 #include "ui/base/resource/resource_bundle.h" |
| 30 | 30 |
| 31 static const char kPropertyPath[] = "path"; |
| 32 static const char kPropertyTitle[] = "title"; |
| 33 static const char kPropertyDirectory[] = "isDirectory"; |
| 34 static const char kImageBaseURL[] = |
| 35 "http://chrome-master.mtv.corp.google.com/chromeos/dev-channel/"; |
| 36 static const char kImageFetcherName[] = "LATEST-x86-generic"; |
| 37 static const char kImageDownloadURL[] = |
| 38 "https://dl.google.com/dl/chromeos/recovery/latest_mario_beta_channel"; |
| 39 static const char kImageFileName[] = "chromeos_image.bin.zip"; |
| 40 static const char kTempImageFolderName[] = "chromeos_image"; |
| 41 |
| 31 //////////////////////////////////////////////////////////////////////////////// | 42 //////////////////////////////////////////////////////////////////////////////// |
| 32 // | 43 // |
| 33 // ImageBurnUIHTMLSource | 44 // ImageBurnUIHTMLSource |
| 34 // | 45 // |
| 35 //////////////////////////////////////////////////////////////////////////////// | 46 //////////////////////////////////////////////////////////////////////////////// |
| 36 | 47 |
| 37 ImageBurnUIHTMLSource::ImageBurnUIHTMLSource() | 48 class ImageBurnUIHTMLSource : public ChromeURLDataManager::DataSource { |
| 38 : DataSource(chrome::kChromeUIImageBurnerHost, MessageLoop::current()) { | 49 public: |
| 39 } | 50 ImageBurnUIHTMLSource() |
| 51 : DataSource(chrome::kChromeUIImageBurnerHost, MessageLoop::current()) { |
| 52 } |
| 40 | 53 |
| 41 void ImageBurnUIHTMLSource::StartDataRequest(const std::string& path, | 54 // Called when the network layer has requested a resource underneath |
| 42 bool is_off_the_record, | 55 // the path we registered. |
| 43 int request_id) { | 56 virtual void StartDataRequest(const std::string& path, |
| 44 DictionaryValue localized_strings; | 57 bool is_off_the_record, |
| 45 localized_strings.SetString("burnConfirmText1", | 58 int request_id) { |
| 46 l10n_util::GetStringUTF16(IDS_IMAGEBURN_CONFIM_BURN1)); | 59 DictionaryValue localized_strings; |
| 47 localized_strings.SetString("burnConfirmText2", | 60 localized_strings.SetString("burnConfirmText1", |
| 48 l10n_util::GetStringUTF16(IDS_IMAGEBURN_CONFIM_BURN2)); | 61 l10n_util::GetStringUTF16(IDS_IMAGEBURN_CONFIM_BURN1)); |
| 49 localized_strings.SetString("burnUnsuccessfulMessage", | 62 localized_strings.SetString("burnConfirmText2", |
| 50 l10n_util::GetStringUTF16(IDS_IMAGEBURN_BURN_UNSUCCESSFUL)); | 63 l10n_util::GetStringUTF16(IDS_IMAGEBURN_CONFIM_BURN2)); |
| 51 localized_strings.SetString("burnSuccessfulMessage", | 64 localized_strings.SetString("burnUnsuccessfulMessage", |
| 52 l10n_util::GetStringUTF16(IDS_IMAGEBURN_BURN_SUCCESSFUL)); | 65 l10n_util::GetStringUTF16(IDS_IMAGEBURN_BURN_UNSUCCESSFUL)); |
| 53 localized_strings.SetString("downloadAbortedMessage", | 66 localized_strings.SetString("burnSuccessfulMessage", |
| 54 l10n_util::GetStringUTF16(IDS_IMAGEBURN_DOWNLOAD_UNSUCCESSFUL)); | 67 l10n_util::GetStringUTF16(IDS_IMAGEBURN_BURN_SUCCESSFUL)); |
| 55 localized_strings.SetString("title", | 68 localized_strings.SetString("downloadAbortedMessage", |
| 56 l10n_util::GetStringUTF16(IDS_IMAGEBURN_TITLE)); | 69 l10n_util::GetStringUTF16(IDS_IMAGEBURN_DOWNLOAD_UNSUCCESSFUL)); |
| 57 localized_strings.SetString("listTitle", | 70 localized_strings.SetString("title", |
| 58 l10n_util::GetStringUTF16(IDS_IMAGEBURN_ROOT_LIST_TITLE)); | 71 l10n_util::GetStringUTF16(IDS_IMAGEBURN_TITLE)); |
| 59 localized_strings.SetString("downloadStatusStart", | 72 localized_strings.SetString("listTitle", |
| 60 l10n_util::GetStringUTF16(IDS_IMAGEBURN_DOWNLOAD_STARTING_STATUS)); | 73 l10n_util::GetStringUTF16(IDS_IMAGEBURN_ROOT_LIST_TITLE)); |
| 61 localized_strings.SetString("downloadStatusInProgress", | 74 localized_strings.SetString("downloadStatusStart", |
| 62 l10n_util::GetStringUTF16(IDS_IMAGEBURN_DOWNLOAD_IN_PROGRESS_STATUS)); | 75 l10n_util::GetStringUTF16(IDS_IMAGEBURN_DOWNLOAD_STARTING_STATUS)); |
| 63 localized_strings.SetString("downloadStatusComplete", | 76 localized_strings.SetString("downloadStatusInProgress", |
| 64 l10n_util::GetStringUTF16(IDS_IMAGEBURN_DOWNLOAD_COMPLETE_STATUS)); | 77 l10n_util::GetStringUTF16(IDS_IMAGEBURN_DOWNLOAD_IN_PROGRESS_STATUS)); |
| 65 localized_strings.SetString("downloadStatusCanceled", | 78 localized_strings.SetString("downloadStatusComplete", |
| 66 l10n_util::GetStringUTF16(IDS_IMAGEBURN_DOWNLOAD_CANCELED_STATUS)); | 79 l10n_util::GetStringUTF16(IDS_IMAGEBURN_DOWNLOAD_COMPLETE_STATUS)); |
| 67 localized_strings.SetString("burnStatusStart", | 80 localized_strings.SetString("downloadStatusCanceled", |
| 68 l10n_util::GetStringUTF16(IDS_IMAGEBURN_BURN_STARTING_STATUS)); | 81 l10n_util::GetStringUTF16(IDS_IMAGEBURN_DOWNLOAD_CANCELED_STATUS)); |
| 69 localized_strings.SetString("burnStatusInProgress", | 82 localized_strings.SetString("burnStatusStart", |
| 70 l10n_util::GetStringUTF16(IDS_IMAGEBURN_BURN_IN_PROGRESS_STATUS)); | 83 l10n_util::GetStringUTF16(IDS_IMAGEBURN_BURN_STARTING_STATUS)); |
| 71 localized_strings.SetString("burnStatusComplete", | 84 localized_strings.SetString("burnStatusInProgress", |
| 72 l10n_util::GetStringUTF16(IDS_IMAGEBURN_BURN_COMPLETE_STATUS)); | 85 l10n_util::GetStringUTF16(IDS_IMAGEBURN_BURN_IN_PROGRESS_STATUS)); |
| 73 localized_strings.SetString("burnStatusCanceled", | 86 localized_strings.SetString("burnStatusComplete", |
| 74 l10n_util::GetStringUTF16(IDS_IMAGEBURN_BURN_CANCELED_STATUS)); | 87 l10n_util::GetStringUTF16(IDS_IMAGEBURN_BURN_COMPLETE_STATUS)); |
| 88 localized_strings.SetString("burnStatusCanceled", |
| 89 l10n_util::GetStringUTF16(IDS_IMAGEBURN_BURN_CANCELED_STATUS)); |
| 75 | 90 |
| 76 SetFontAndTextDirection(&localized_strings); | 91 SetFontAndTextDirection(&localized_strings); |
| 77 | 92 |
| 78 static const base::StringPiece imageburn_html( | 93 static const base::StringPiece imageburn_html( |
| 79 ResourceBundle::GetSharedInstance().GetRawDataResource( | 94 ResourceBundle::GetSharedInstance().GetRawDataResource( |
| 80 IDR_IMAGEBURNER_HTML)); | 95 IDR_IMAGEBURNER_HTML)); |
| 81 const std::string full_html = jstemplate_builder::GetI18nTemplateHtml( | 96 const std::string full_html = jstemplate_builder::GetI18nTemplateHtml( |
| 82 imageburn_html, &localized_strings); | 97 imageburn_html, &localized_strings); |
| 83 | 98 |
| 84 scoped_refptr<RefCountedBytes> html_bytes(new RefCountedBytes); | 99 scoped_refptr<RefCountedBytes> html_bytes(new RefCountedBytes); |
| 85 html_bytes->data.resize(full_html.size()); | 100 html_bytes->data.resize(full_html.size()); |
| 86 std::copy(full_html.begin(), full_html.end(), html_bytes->data.begin()); | 101 std::copy(full_html.begin(), full_html.end(), html_bytes->data.begin()); |
| 87 | 102 |
| 88 SendResponse(request_id, html_bytes); | 103 SendResponse(request_id, html_bytes); |
| 89 } | 104 } |
| 105 |
| 106 virtual std::string GetMimeType(const std::string&) const { |
| 107 return "text/html"; |
| 108 } |
| 109 |
| 110 private: |
| 111 virtual ~ImageBurnUIHTMLSource() {} |
| 112 |
| 113 DISALLOW_COPY_AND_ASSIGN(ImageBurnUIHTMLSource); |
| 114 }; |
| 115 |
| 116 //////////////////////////////////////////////////////////////////////////////// |
| 117 // |
| 118 // ImageBurnTaskProxy |
| 119 // |
| 120 //////////////////////////////////////////////////////////////////////////////// |
| 121 |
| 122 class ImageBurnTaskProxy |
| 123 : public base::RefCountedThreadSafe<ImageBurnTaskProxy> { |
| 124 public: |
| 125 explicit ImageBurnTaskProxy(const base::WeakPtr<ImageBurnHandler>& handler) |
| 126 : handler_(handler) { |
| 127 resource_manager_ = ImageBurnResourceManager::GetInstance(); |
| 128 } |
| 129 |
| 130 bool ReportDownloadInitialized() { |
| 131 bool initialized = resource_manager_-> CheckImageDownloadStarted(); |
| 132 if (!initialized) |
| 133 resource_manager_-> ReportImageDownloadStarted(); |
| 134 return initialized; |
| 135 } |
| 136 |
| 137 bool CheckDownloadFinished() { |
| 138 return resource_manager_->CheckDownloadFinished(); |
| 139 } |
| 140 |
| 141 void BurnImage() { |
| 142 if (!resource_manager_->CheckBurnInProgress() && handler_) { |
| 143 resource_manager_->SetBurnInProgress(true); |
| 144 handler_->BurnImage(); |
| 145 } |
| 146 } |
| 147 |
| 148 void FinalizeBurn(bool success) { |
| 149 if (handler_) { |
| 150 handler_->FinalizeBurn(success); |
| 151 resource_manager_->SetBurnInProgress(false); |
| 152 } |
| 153 } |
| 154 |
| 155 void CreateImageUrl(TabContents* tab_contents, ImageBurnHandler* downloader) { |
| 156 resource_manager_->CreateImageUrl(tab_contents, downloader); |
| 157 } |
| 158 |
| 159 private: |
| 160 base::WeakPtr<ImageBurnHandler> handler_; |
| 161 ImageBurnResourceManager* resource_manager_; |
| 162 |
| 163 friend class base::RefCountedThreadSafe<ImageBurnTaskProxy>; |
| 164 |
| 165 DISALLOW_COPY_AND_ASSIGN(ImageBurnTaskProxy); |
| 166 }; |
| 90 | 167 |
| 91 //////////////////////////////////////////////////////////////////////////////// | 168 //////////////////////////////////////////////////////////////////////////////// |
| 92 // | 169 // |
| 93 // ImageBurnHandler | 170 // ImageBurnHandler |
| 94 // | 171 // |
| 95 //////////////////////////////////////////////////////////////////////////////// | 172 //////////////////////////////////////////////////////////////////////////////// |
| 96 | 173 |
| 97 ImageBurnHandler::ImageBurnHandler(TabContents* contents) | 174 ImageBurnHandler::ImageBurnHandler(TabContents* contents) |
| 98 :tab_contents_(contents), | 175 :tab_contents_(contents), |
| 99 download_manager_(NULL), | 176 download_manager_(NULL), |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 181 local_image_file_path_ = download->full_path(); | 258 local_image_file_path_ = download->full_path(); |
| 182 DownloadCompleted(true); | 259 DownloadCompleted(true); |
| 183 } | 260 } |
| 184 | 261 |
| 185 void ImageBurnHandler::OnDownloadOpened(DownloadItem* download) { | 262 void ImageBurnHandler::OnDownloadOpened(DownloadItem* download) { |
| 186 if (download->safety_state() == DownloadItem::DANGEROUS) | 263 if (download->safety_state() == DownloadItem::DANGEROUS) |
| 187 download->DangerousDownloadValidated(); | 264 download->DangerousDownloadValidated(); |
| 188 } | 265 } |
| 189 | 266 |
| 190 void ImageBurnHandler::ModelChanged() { | 267 void ImageBurnHandler::ModelChanged() { |
| 268 // Find our item and observe it. |
| 191 std::vector<DownloadItem*> downloads; | 269 std::vector<DownloadItem*> downloads; |
| 192 download_manager_->GetTemporaryDownloads( | 270 download_manager_->GetTemporaryDownloads( |
| 193 burn_resource_manager_->GetLocalImageDirPath(), &downloads); | 271 burn_resource_manager_->GetLocalImageDirPath(), &downloads); |
| 194 if (download_item_observer_added_) | 272 if (download_item_observer_added_) // Already added. |
| 195 return; | 273 return; |
| 196 std::vector<DownloadItem*>::const_iterator it = downloads.begin(); | 274 std::vector<DownloadItem*>::const_iterator it = downloads.begin(); |
| 197 for (; it != downloads.end(); ++it) { | 275 for (; it != downloads.end(); ++it) { |
| 198 if ((*it)->url() == *image_download_url_) { | 276 if ((*it)->original_url() == *image_download_url_) { |
| 277 // Found it. |
| 199 download_item_observer_added_ = true; | 278 download_item_observer_added_ = true; |
| 200 (*it)->AddObserver(this); | 279 (*it)->AddObserver(this); |
| 201 active_download_item_ = *it; | 280 active_download_item_ = *it; |
| 202 break; | 281 break; |
| 203 } | 282 } |
| 204 } | 283 } |
| 205 } | 284 } |
| 206 | 285 |
| 207 void ImageBurnHandler::HandleGetRoots(const ListValue* args) { | 286 void ImageBurnHandler::HandleGetRoots(const ListValue* args) { |
| 208 ListValue results_value; | 287 ListValue results_value; |
| 209 DictionaryValue info_value; | 288 DictionaryValue info_value; |
| 210 chromeos::MountLibrary* mount_lib = | 289 chromeos::MountLibrary* mount_lib = |
| 211 chromeos::CrosLibrary::Get()->GetMountLibrary(); | 290 chromeos::CrosLibrary::Get()->GetMountLibrary(); |
| 212 const chromeos::MountLibrary::DiskVector& disks = mount_lib->disks(); | 291 const chromeos::MountLibrary::DiskVector& disks = mount_lib->disks(); |
| 213 if (!burn_resource_manager_->CheckBurnInProgress()) { | 292 if (!burn_resource_manager_->CheckBurnInProgress()) { |
| 214 for (size_t i = 0; i < disks.size(); ++i) { | 293 for (size_t i = 0; i < disks.size(); ++i) { |
| 215 if (!disks[i].mount_path.empty()) { | 294 if (!disks[i].mount_path.empty()) { |
| 216 DictionaryValue* page_value = new DictionaryValue(); | |
| 217 FilePath disk_path = FilePath(disks[i].system_path).DirName(); | 295 FilePath disk_path = FilePath(disks[i].system_path).DirName(); |
| 218 std::string title = "/dev/" + disk_path.BaseName().value(); | 296 std::string title = "/dev/" + disk_path.BaseName().value(); |
| 219 page_value->SetString(kPropertyTitle, title); | 297 if (!mount_lib->IsBootPath(title.c_str())) { |
| 220 page_value->SetString(kPropertyPath, title); | 298 DictionaryValue* page_value = new DictionaryValue(); |
| 221 page_value->SetBoolean(kPropertyDirectory, true); | 299 page_value->SetString(std::string(kPropertyTitle), title); |
| 222 results_value.Append(page_value); | 300 page_value->SetString(std::string(kPropertyPath), title); |
| 301 page_value->SetBoolean(std::string(kPropertyDirectory), true); |
| 302 results_value.Append(page_value); |
| 303 } |
| 223 } | 304 } |
| 224 } | 305 } |
| 225 } | 306 } |
| 226 info_value.SetString("functionCall", "getRoots"); | 307 info_value.SetString("functionCall", "getRoots"); |
| 227 info_value.SetString(kPropertyPath, ""); | 308 info_value.SetString(std::string(kPropertyPath), ""); |
| 228 dom_ui_->CallJavascriptFunction(L"browseFileResult", | 309 dom_ui_->CallJavascriptFunction(L"browseFileResult", |
| 229 info_value, results_value); | 310 info_value, results_value); |
| 230 } | 311 } |
| 231 | 312 |
| 232 void ImageBurnHandler::HandleDownloadImage(const ListValue* args) { | 313 void ImageBurnHandler::HandleDownloadImage(const ListValue* args) { |
| 233 ExtractTargetedDeviceSystemPath(args); | 314 ExtractTargetedDeviceSystemPath(args); |
| 234 CreateLocalImagePath(); | 315 CreateLocalImagePath(); |
| 235 CreateImageUrl(); | 316 CreateImageUrl(); |
| 236 } | 317 } |
| 237 | 318 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 275 signal_value.SetString("state", "IN_PROGRESS"); | 356 signal_value.SetString("state", "IN_PROGRESS"); |
| 276 signal_value.SetString("path", image_target_.value()); | 357 signal_value.SetString("path", image_target_.value()); |
| 277 signal_value.SetInteger("received", 0); | 358 signal_value.SetInteger("received", 0); |
| 278 signal_value.SetString("progress_status_text", ""); | 359 signal_value.SetString("progress_status_text", ""); |
| 279 dom_ui_->CallJavascriptFunction(L"burnProgressUpdated", signal_value); | 360 dom_ui_->CallJavascriptFunction(L"burnProgressUpdated", signal_value); |
| 280 } | 361 } |
| 281 } | 362 } |
| 282 | 363 |
| 283 void ImageBurnHandler::FinalizeBurn(bool successful) { | 364 void ImageBurnHandler::FinalizeBurn(bool successful) { |
| 284 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 365 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 285 if (successful) | 366 dom_ui_->CallJavascriptFunction(successful ? |
| 286 dom_ui_->CallJavascriptFunction(L"burnSuccessful"); | 367 L"burnSuccessful" : L"burnUnsuccessful"); |
| 287 else | |
| 288 dom_ui_->CallJavascriptFunction(L"burnUnsuccessful"); | |
| 289 } | 368 } |
| 290 | 369 |
| 291 void ImageBurnHandler::UpdateBurnProgress(int64 total_burnt, | 370 void ImageBurnHandler::UpdateBurnProgress(int64 total_burnt, |
| 292 int64 image_size, | 371 int64 image_size, |
| 293 const std::string& path, | 372 const std::string& path, |
| 294 chromeos::BurnEventType event) { | 373 chromeos::BurnEventType event) { |
| 295 DictionaryValue progress_value; | 374 DictionaryValue progress_value; |
| 296 progress_value.SetString("progress_status_text", | 375 progress_value.SetString("progress_status_text", |
| 297 GetBurnProgressText(total_burnt, image_size)); | 376 GetBurnProgressText(total_burnt, image_size)); |
| 298 if (event == chromeos::BURN_UPDATED) | 377 if (event == chromeos::BURN_UPDATED) |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 385 image_target_ = FilePath(image_dest); | 464 image_target_ = FilePath(image_dest); |
| 386 } | 465 } |
| 387 | 466 |
| 388 void ImageBurnHandler::CreateLocalImagePath() { | 467 void ImageBurnHandler::CreateLocalImagePath() { |
| 389 local_image_file_path_ = | 468 local_image_file_path_ = |
| 390 burn_resource_manager_->GetLocalImageDirPath().Append(kImageFileName); | 469 burn_resource_manager_->GetLocalImageDirPath().Append(kImageFileName); |
| 391 } | 470 } |
| 392 | 471 |
| 393 //////////////////////////////////////////////////////////////////////////////// | 472 //////////////////////////////////////////////////////////////////////////////// |
| 394 // | 473 // |
| 395 // ImageBurnTaskProxy | |
| 396 // | |
| 397 //////////////////////////////////////////////////////////////////////////////// | |
| 398 ImageBurnTaskProxy::ImageBurnTaskProxy( | |
| 399 const base::WeakPtr<ImageBurnHandler>& handler) | |
| 400 : handler_(handler) { | |
| 401 resource_manager_ = ImageBurnResourceManager::GetInstance(); | |
| 402 } | |
| 403 | |
| 404 bool ImageBurnTaskProxy::ReportDownloadInitialized() { | |
| 405 bool initialized = resource_manager_-> CheckImageDownloadStarted(); | |
| 406 if (!initialized) | |
| 407 resource_manager_-> ReportImageDownloadStarted(); | |
| 408 return initialized; | |
| 409 } | |
| 410 | |
| 411 bool ImageBurnTaskProxy::CheckDownloadFinished() { | |
| 412 return resource_manager_->CheckDownloadFinished(); | |
| 413 } | |
| 414 | |
| 415 void ImageBurnTaskProxy:: BurnImage() { | |
| 416 if (!resource_manager_->CheckBurnInProgress() && handler_) { | |
| 417 resource_manager_->SetBurnInProgress(true); | |
| 418 handler_->BurnImage(); | |
| 419 } | |
| 420 } | |
| 421 | |
| 422 void ImageBurnTaskProxy::FinalizeBurn(bool success) { | |
| 423 if (handler_) { | |
| 424 handler_->FinalizeBurn(success); | |
| 425 resource_manager_->SetBurnInProgress(false); | |
| 426 } | |
| 427 } | |
| 428 | |
| 429 void ImageBurnTaskProxy::CreateImageUrl(TabContents* tab_contents, | |
| 430 ImageBurnHandler* downloader) { | |
| 431 resource_manager_->CreateImageUrl(tab_contents, downloader); | |
| 432 } | |
| 433 | |
| 434 | |
| 435 //////////////////////////////////////////////////////////////////////////////// | |
| 436 // | |
| 437 // ImageBurnResourceManager | 474 // ImageBurnResourceManager |
| 438 // | 475 // |
| 439 //////////////////////////////////////////////////////////////////////////////// | 476 //////////////////////////////////////////////////////////////////////////////// |
| 440 | 477 |
| 441 ImageBurnResourceManager::ImageBurnResourceManager() | 478 ImageBurnResourceManager::ImageBurnResourceManager() |
| 442 : image_download_started_(false), | 479 : image_download_started_(false), |
| 443 image_download_finished_(false), | 480 image_download_finished_(false), |
| 444 burn_in_progress_(false), | 481 burn_in_progress_(false), |
| 445 download_manager_(NULL), | 482 download_manager_(NULL), |
| 446 download_item_observer_added_(false), | 483 download_item_observer_added_(false), |
| 447 active_download_item_(NULL), | 484 active_download_item_(NULL), |
| 448 image_url_(NULL), | 485 image_url_(new GURL(kImageDownloadURL)), |
| 449 image_fetcher_url_(kImageBaseURL + kImageFetcherName), | 486 image_fetcher_url_(std::string(kImageBaseURL) + kImageFetcherName), |
| 450 image_url_fetching_requested_(false), | 487 image_url_fetching_requested_(false), |
| 451 image_url_fetched_(false) { | 488 image_url_fetched_(true) { |
| 452 local_image_dir_file_path_.clear(); | 489 local_image_dir_file_path_.clear(); |
| 453 image_fecher_local_path_ = GetLocalImageDirPath().Append(kImageFetcherName); | 490 image_fecher_local_path_ = GetLocalImageDirPath().Append(kImageFetcherName); |
| 454 } | 491 } |
| 455 | 492 |
| 456 ImageBurnResourceManager::~ImageBurnResourceManager() { | 493 ImageBurnResourceManager::~ImageBurnResourceManager() { |
| 457 if (!local_image_dir_file_path_.empty()) { | 494 if (!local_image_dir_file_path_.empty()) { |
| 458 file_util::Delete(local_image_dir_file_path_, true); | 495 file_util::Delete(local_image_dir_file_path_, true); |
| 459 } | 496 } |
| 460 if (active_download_item_) { | 497 if (active_download_item_) { |
| 461 active_download_item_->RemoveObserver(this); | 498 active_download_item_->RemoveObserver(this); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 473 if (download->state() == DownloadItem::CANCELLED) { | 510 if (download->state() == DownloadItem::CANCELLED) { |
| 474 image_url_.reset(); | 511 image_url_.reset(); |
| 475 ImageUrlFetched(false); | 512 ImageUrlFetched(false); |
| 476 } | 513 } |
| 477 } | 514 } |
| 478 | 515 |
| 479 void ImageBurnResourceManager::OnDownloadFileCompleted(DownloadItem* download) { | 516 void ImageBurnResourceManager::OnDownloadFileCompleted(DownloadItem* download) { |
| 480 DCHECK(download->state() == DownloadItem::COMPLETE); | 517 DCHECK(download->state() == DownloadItem::COMPLETE); |
| 481 std::string image_url; | 518 std::string image_url; |
| 482 if (file_util::ReadFileToString(image_fecher_local_path_, &image_url)) { | 519 if (file_util::ReadFileToString(image_fecher_local_path_, &image_url)) { |
| 483 image_url_.reset(new GURL(kImageBaseURL + image_url)); | 520 image_url_.reset(new GURL(std::string(kImageBaseURL) + image_url)); |
| 484 ImageUrlFetched(true); | 521 ImageUrlFetched(true); |
| 485 } else { | 522 } else { |
| 486 image_url_.reset(); | 523 image_url_.reset(); |
| 487 ImageUrlFetched(false); | 524 ImageUrlFetched(false); |
| 488 } | 525 } |
| 489 } | 526 } |
| 490 | 527 |
| 491 void ImageBurnResourceManager::OnDownloadOpened(DownloadItem* download) { } | 528 void ImageBurnResourceManager::OnDownloadOpened(DownloadItem* download) { } |
| 492 | 529 |
| 493 void ImageBurnResourceManager::ModelChanged() { | 530 void ImageBurnResourceManager::ModelChanged() { |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 612 ImageBurnHandler* handler = new ImageBurnHandler(contents); | 649 ImageBurnHandler* handler = new ImageBurnHandler(contents); |
| 613 AddMessageHandler((handler)->Attach(this)); | 650 AddMessageHandler((handler)->Attach(this)); |
| 614 ImageBurnUIHTMLSource* html_source = new ImageBurnUIHTMLSource(); | 651 ImageBurnUIHTMLSource* html_source = new ImageBurnUIHTMLSource(); |
| 615 BrowserThread::PostTask( | 652 BrowserThread::PostTask( |
| 616 BrowserThread::IO, FROM_HERE, | 653 BrowserThread::IO, FROM_HERE, |
| 617 NewRunnableMethod( | 654 NewRunnableMethod( |
| 618 ChromeURLDataManager::GetInstance(), | 655 ChromeURLDataManager::GetInstance(), |
| 619 &ChromeURLDataManager::AddDataSource, | 656 &ChromeURLDataManager::AddDataSource, |
| 620 make_scoped_refptr(html_source))); | 657 make_scoped_refptr(html_source))); |
| 621 } | 658 } |
| OLD | NEW |