summaryrefslogtreecommitdiffstats
path: root/chrome/browser
diff options
context:
space:
mode:
authorhashimoto@chromium.org <hashimoto@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-03-30 04:28:16 +0000
committerhashimoto@chromium.org <hashimoto@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-03-30 04:28:16 +0000
commite013858e413435be2ce7d5a53d32b3cffdc4182b (patch)
tree323f50d0acfccc2c3b1884a02aa2b693864cc02c /chrome/browser
parent7e2a973350fae3cd762d6bf89376d240de660404 (diff)
downloadchromium_src-e013858e413435be2ce7d5a53d32b3cffdc4182b.zip
chromium_src-e013858e413435be2ce7d5a53d32b3cffdc4182b.tar.gz
chromium_src-e013858e413435be2ce7d5a53d32b3cffdc4182b.tar.bz2
chromeos: Move recovery config file reading code from BurnController to BurnManager
BUG=chromium-os:28630 TEST=chrome://imageburner works Review URL: https://chromiumcodereview.appspot.com/9802049 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@129784 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
-rw-r--r--chrome/browser/chromeos/imageburner/burn_controller.cc34
-rw-r--r--chrome/browser/chromeos/imageburner/burn_manager.cc33
-rw-r--r--chrome/browser/chromeos/imageburner/burn_manager.h11
3 files changed, 38 insertions, 40 deletions
diff --git a/chrome/browser/chromeos/imageburner/burn_controller.cc b/chrome/browser/chromeos/imageburner/burn_controller.cc
index fffc9d0..197b1b1 100644
--- a/chrome/browser/chromeos/imageburner/burn_controller.cc
+++ b/chrome/browser/chromeos/imageburner/burn_controller.cc
@@ -11,7 +11,6 @@
#include "chrome/browser/chromeos/cros/cros_library.h"
#include "chrome/browser/chromeos/cros/network_library.h"
#include "chrome/browser/chromeos/imageburner/burn_manager.h"
-#include "chrome/browser/chromeos/system/statistics_provider.h"
#include "grit/generated_resources.h"
#include "googleurl/src/gurl.h"
@@ -20,9 +19,6 @@ namespace imageburner {
namespace {
-// Name for hwid in machine statistics.
-const char kHwidStatistic[] = "hardware_class";
-
const char kImageZipFileName[] = "chromeos_image.bin.zip";
// 3.9GB. It is less than 4GB because true device size ussually varies a little.
@@ -182,12 +178,14 @@ class BurnControllerImpl
}
// Part of BurnManager::Delegate interface.
- virtual void OnConfigFileFetched(const ConfigFile& config_file, bool success)
- OVERRIDE {
- if (!success || !ExtractInfoFromConfigFile(config_file)) {
+ virtual void OnConfigFileFetched(bool success,
+ const std::string& image_file_name,
+ const GURL& image_download_url) OVERRIDE {
+ if (!success) {
DownloadCompleted(false);
return;
}
+ image_file_name_ = image_file_name;
if (state_machine_->download_finished()) {
BurnImage();
@@ -195,7 +193,7 @@ class BurnControllerImpl
}
if (!state_machine_->download_started()) {
- burn_manager_->FetchImage(image_download_url_, zip_image_file_path_);
+ burn_manager_->FetchImage(image_download_url, zip_image_file_path_);
state_machine_->OnDownloadStarted();
}
}
@@ -333,25 +331,6 @@ class BurnControllerImpl
burn_manager_->ResetTargetPaths();
}
- bool ExtractInfoFromConfigFile(const ConfigFile& config_file) {
- std::string hwid;
- if (!system::StatisticsProvider::GetInstance()->
- GetMachineStatistic(kHwidStatistic, &hwid))
- return false;
-
- image_file_name_ = config_file.GetProperty(kFileName, hwid);
- if (image_file_name_.empty())
- return false;
-
- image_download_url_ = GURL(config_file.GetProperty(kUrl, hwid));
- if (image_download_url_.is_empty()) {
- image_file_name_.clear();
- return false;
- }
-
- return true;
- }
-
int64 GetDeviceSize(const std::string& device_path) {
disks::DiskMountManager* disk_mount_manager =
disks::DiskMountManager::GetInstance();
@@ -364,7 +343,6 @@ class BurnControllerImpl
}
FilePath zip_image_file_path_;
- GURL image_download_url_;
std::string image_file_name_;
BurnManager* burn_manager_;
StateMachine* state_machine_;
diff --git a/chrome/browser/chromeos/imageburner/burn_manager.cc b/chrome/browser/chromeos/imageburner/burn_manager.cc
index b4d89c5..f784623 100644
--- a/chrome/browser/chromeos/imageburner/burn_manager.cc
+++ b/chrome/browser/chromeos/imageburner/burn_manager.cc
@@ -9,6 +9,7 @@
#include "base/path_service.h"
#include "base/string_util.h"
#include "chrome/browser/browser_process.h"
+#include "chrome/browser/chromeos/system/statistics_provider.h"
#include "chrome/common/chrome_paths.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/common/url_fetcher.h"
@@ -21,6 +22,9 @@ namespace imageburner {
namespace {
+// Name for hwid in machine statistics.
+const char kHwidStatistic[] = "hardware_class";
+
const char kConfigFileUrl[] =
"https://dl.google.com/dl/edgedl/chromeos/recovery/recovery.conf";
const char kTempImageFolderName[] = "chromeos_image";
@@ -197,6 +201,7 @@ void StateMachine::OnCancelation() {
BurnManager::BurnManager()
: weak_ptr_factory_(this),
config_file_url_(kConfigFileUrl),
+ config_file_fetched_(false),
state_machine_(new StateMachine()),
bytes_image_download_progress_last_reported_(0) {
}
@@ -267,8 +272,8 @@ const FilePath& BurnManager::GetImageDir() {
}
void BurnManager::FetchConfigFile(Delegate* delegate) {
- if (config_file_fetched()) {
- delegate->OnConfigFileFetched(config_file_, true);
+ if (config_file_fetched_) {
+ delegate->OnConfigFileFetched(true, image_file_name_, image_download_url_);
return;
}
downloaders_.push_back(delegate->AsWeakPtr());
@@ -338,18 +343,32 @@ void BurnManager::OnURLFetchDownloadProgress(const content::URLFetcher* source,
}
void BurnManager::ConfigFileFetched(bool fetched, const std::string& content) {
- if (config_file_fetched())
+ if (config_file_fetched_)
return;
- if (fetched) {
- config_file_.reset(content);
+ // Get image file name and image download URL.
+ std::string hwid;
+ if (fetched && system::StatisticsProvider::GetInstance()->
+ GetMachineStatistic(kHwidStatistic, &hwid)) {
+ ConfigFile config_file(content);
+ image_file_name_ = config_file.GetProperty(kFileName, hwid);
+ image_download_url_ = GURL(config_file.GetProperty(kUrl, hwid));
+ }
+
+ // Error check.
+ if (fetched && !image_file_name_.empty() && !image_download_url_.is_empty()) {
+ config_file_fetched_ = true;
} else {
- config_file_.clear();
+ fetched = false;
+ image_file_name_.clear();
+ image_download_url_ = GURL();
}
for (size_t i = 0; i < downloaders_.size(); ++i) {
if (downloaders_[i]) {
- downloaders_[i]->OnConfigFileFetched(config_file_, fetched);
+ downloaders_[i]->OnConfigFileFetched(fetched,
+ image_file_name_,
+ image_download_url_);
}
}
downloaders_.clear();
diff --git a/chrome/browser/chromeos/imageburner/burn_manager.h b/chrome/browser/chromeos/imageburner/burn_manager.h
index de125b4..15a4622 100644
--- a/chrome/browser/chromeos/imageburner/burn_manager.h
+++ b/chrome/browser/chromeos/imageburner/burn_manager.h
@@ -160,8 +160,9 @@ class BurnManager : content::URLFetcherDelegate {
class Delegate : public base::SupportsWeakPtr<Delegate> {
public:
virtual void OnImageDirCreated(bool success) = 0;
- virtual void OnConfigFileFetched(const ConfigFile& config_file,
- bool success) = 0;
+ virtual void OnConfigFileFetched(bool success,
+ const std::string& image_file_name,
+ const GURL& image_download_url) = 0;
};
class Observer {
@@ -237,16 +238,16 @@ class BurnManager : content::URLFetcherDelegate {
void OnImageDirCreated(Delegate* delegate, bool success);
void ConfigFileFetched(bool fetched, const std::string& content);
- bool config_file_fetched() const { return !config_file_.empty(); }
-
base::WeakPtrFactory<BurnManager> weak_ptr_factory_;
FilePath image_dir_;
FilePath target_device_path_;
FilePath target_file_path_;
- ConfigFile config_file_;
GURL config_file_url_;
+ bool config_file_fetched_;
+ std::string image_file_name_;
+ GURL image_download_url_;
std::vector<base::WeakPtr<Delegate> > downloaders_;
scoped_ptr<StateMachine> state_machine_;