| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/ui/webui/chromeos/imageburner/imageburner_ui.h" | 5 #include "chrome/browser/ui/webui/chromeos/imageburner/imageburner_ui.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 #include "content/public/browser/browser_thread.h" | 23 #include "content/public/browser/browser_thread.h" |
| 24 #include "grit/browser_resources.h" | 24 #include "grit/browser_resources.h" |
| 25 #include "grit/generated_resources.h" | 25 #include "grit/generated_resources.h" |
| 26 #include "grit/locale_settings.h" | 26 #include "grit/locale_settings.h" |
| 27 #include "ui/base/l10n/l10n_util.h" | 27 #include "ui/base/l10n/l10n_util.h" |
| 28 #include "ui/base/resource/resource_bundle.h" | 28 #include "ui/base/resource/resource_bundle.h" |
| 29 #include "ui/base/text/bytes_formatting.h" | 29 #include "ui/base/text/bytes_formatting.h" |
| 30 | 30 |
| 31 using content::BrowserThread; | 31 using content::BrowserThread; |
| 32 using content::DownloadItem; | 32 using content::DownloadItem; |
| 33 using content::WebContents; |
| 33 | 34 |
| 34 const char kPropertyDevicePath[] = "devicePath"; | 35 const char kPropertyDevicePath[] = "devicePath"; |
| 35 const char kPropertyFilePath[] = "filePath"; | 36 const char kPropertyFilePath[] = "filePath"; |
| 36 const char kPropertyLabel[] = "label"; | 37 const char kPropertyLabel[] = "label"; |
| 37 const char kPropertyPath[] = "path"; | 38 const char kPropertyPath[] = "path"; |
| 38 | 39 |
| 39 // Name for hwid in machine statistics. | 40 // Name for hwid in machine statistics. |
| 40 const char kHwidStatistic[] = "hardware_class"; | 41 const char kHwidStatistic[] = "hardware_class"; |
| 41 | 42 |
| 42 const char kImageZipFileName[] = "chromeos_image.bin.zip"; | 43 const char kImageZipFileName[] = "chromeos_image.bin.zip"; |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 BrowserThread::UI, FROM_HERE, | 121 BrowserThread::UI, FROM_HERE, |
| 121 base::Bind(&WebUIHandlerTaskProxy::DoNothing, this)); | 122 base::Bind(&WebUIHandlerTaskProxy::DoNothing, this)); |
| 122 } | 123 } |
| 123 | 124 |
| 124 //////////////////////////////////////////////////////////////////////////////// | 125 //////////////////////////////////////////////////////////////////////////////// |
| 125 // | 126 // |
| 126 // WebUIHandler | 127 // WebUIHandler |
| 127 // | 128 // |
| 128 //////////////////////////////////////////////////////////////////////////////// | 129 //////////////////////////////////////////////////////////////////////////////// |
| 129 | 130 |
| 130 WebUIHandler::WebUIHandler(TabContents* contents) | 131 WebUIHandler::WebUIHandler(WebContents* contents) |
| 131 : tab_contents_(contents), | 132 : web_contents_(contents), |
| 132 download_manager_(NULL), | 133 download_manager_(NULL), |
| 133 active_download_item_(NULL), | 134 active_download_item_(NULL), |
| 134 burn_manager_(NULL), | 135 burn_manager_(NULL), |
| 135 state_machine_(NULL), | 136 state_machine_(NULL), |
| 136 observing_burn_lib_(false), | 137 observing_burn_lib_(false), |
| 137 working_(false) { | 138 working_(false) { |
| 138 chromeos::disks::DiskMountManager::GetInstance()->AddObserver(this); | 139 chromeos::disks::DiskMountManager::GetInstance()->AddObserver(this); |
| 139 chromeos::CrosLibrary::Get()->GetNetworkLibrary()-> | 140 chromeos::CrosLibrary::Get()->GetNetworkLibrary()-> |
| 140 AddNetworkManagerObserver(this); | 141 AddNetworkManagerObserver(this); |
| 141 burn_manager_ = BurnManager::GetInstance(); | 142 burn_manager_ = BurnManager::GetInstance(); |
| (...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 383 BrowserThread::UI, FROM_HERE, | 384 BrowserThread::UI, FROM_HERE, |
| 384 base::Bind(&WebUIHandlerTaskProxy::OnImageDirCreated, | 385 base::Bind(&WebUIHandlerTaskProxy::OnImageDirCreated, |
| 385 task.get(), success)); | 386 task.get(), success)); |
| 386 } | 387 } |
| 387 | 388 |
| 388 void WebUIHandler::ImageDirCreatedOnUIThread(bool success) { | 389 void WebUIHandler::ImageDirCreatedOnUIThread(bool success) { |
| 389 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 390 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 390 if (success) { | 391 if (success) { |
| 391 zip_image_file_path_ = | 392 zip_image_file_path_ = |
| 392 burn_manager_->GetImageDir().Append(kImageZipFileName); | 393 burn_manager_->GetImageDir().Append(kImageZipFileName); |
| 393 burn_manager_->FetchConfigFile(tab_contents_, this); | 394 burn_manager_->FetchConfigFile(web_contents_, this); |
| 394 } else { | 395 } else { |
| 395 DownloadCompleted(success); | 396 DownloadCompleted(success); |
| 396 } | 397 } |
| 397 } | 398 } |
| 398 | 399 |
| 399 void WebUIHandler::OnConfigFileFetched(const ConfigFile& | 400 void WebUIHandler::OnConfigFileFetched(const ConfigFile& |
| 400 config_file, bool success) { | 401 config_file, bool success) { |
| 401 | 402 |
| 402 if (!success || !ExtractInfoFromConfigFile(config_file)) { | 403 if (!success || !ExtractInfoFromConfigFile(config_file)) { |
| 403 DownloadCompleted(false); | 404 DownloadCompleted(false); |
| 404 return; | 405 return; |
| 405 } | 406 } |
| 406 | 407 |
| 407 if (state_machine_->download_finished()) { | 408 if (state_machine_->download_finished()) { |
| 408 BurnImage(); | 409 BurnImage(); |
| 409 return; | 410 return; |
| 410 } | 411 } |
| 411 | 412 |
| 412 if (!download_manager_) { | 413 if (!download_manager_) { |
| 413 download_manager_ = | 414 download_manager_ = |
| 414 tab_contents_->GetBrowserContext()->GetDownloadManager(); | 415 web_contents_->GetBrowserContext()->GetDownloadManager(); |
| 415 download_manager_->AddObserver(this); | 416 download_manager_->AddObserver(this); |
| 416 } | 417 } |
| 417 if (!state_machine_->download_started()) { | 418 if (!state_machine_->download_started()) { |
| 418 burn_manager_->downloader()->AddListener(this, image_download_url_); | 419 burn_manager_->downloader()->AddListener(this, image_download_url_); |
| 419 if (!state_machine_->image_download_requested()) { | 420 if (!state_machine_->image_download_requested()) { |
| 420 state_machine_->OnImageDownloadRequested(); | 421 state_machine_->OnImageDownloadRequested(); |
| 421 burn_manager_->downloader()->DownloadFile(image_download_url_, | 422 burn_manager_->downloader()->DownloadFile(image_download_url_, |
| 422 zip_image_file_path_, tab_contents_); | 423 zip_image_file_path_, web_contents_); |
| 423 } | 424 } |
| 424 } | 425 } |
| 425 } | 426 } |
| 426 | 427 |
| 427 void WebUIHandler::DownloadCompleted(bool success) { | 428 void WebUIHandler::DownloadCompleted(bool success) { |
| 428 CleanupDownloadObjects(); | 429 CleanupDownloadObjects(); |
| 429 if (success) { | 430 if (success) { |
| 430 state_machine_->OnDownloadFinished(); | 431 state_machine_->OnDownloadFinished(); |
| 431 BurnImage(); | 432 BurnImage(); |
| 432 } else { | 433 } else { |
| (...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 636 } | 637 } |
| 637 | 638 |
| 638 } // namespace imageburner. | 639 } // namespace imageburner. |
| 639 | 640 |
| 640 //////////////////////////////////////////////////////////////////////////////// | 641 //////////////////////////////////////////////////////////////////////////////// |
| 641 // | 642 // |
| 642 // ImageBurnUI | 643 // ImageBurnUI |
| 643 // | 644 // |
| 644 //////////////////////////////////////////////////////////////////////////////// | 645 //////////////////////////////////////////////////////////////////////////////// |
| 645 | 646 |
| 646 ImageBurnUI::ImageBurnUI(TabContents* contents) : ChromeWebUI(contents) { | 647 ImageBurnUI::ImageBurnUI(WebContents* contents) : ChromeWebUI(contents) { |
| 647 imageburner::WebUIHandler* handler = new imageburner::WebUIHandler(contents); | 648 imageburner::WebUIHandler* handler = new imageburner::WebUIHandler(contents); |
| 648 AddMessageHandler(handler); | 649 AddMessageHandler(handler); |
| 649 | 650 |
| 650 Profile* profile = Profile::FromBrowserContext(contents->GetBrowserContext()); | 651 Profile* profile = Profile::FromBrowserContext(contents->GetBrowserContext()); |
| 651 profile->GetChromeURLDataManager()->AddDataSource( | 652 profile->GetChromeURLDataManager()->AddDataSource( |
| 652 CreateImageburnerUIHTMLSource()); | 653 CreateImageburnerUIHTMLSource()); |
| 653 } | 654 } |
| OLD | NEW |