Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(36)

Side by Side Diff: chrome/browser/chromeos/imageburner/burn_manager.cc

Issue 12729002: Add a unified observer to replace NetworkManagerObserver (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/imageburner/burn_manager.h" 5 #include "chrome/browser/chromeos/imageburner/burn_manager.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/file_util.h" 8 #include "base/file_util.h"
9 #include "base/path_service.h" 9 #include "base/path_service.h"
10 #include "base/string_util.h" 10 #include "base/string_util.h"
11 #include "chrome/browser/browser_process.h" 11 #include "chrome/browser/browser_process.h"
12 #include "chrome/browser/chromeos/cros/burn_library.h" 12 #include "chrome/browser/chromeos/cros/burn_library.h"
13 #include "chrome/browser/chromeos/cros/cros_library.h" 13 #include "chrome/browser/chromeos/cros/cros_library.h"
14 #include "chrome/browser/chromeos/net/connectivity_state_helper.h"
14 #include "chrome/browser/chromeos/system/statistics_provider.h" 15 #include "chrome/browser/chromeos/system/statistics_provider.h"
15 #include "chrome/common/chrome_paths.h" 16 #include "chrome/common/chrome_paths.h"
16 #include "content/public/browser/browser_thread.h" 17 #include "content/public/browser/browser_thread.h"
17 #include "grit/generated_resources.h" 18 #include "grit/generated_resources.h"
18 #include "net/url_request/url_fetcher.h" 19 #include "net/url_request/url_fetcher.h"
19 #include "net/url_request/url_request_status.h" 20 #include "net/url_request/url_request_status.h"
20 21
21 using content::BrowserThread; 22 using content::BrowserThread;
22 23
23 namespace chromeos { 24 namespace chromeos {
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 // 198 //
198 //////////////////////////////////////////////////////////////////////////////// 199 ////////////////////////////////////////////////////////////////////////////////
199 200
200 BurnManager::BurnManager() 201 BurnManager::BurnManager()
201 : device_handler_(disks::DiskMountManager::GetInstance()), 202 : device_handler_(disks::DiskMountManager::GetInstance()),
202 config_file_url_(kConfigFileUrl), 203 config_file_url_(kConfigFileUrl),
203 config_file_fetched_(false), 204 config_file_fetched_(false),
204 state_machine_(new StateMachine()), 205 state_machine_(new StateMachine()),
205 bytes_image_download_progress_last_reported_(0), 206 bytes_image_download_progress_last_reported_(0),
206 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) { 207 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) {
207 CrosLibrary::Get()->GetNetworkLibrary()->AddNetworkManagerObserver(this); 208 ConnectivityStateHelper::Get()->AddNetworkManagerObserver(this);
208 CrosLibrary::Get()->GetBurnLibrary()->AddObserver(this); 209 CrosLibrary::Get()->GetBurnLibrary()->AddObserver(this);
209 base::WeakPtr<BurnManager> weak_ptr(weak_ptr_factory_.GetWeakPtr()); 210 base::WeakPtr<BurnManager> weak_ptr(weak_ptr_factory_.GetWeakPtr());
210 device_handler_.SetCallbacks( 211 device_handler_.SetCallbacks(
211 base::Bind(&BurnManager::NotifyDeviceAdded, weak_ptr), 212 base::Bind(&BurnManager::NotifyDeviceAdded, weak_ptr),
212 base::Bind(&BurnManager::NotifyDeviceRemoved, weak_ptr)); 213 base::Bind(&BurnManager::NotifyDeviceRemoved, weak_ptr));
213 } 214 }
214 215
215 BurnManager::~BurnManager() { 216 BurnManager::~BurnManager() {
216 if (!image_dir_.empty()) { 217 if (!image_dir_.empty()) {
217 file_util::Delete(image_dir_, true); 218 file_util::Delete(image_dir_, true);
218 } 219 }
219 CrosLibrary::Get()->GetBurnLibrary()->RemoveObserver(this); 220 CrosLibrary::Get()->GetBurnLibrary()->RemoveObserver(this);
220 CrosLibrary::Get()->GetNetworkLibrary()->RemoveNetworkManagerObserver(this); 221 ConnectivityStateHelper::Get()->RemoveNetworkManagerObserver(this);
221 } 222 }
222 223
223 // static 224 // static
224 void BurnManager::Initialize() { 225 void BurnManager::Initialize() {
225 if (g_burn_manager) { 226 if (g_burn_manager) {
226 LOG(WARNING) << "BurnManager was already initialized"; 227 LOG(WARNING) << "BurnManager was already initialized";
227 return; 228 return;
228 } 229 }
229 g_burn_manager = new BurnManager(); 230 g_burn_manager = new BurnManager();
230 VLOG(1) << "BurnManager initialized"; 231 VLOG(1) << "BurnManager initialized";
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
411 // The burning task is successfully done. 412 // The burning task is successfully done.
412 // Update the state. 413 // Update the state.
413 state_machine_->OnSuccess(); 414 state_machine_->OnSuccess();
414 } 415 }
415 416
416 // Proxy the BurnLibrary callback to observers. 417 // Proxy the BurnLibrary callback to observers.
417 FOR_EACH_OBSERVER( 418 FOR_EACH_OBSERVER(
418 Observer, observers_, OnBurnProgressUpdated(event, status)); 419 Observer, observers_, OnBurnProgressUpdated(event, status));
419 } 420 }
420 421
421 void BurnManager::OnNetworkManagerChanged(NetworkLibrary* obj) { 422 void BurnManager::NetworkManagerChanged() {
422 // TODO(hidehiko): Split this into a class to write tests. 423 // TODO(hidehiko): Split this into a class to write tests.
423 if (state_machine_->state() == StateMachine::INITIAL && IsNetworkConnected()) 424 if (state_machine_->state() == StateMachine::INITIAL && IsNetworkConnected())
424 FOR_EACH_OBSERVER(Observer, observers_, OnNetworkDetected()); 425 FOR_EACH_OBSERVER(Observer, observers_, OnNetworkDetected());
425 426
426 if (state_machine_->state() == StateMachine::DOWNLOADING && 427 if (state_machine_->state() == StateMachine::DOWNLOADING &&
427 !IsNetworkConnected()) 428 !IsNetworkConnected())
428 OnError(IDS_IMAGEBURN_NETWORK_ERROR); 429 OnError(IDS_IMAGEBURN_NETWORK_ERROR);
429 } 430 }
430 431
431 void BurnManager::ConfigFileFetched(bool fetched, const std::string& content) { 432 void BurnManager::ConfigFileFetched(bool fetched, const std::string& content) {
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
467 // Note: in theory, this is not a part of notification, but cancelling 468 // Note: in theory, this is not a part of notification, but cancelling
468 // the running burning task. However, there is no good place to be in the 469 // the running burning task. However, there is no good place to be in the
469 // current code. 470 // current code.
470 // TODO(hidehiko): Clean this up after refactoring. 471 // TODO(hidehiko): Clean this up after refactoring.
471 OnError(IDS_IMAGEBURN_DEVICE_NOT_FOUND_ERROR); 472 OnError(IDS_IMAGEBURN_DEVICE_NOT_FOUND_ERROR);
472 } 473 }
473 } 474 }
474 475
475 } // namespace imageburner 476 } // namespace imageburner
476 } // namespace chromeos 477 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/imageburner/burn_manager.h ('k') | chrome/browser/chromeos/login/login_utils.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698