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

Unified Diff: chrome/browser/chromeos/cros/update_library.cc

Issue 7672002: cros: Apply the Init() model to UpdateLibrary API. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix mock Created 9 years, 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/chromeos/cros/update_library.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/chromeos/cros/update_library.cc
diff --git a/chrome/browser/chromeos/cros/update_library.cc b/chrome/browser/chromeos/cros/update_library.cc
index f89763814033ae59f5a4914da3d2a72b0a44658f..deda502748bb2d19063a3f99a48fe3c23f186e3e 100644
--- a/chrome/browser/chromeos/cros/update_library.cc
+++ b/chrome/browser/chromeos/cros/update_library.cc
@@ -5,6 +5,7 @@
#include "chrome/browser/chromeos/cros/update_library.h"
#include "base/basictypes.h"
+#include "base/logging.h"
#include "base/message_loop.h"
#include "base/observer_list.h"
#include "chrome/browser/chromeos/cros/cros_library.h"
@@ -14,10 +15,7 @@ namespace chromeos {
class UpdateLibraryImpl : public UpdateLibrary {
public:
- UpdateLibraryImpl() : status_connection_(NULL) {
- if (CrosLibrary::Get()->EnsureLoaded())
- Init();
- }
+ UpdateLibraryImpl() : status_connection_(NULL) {}
virtual ~UpdateLibraryImpl() {
if (status_connection_) {
@@ -26,6 +24,16 @@ class UpdateLibraryImpl : public UpdateLibrary {
}
}
+ void Init() {
+ if (CrosLibrary::Get()->EnsureLoaded()) {
+ CHECK(!status_connection_) << "Already initialized";
+ status_connection_ =
+ chromeos::MonitorUpdateStatus(&UpdateStatusHandler, this);
+ // Asynchronously load the initial state.
+ chromeos::RequestUpdateStatus(&UpdateStatusHandler, this);
+ }
+ }
+
void AddObserver(Observer* observer) {
observers_.AddObserver(observer);
}
@@ -66,17 +74,11 @@ class UpdateLibraryImpl : public UpdateLibrary {
}
private:
- static void ChangedHandler(void* object, const UpdateProgress& status) {
+ static void UpdateStatusHandler(void* object, const UpdateProgress& status) {
UpdateLibraryImpl* impl = static_cast<UpdateLibraryImpl*>(object);
impl->UpdateStatus(Status(status));
}
- void Init() {
- status_connection_ = chromeos::MonitorUpdateStatus(&ChangedHandler, this);
- // Asynchronously load the initial state.
- RequestUpdateStatus(&ChangedHandler, this);
- }
-
void UpdateStatus(const Status& status) {
// Make sure we run on UI thread.
if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) {
@@ -106,6 +108,7 @@ class UpdateLibraryStubImpl : public UpdateLibrary {
public:
UpdateLibraryStubImpl() {}
virtual ~UpdateLibraryStubImpl() {}
+ void Init() {}
void AddObserver(Observer* observer) {}
void RemoveObserver(Observer* observer) {}
bool HasObserver(Observer* observer) { return false; }
@@ -120,9 +123,7 @@ class UpdateLibraryStubImpl : public UpdateLibrary {
if (callback)
callback(user_data, "beta-channel");
}
- const UpdateLibrary::Status& status() const {
- return status_;
- }
+ const UpdateLibrary::Status& status() const { return status_; }
private:
Status status_;
@@ -132,10 +133,13 @@ class UpdateLibraryStubImpl : public UpdateLibrary {
// static
UpdateLibrary* UpdateLibrary::GetImpl(bool stub) {
+ UpdateLibrary* impl;
if (stub)
- return new UpdateLibraryStubImpl();
+ impl = new UpdateLibraryStubImpl();
else
- return new UpdateLibraryImpl();
+ impl = new UpdateLibraryImpl();
+ impl->Init();
+ return impl;
}
} // namespace chromeos
« no previous file with comments | « chrome/browser/chromeos/cros/update_library.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698