diff options
author | phajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-04-11 16:03:46 +0000 |
---|---|---|
committer | phajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-04-11 16:03:46 +0000 |
commit | 79e2637bf2c443d43c7ac33cd69b2b053049d127 (patch) | |
tree | 8001b8593b2a148875a045b31fbcdd15bf7ba90e | |
parent | 325672f20a701f56f0b8f0b19728f52ad7bc7416 (diff) | |
download | chromium_src-79e2637bf2c443d43c7ac33cd69b2b053049d127.zip chromium_src-79e2637bf2c443d43c7ac33cd69b2b053049d127.tar.gz chromium_src-79e2637bf2c443d43c7ac33cd69b2b053049d127.tar.bz2 |
[chromeos] Remove more chrome dependencies from BurnManager.
BUG=180711
Review URL: https://codereview.chromium.org/13800022
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@193657 0039d316-1c4b-4281-b951-d872f2087c98
4 files changed, 40 insertions, 35 deletions
diff --git a/chrome/browser/chromeos/chrome_browser_main_chromeos.cc b/chrome/browser/chromeos/chrome_browser_main_chromeos.cc index d3acb3a..d7a7405 100644 --- a/chrome/browser/chromeos/chrome_browser_main_chromeos.cc +++ b/chrome/browser/chromeos/chrome_browser_main_chromeos.cc @@ -16,6 +16,7 @@ #include "base/lazy_instance.h" #include "base/linux_util.h" #include "base/message_loop.h" +#include "base/path_service.h" #include "base/prefs/pref_service.h" #include "base/strings/string_number_conversions.h" #include "base/strings/string_split.h" @@ -80,6 +81,7 @@ #include "chrome/browser/rlz/rlz.h" #include "chrome/browser/storage_monitor/storage_monitor_chromeos.h" #include "chrome/common/chrome_notification_types.h" +#include "chrome/common/chrome_paths.h" #include "chrome/common/chrome_switches.h" #include "chrome/common/chrome_version_info.h" #include "chrome/common/logging_chrome.h" @@ -451,7 +453,11 @@ void ChromeBrowserMainPartsChromeos::PostMainMessageLoopStart() { // about_flags settings are applied in ChromeBrowserMainParts::PreCreateThreads. void ChromeBrowserMainPartsChromeos::PreMainMessageLoopRun() { AudioHandler::Initialize(); - imageburner::BurnManager::Initialize(); + + base::FilePath downloads_directory; + CHECK(PathService::Get(chrome::DIR_DEFAULT_DOWNLOADS, &downloads_directory)); + imageburner::BurnManager::Initialize( + downloads_directory, g_browser_process->system_request_context()); // 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 diff --git a/chrome/browser/chromeos/imageburner/burn_controller.cc b/chrome/browser/chromeos/imageburner/burn_controller.cc index c6d84e3..a5784ae 100644 --- a/chrome/browser/chromeos/imageburner/burn_controller.cc +++ b/chrome/browser/chromeos/imageburner/burn_controller.cc @@ -9,6 +9,7 @@ #include "base/memory/weak_ptr.h" #include "chrome/browser/chromeos/cros/cros_library.h" #include "chrome/browser/chromeos/imageburner/burn_manager.h" +#include "chromeos/network/network_state_handler.h" #include "googleurl/src/gurl.h" #include "grit/generated_resources.h" @@ -126,7 +127,7 @@ class BurnControllerImpl const base::FilePath& target_file_path) OVERRIDE { if (!target_device_path.empty() && !target_file_path.empty() && state_machine_->new_burn_posible()) { - if (!burn_manager_->IsNetworkConnected()) { + if (!NetworkStateHandler::Get()->DefaultNetwork()) { delegate_->OnNoNetwork(); return; } diff --git a/chrome/browser/chromeos/imageburner/burn_manager.cc b/chrome/browser/chromeos/imageburner/burn_manager.cc index 1321787..de901ab 100644 --- a/chrome/browser/chromeos/imageburner/burn_manager.cc +++ b/chrome/browser/chromeos/imageburner/burn_manager.cc @@ -6,20 +6,18 @@ #include "base/bind.h" #include "base/file_util.h" -#include "base/path_service.h" #include "base/string_util.h" #include "base/threading/worker_pool.h" -#include "chrome/browser/browser_process.h" -#include "chrome/browser/chromeos/cros/cros_library.h" -#include "chrome/browser/chromeos/net/connectivity_state_helper.h" #include "chrome/browser/chromeos/system/statistics_provider.h" -#include "chrome/common/chrome_paths.h" #include "chromeos/dbus/dbus_thread_manager.h" #include "chromeos/dbus/image_burner_client.h" +#include "chromeos/network/network_state.h" +#include "chromeos/network/network_state_handler.h" #include "components/zip/zip.h" #include "content/public/browser/browser_thread.h" #include "grit/generated_resources.h" #include "net/url_request/url_fetcher.h" +#include "net/url_request/url_request_context_getter.h" #include "net/url_request/url_request_status.h" using content::BrowserThread; @@ -212,18 +210,22 @@ void StateMachine::OnSuccess() { // //////////////////////////////////////////////////////////////////////////////// -BurnManager::BurnManager() +BurnManager::BurnManager( + const base::FilePath& downloads_directory, + scoped_refptr<net::URLRequestContextGetter> context_getter) : device_handler_(disks::DiskMountManager::GetInstance()), unzipping_(false), cancelled_(false), burning_(false), block_burn_signals_(false), + image_dir_(downloads_directory.Append(kTempImageFolderName)), config_file_url_(kConfigFileUrl), config_file_fetched_(false), state_machine_(new StateMachine()), + url_request_context_getter_(context_getter), bytes_image_download_progress_last_reported_(0), ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) { - ConnectivityStateHelper::Get()->AddNetworkManagerObserver(this); + NetworkStateHandler::Get()->AddObserver(this); base::WeakPtr<BurnManager> weak_ptr(weak_ptr_factory_.GetWeakPtr()); device_handler_.SetCallbacks( base::Bind(&BurnManager::NotifyDeviceAdded, weak_ptr), @@ -239,17 +241,19 @@ BurnManager::~BurnManager() { if (!image_dir_.empty()) { file_util::Delete(image_dir_, true); } - ConnectivityStateHelper::Get()->RemoveNetworkManagerObserver(this); + NetworkStateHandler::Get()->RemoveObserver(this); DBusThreadManager::Get()->GetImageBurnerClient()->ResetEventHandlers(); } // static -void BurnManager::Initialize() { +void BurnManager::Initialize( + const base::FilePath& downloads_directory, + scoped_refptr<net::URLRequestContextGetter> context_getter) { if (g_burn_manager) { LOG(WARNING) << "BurnManager was already initialized"; return; } - g_burn_manager = new BurnManager(); + g_burn_manager = new BurnManager(downloads_directory, context_getter); VLOG(1) << "BurnManager initialized"; } @@ -281,10 +285,6 @@ std::vector<disks::DiskMountManager::Disk> BurnManager::GetBurnableDevices() { return device_handler_.GetBurnableDevices(); } -bool BurnManager::IsNetworkConnected() const { - return CrosLibrary::Get()->GetNetworkLibrary()->Connected(); -} - void BurnManager::Cancel() { OnError(IDS_IMAGEBURN_USER_ERROR); } @@ -320,8 +320,6 @@ void BurnManager::OnError(int message_id) { void BurnManager::CreateImageDir() { if (image_dir_.empty()) { - CHECK(PathService::Get(chrome::DIR_DEFAULT_DOWNLOADS, &image_dir_)); - image_dir_ = image_dir_.Append(kTempImageFolderName); BrowserThread::PostBlockingPoolTask( FROM_HERE, base::Bind(CreateDirectory, @@ -362,8 +360,7 @@ void BurnManager::FetchConfigFile() { config_fetcher_.reset(net::URLFetcher::Create( config_file_url_, net::URLFetcher::GET, this)); - config_fetcher_->SetRequestContext( - g_browser_process->system_request_context()); + config_fetcher_->SetRequestContext(url_request_context_getter_); config_fetcher_->Start(); } @@ -383,8 +380,7 @@ void BurnManager::FetchImage() { image_fetcher_.reset(net::URLFetcher::Create(image_download_url_, net::URLFetcher::GET, this)); - image_fetcher_->SetRequestContext( - g_browser_process->system_request_context()); + image_fetcher_->SetRequestContext(url_request_context_getter_); image_fetcher_->SaveResponseToFileAtPath( zip_image_file_path_, BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE)); @@ -491,13 +487,12 @@ void BurnManager::OnURLFetchDownloadProgress(const net::URLFetcher* source, } } -void BurnManager::NetworkManagerChanged() { +void BurnManager::DefaultNetworkChanged(const NetworkState* network) { // TODO(hidehiko): Split this into a class to write tests. - if (state_machine_->state() == StateMachine::INITIAL && IsNetworkConnected()) + if (state_machine_->state() == StateMachine::INITIAL && network) FOR_EACH_OBSERVER(Observer, observers_, OnNetworkDetected()); - if (state_machine_->state() == StateMachine::DOWNLOADING && - !IsNetworkConnected()) + if (state_machine_->state() == StateMachine::DOWNLOADING && !network) OnError(IDS_IMAGEBURN_NETWORK_ERROR); } diff --git a/chrome/browser/chromeos/imageburner/burn_manager.h b/chrome/browser/chromeos/imageburner/burn_manager.h index 7fad8c3..d53e12d 100644 --- a/chrome/browser/chromeos/imageburner/burn_manager.h +++ b/chrome/browser/chromeos/imageburner/burn_manager.h @@ -17,13 +17,14 @@ #include "base/observer_list.h" #include "base/time.h" #include "chrome/browser/chromeos/imageburner/burn_device_handler.h" -#include "chrome/browser/chromeos/net/connectivity_state_helper_observer.h" #include "chromeos/disks/disk_mount_manager.h" +#include "chromeos/network/network_state_handler_observer.h" #include "googleurl/src/gurl.h" #include "net/url_request/url_fetcher_delegate.h" namespace net { class URLFetcher; +class URLRequestContextGetter; } // namespace net namespace chromeos { @@ -210,7 +211,7 @@ class StateMachine { // TODO(hidehiko): Simplify the relationship among this class, // BurnController and helper classes defined above. class BurnManager : public net::URLFetcherDelegate, - public ConnectivityStateHelperObserver { + public NetworkStateHandlerObserver { public: // Interface for classes that need to observe events for the burning image // tasks. @@ -246,7 +247,9 @@ class BurnManager : public net::URLFetcherDelegate, }; // Creates the global BurnManager instance. - static void Initialize(); + static void Initialize( + const base::FilePath& downloads_directory, + scoped_refptr<net::URLRequestContextGetter> context_getter); // Destroys the global BurnManager instance if it exists. static void Shutdown(); @@ -264,9 +267,6 @@ class BurnManager : public net::URLFetcherDelegate, // Returns devices on which we can burn recovery image. std::vector<disks::DiskMountManager::Disk> GetBurnableDevices(); - // Returns true if some network is connected. - bool IsNetworkConnected() const; - // Cancels a currently running task of burning recovery image. // Note: currently we only support Cancel method, which may look asymmetry // because there is no method to start the task. It is just because that @@ -316,8 +316,8 @@ class BurnManager : public net::URLFetcherDelegate, int64 current, int64 total) OVERRIDE; - // ConnectivityStateHelperObserver override. - virtual void NetworkManagerChanged() OVERRIDE; + // NetworkStateHandlerObserver override. + virtual void DefaultNetworkChanged(const NetworkState* network) OVERRIDE; // Creates directory image will be downloaded to. // Must be called from FILE thread. @@ -345,7 +345,8 @@ class BurnManager : public net::URLFetcherDelegate, StateMachine* state_machine() const { return state_machine_.get(); } private: - BurnManager(); + BurnManager(const base::FilePath& downloads_directory, + scoped_refptr<net::URLRequestContextGetter> context_getter); virtual ~BurnManager(); void UpdateBurnStatus(BurnEvent evt, const ImageBurnStatus& status); @@ -389,6 +390,8 @@ class BurnManager : public net::URLFetcherDelegate, scoped_ptr<net::URLFetcher> config_fetcher_; scoped_ptr<net::URLFetcher> image_fetcher_; + scoped_refptr<net::URLRequestContextGetter> url_request_context_getter_; + base::TimeTicks tick_image_download_start_; int64 bytes_image_download_progress_last_reported_; |