summaryrefslogtreecommitdiffstats
path: root/chrome/browser
diff options
context:
space:
mode:
authorhashimoto@chromium.org <hashimoto@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-03-02 15:00:38 +0000
committerhashimoto@chromium.org <hashimoto@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-03-02 15:00:38 +0000
commita704b43862c3fa26e6c218b5c6d8f42ad05f3264 (patch)
treef4d1a76ce123dc669f7713adcb940c3ad30fc8e4 /chrome/browser
parent4317ccc735d9503b3a7c9f0a7043770322dd4bd9 (diff)
downloadchromium_src-a704b43862c3fa26e6c218b5c6d8f42ad05f3264.zip
chromium_src-a704b43862c3fa26e6c218b5c6d8f42ad05f3264.tar.gz
chromium_src-a704b43862c3fa26e6c218b5c6d8f42ad05f3264.tar.bz2
Use URLFetcher to download ChromeOS recovery image config file
Initialization of BurnManager is deferred since it depends on IO thread through BrowserProcess::system_request_context. BUG=113469 TEST=Open chrome://imageburner on a Chromebook, ensure it works. Review URL: http://codereview.chromium.org/9568001 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@124638 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
-rw-r--r--chrome/browser/chromeos/chrome_browser_main_chromeos.cc4
-rw-r--r--chrome/browser/chromeos/imageburner/burn_controller.cc2
-rw-r--r--chrome/browser/chromeos/imageburner/burn_manager.cc113
-rw-r--r--chrome/browser/chromeos/imageburner/burn_manager.h45
4 files changed, 46 insertions, 118 deletions
diff --git a/chrome/browser/chromeos/chrome_browser_main_chromeos.cc b/chrome/browser/chromeos/chrome_browser_main_chromeos.cc
index 579f7bc..95ab163 100644
--- a/chrome/browser/chromeos/chrome_browser_main_chromeos.cc
+++ b/chrome/browser/chromeos/chrome_browser_main_chromeos.cc
@@ -230,7 +230,6 @@ ChromeBrowserMainPartsChromeos::~ChromeBrowserMainPartsChromeos() {
if (chromeos::KioskModeHelper::IsKioskModeEnabled())
chromeos::ShutdownKioskModeScreensaver();
cryptohome::AsyncMethodCaller::Shutdown();
- chromeos::imageburner::BurnManager::Shutdown();
chromeos::disks::DiskMountManager::Shutdown();
// CrosLibrary is shut down before DBusThreadManager even though the former
@@ -292,7 +291,6 @@ void ChromeBrowserMainPartsChromeos::PostMainMessageLoopStart() {
session_manager_observer_.reset(new chromeos::SessionManagerObserver);
chromeos::disks::DiskMountManager::Initialize();
- chromeos::imageburner::BurnManager::Initialize();
cryptohome::AsyncMethodCaller::Initialize();
// Initialize the network change notifier for Chrome OS. The network
@@ -328,6 +326,7 @@ void ChromeBrowserMainPartsChromeos::PostMainMessageLoopStart() {
void ChromeBrowserMainPartsChromeos::PreMainMessageLoopRun() {
chromeos::AudioHandler::Initialize();
+ chromeos::imageburner::BurnManager::Initialize();
// Listen for system key events so that the user will be able to adjust the
// volume on the login screen, if Chrome is running on Chrome OS
@@ -535,6 +534,7 @@ void ChromeBrowserMainPartsChromeos::PostMainMessageLoopRun() {
// chromeos::SystemKeyEventListener::Shutdown() is always safe to call,
// even if Initialize() wasn't called.
chromeos::SystemKeyEventListener::Shutdown();
+ chromeos::imageburner::BurnManager::Shutdown();
chromeos::AudioHandler::Shutdown();
chromeos::WebSocketProxyController::Shutdown();
diff --git a/chrome/browser/chromeos/imageburner/burn_controller.cc b/chrome/browser/chromeos/imageburner/burn_controller.cc
index cf6a247..ed01efc 100644
--- a/chrome/browser/chromeos/imageburner/burn_controller.cc
+++ b/chrome/browser/chromeos/imageburner/burn_controller.cc
@@ -211,7 +211,7 @@ class BurnControllerImpl
if (success) {
zip_image_file_path_ =
burn_manager_->GetImageDir().Append(kImageZipFileName);
- burn_manager_->FetchConfigFile(web_contents_, this);
+ burn_manager_->FetchConfigFile(this);
} else {
DownloadCompleted(success);
}
diff --git a/chrome/browser/chromeos/imageburner/burn_manager.cc b/chrome/browser/chromeos/imageburner/burn_manager.cc
index 3bc090b..d786111 100644
--- a/chrome/browser/chromeos/imageburner/burn_manager.cc
+++ b/chrome/browser/chromeos/imageburner/burn_manager.cc
@@ -8,18 +8,19 @@
#include "base/file_util.h"
#include "base/path_service.h"
#include "base/string_util.h"
+#include "chrome/browser/browser_process.h"
#include "chrome/browser/download/download_util.h"
-#include "chrome/browser/tab_contents/tab_util.h"
#include "chrome/common/chrome_paths.h"
#include "content/browser/download/download_types.h"
-#include "content/browser/renderer_host/render_view_host.h"
#include "content/public/browser/browser_context.h"
#include "content/public/browser/browser_thread.h"
-#include "content/public/browser/render_process_host.h"
+#include "content/public/browser/download_manager.h"
#include "content/public/browser/web_contents.h"
+#include "content/public/common/url_fetcher.h"
+#include "net/base/file_stream.h"
+#include "net/url_request/url_request_status.h"
using content::BrowserThread;
-using content::DownloadItem;
using content::DownloadManager;
using content::WebContents;
@@ -31,7 +32,6 @@ namespace {
const char kConfigFileUrl[] =
"https://dl.google.com/dl/edgedl/chromeos/recovery/recovery.conf";
const char kTempImageFolderName[] = "chromeos_image";
-const char kConfigFileName[] = "recovery.conf";
BurnManager* g_burn_manager = NULL;
@@ -43,16 +43,6 @@ void CreateDirectory(const FilePath& path,
base::Bind(callback, success));
}
-// Reads file content and calls |callback| with the result on UI thread.
-void ReadFile(const FilePath& path,
- base::Callback<void(bool success,
- const std::string& file_content)> callback) {
- std::string file_content;
- const bool success = file_util::ReadFileToString(path, &file_content);
- BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
- base::Bind(callback, success, file_content));
-}
-
// Creates a FileStream and calls |callback| with the result on UI thread.
void CreateFileStream(
const FilePath& file_path,
@@ -229,12 +219,7 @@ void StateMachine::OnCancelation() {
BurnManager::BurnManager()
: weak_ptr_factory_(this),
- download_manager_(NULL),
- download_item_observer_added_(false),
- active_download_item_(NULL),
config_file_url_(kConfigFileUrl),
- config_file_requested_(false),
- config_file_fetched_(false),
state_machine_(new StateMachine()),
downloader_(NULL) {
}
@@ -243,10 +228,6 @@ BurnManager::~BurnManager() {
if (!image_dir_.empty()) {
file_util::Delete(image_dir_, true);
}
- if (active_download_item_)
- active_download_item_->RemoveObserver(this);
- if (download_manager_)
- download_manager_->RemoveObserver(this);
}
// static
@@ -275,49 +256,6 @@ BurnManager* BurnManager::GetInstance() {
return g_burn_manager;
}
-void BurnManager::OnDownloadUpdated(DownloadItem* download) {
- if (download->IsCancelled()) {
- ConfigFileFetched(false, "");
- DCHECK(!download_item_observer_added_);
- DCHECK(active_download_item_ == NULL);
- } else if (download->IsComplete()) {
- OnConfigFileDownloaded();
- }
-}
-
-void BurnManager::OnConfigFileDownloaded() {
- BrowserThread::PostBlockingPoolTask(
- FROM_HERE,
- base::Bind(ReadFile,
- config_file_path_,
- base::Bind(&BurnManager::ConfigFileFetched,
- weak_ptr_factory_.GetWeakPtr())));
-}
-
-void BurnManager::ModelChanged(DownloadManager* manager) {
- DCHECK_EQ(download_manager_, manager);
-
- std::vector<DownloadItem*> downloads;
- download_manager_->GetTemporaryDownloads(GetImageDir(), &downloads);
- if (download_item_observer_added_)
- return;
- for (std::vector<DownloadItem*>::const_iterator it = downloads.begin();
- it != downloads.end();
- ++it) {
- if ((*it)->GetURL() == config_file_url_) {
- download_item_observer_added_ = true;
- (*it)->AddObserver(this);
- active_download_item_ = *it;
- break;
- }
- }
-}
-
-void BurnManager::OnBurnDownloadStarted(bool success) {
- if (!success)
- ConfigFileFetched(false, "");
-}
-
void BurnManager::CreateImageDir(Delegate* delegate) {
if (image_dir_.empty()) {
CHECK(PathService::Get(chrome::DIR_DEFAULT_DOWNLOADS, &image_dir_));
@@ -343,39 +281,38 @@ const FilePath& BurnManager::GetImageDir() {
return image_dir_;
}
-void BurnManager::FetchConfigFile(WebContents* web_contents,
- Delegate* delegate) {
- if (config_file_fetched_) {
+void BurnManager::FetchConfigFile(Delegate* delegate) {
+ if (config_file_fetched()) {
delegate->OnConfigFileFetched(config_file_, true);
return;
}
downloaders_.push_back(delegate->AsWeakPtr());
- if (config_file_requested_)
+ if (config_fetcher_.get())
return;
- config_file_requested_ = true;
- config_file_path_ = GetImageDir().Append(kConfigFileName);
- download_manager_ = web_contents->GetBrowserContext()->GetDownloadManager();
- download_manager_->AddObserver(this);
- downloader()->AddListener(this, config_file_url_);
- downloader()->DownloadFile(config_file_url_, config_file_path_, web_contents);
+ config_fetcher_.reset(content::URLFetcher::Create(
+ config_file_url_, content::URLFetcher::GET, this));
+ config_fetcher_->StartWithRequestContextGetter(
+ g_browser_process->system_request_context());
+}
+
+void BurnManager::OnURLFetchComplete(const content::URLFetcher* source) {
+ if (source == config_fetcher_.get()) {
+ std::string data;
+ const bool success =
+ source->GetStatus().status() == net::URLRequestStatus::SUCCESS;
+ if (success)
+ config_fetcher_->GetResponseAsString(&data);
+ config_fetcher_.reset();
+ ConfigFileFetched(success, data);
+ }
}
void BurnManager::ConfigFileFetched(bool fetched, const std::string& content) {
- if (config_file_fetched_)
+ if (config_file_fetched())
return;
- if (active_download_item_) {
- active_download_item_->RemoveObserver(this);
- active_download_item_ = NULL;
- }
- download_item_observer_added_ = false;
- if (download_manager_)
- download_manager_->RemoveObserver(this);
-
- config_file_fetched_ = fetched;
-
if (fetched) {
config_file_.reset(content);
} else {
diff --git a/chrome/browser/chromeos/imageburner/burn_manager.h b/chrome/browser/chromeos/imageburner/burn_manager.h
index d28a1f16..c13c35d 100644
--- a/chrome/browser/chromeos/imageburner/burn_manager.h
+++ b/chrome/browser/chromeos/imageburner/burn_manager.h
@@ -12,11 +12,18 @@
#include <vector>
#include "base/file_path.h"
+#include "base/memory/scoped_ptr.h"
#include "base/observer_list.h"
-#include "content/public/browser/download_item.h"
-#include "content/public/browser/download_manager.h"
+#include "content/public/common/url_fetcher_delegate.h"
#include "googleurl/src/gurl.h"
-#include "net/base/file_stream.h"
+
+namespace content {
+class WebContents;
+}
+
+namespace net {
+class FileStream;
+}
namespace chromeos {
namespace imageburner {
@@ -197,10 +204,7 @@ class StateMachine {
DISALLOW_COPY_AND_ASSIGN(StateMachine);
};
-class BurnManager
- : public content::DownloadManager::Observer,
- public content::DownloadItem::Observer,
- public Downloader::Listener {
+class BurnManager : content::URLFetcherDelegate {
public:
class Delegate : public base::SupportsWeakPtr<Delegate> {
@@ -220,20 +224,12 @@ class BurnManager
// Initialize() should already have been called.
static BurnManager* GetInstance();
- // content::DownloadItem::Observer interface.
- virtual void OnDownloadUpdated(content::DownloadItem* download) OVERRIDE;
- virtual void OnDownloadOpened(content::DownloadItem* download) OVERRIDE {}
-
- // content::DownloadManager::Observer interface.
- virtual void ModelChanged(content::DownloadManager* manager) OVERRIDE;
-
- // Downloader::Listener interface.
- virtual void OnBurnDownloadStarted(bool success) OVERRIDE;
-
// Creates URL image should be fetched from.
// Must be called from UI thread.
- void FetchConfigFile(content::WebContents* web_content,
- Delegate* delegate);
+ void FetchConfigFile(Delegate* delegate);
+
+ // URLFetcherDelegate override.
+ virtual void OnURLFetchComplete(const content::URLFetcher* source) OVERRIDE;
// Creates directory image will be downloaded to.
// Must be called from FILE thread.
@@ -271,29 +267,24 @@ class BurnManager
virtual ~BurnManager();
void OnImageDirCreated(Delegate* delegate, bool success);
- void OnConfigFileDownloaded();
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_;
- FilePath config_file_path_;
-
- content::DownloadManager* download_manager_;
- bool download_item_observer_added_;
- content::DownloadItem* active_download_item_;
ConfigFile config_file_;
GURL config_file_url_;
- bool config_file_requested_;
- bool config_file_fetched_;
std::vector<base::WeakPtr<Delegate> > downloaders_;
scoped_ptr<StateMachine> state_machine_;
scoped_ptr<Downloader> downloader_;
+ scoped_ptr<content::URLFetcher> config_fetcher_;
DISALLOW_COPY_AND_ASSIGN(BurnManager);
};