summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorstevenjb@google.com <stevenjb@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2011-03-16 22:43:22 +0000
committerstevenjb@google.com <stevenjb@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2011-03-16 22:43:22 +0000
commit9b591247b018f7413a7cb96db13ab3fb071e6c5d (patch)
tree86b109c8f86b45b92fdb324360c6f5966e705fff
parent32e13a4845ed1a14a2e169128fd3414fd20d8a6a (diff)
downloadchromium_src-9b591247b018f7413a7cb96db13ab3fb071e6c5d.zip
chromium_src-9b591247b018f7413a7cb96db13ab3fb071e6c5d.tar.gz
chromium_src-9b591247b018f7413a7cb96db13ab3fb071e6c5d.tar.bz2
Changes to use async RequestUpdateTrack and SetUpdateTrack in UpdateLibrary.
See http://codereview.chromium.org/6673061/ for libcros changes Nore: requires updating cros.DEPS before pushing this. BUG=chromium-os:13089 TEST=See issue. Review URL: http://codereview.chromium.org/6694051 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@78452 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/chromeos/cros/mock_update_library.h5
-rw-r--r--chrome/browser/chromeos/cros/update_library.cc30
-rw-r--r--chrome/browser/chromeos/cros/update_library.h10
-rw-r--r--chrome/browser/ui/webui/options/about_page_handler.cc34
-rw-r--r--chrome/browser/ui/webui/options/about_page_handler.h3
5 files changed, 57 insertions, 25 deletions
diff --git a/chrome/browser/chromeos/cros/mock_update_library.h b/chrome/browser/chromeos/cros/mock_update_library.h
index 35af433..8abace9 100644
--- a/chrome/browser/chromeos/cros/mock_update_library.h
+++ b/chrome/browser/chromeos/cros/mock_update_library.h
@@ -18,10 +18,11 @@ class MockUpdateLibrary : public UpdateLibrary {
virtual ~MockUpdateLibrary() {}
MOCK_METHOD1(AddObserver, void(Observer*)); // NOLINT
MOCK_METHOD1(RemoveObserver, void(Observer*)); // NOLINT
+ MOCK_METHOD1(HasObserver, bool(Observer*));
MOCK_METHOD2(RequestUpdateCheck, void(chromeos::UpdateCallback, void*));
MOCK_METHOD0(RebootAfterUpdate, bool(void));
- MOCK_METHOD1(SetReleaseTrack, bool(const std::string&));
- MOCK_METHOD0(GetReleaseTrack, std::string());
+ MOCK_METHOD1(SetReleaseTrack, void(const std::string&));
+ MOCK_METHOD2(GetReleaseTrack, void(chromeos::UpdateTrackCallback, void*));
MOCK_CONST_METHOD0(status, const Status&(void));
private:
diff --git a/chrome/browser/chromeos/cros/update_library.cc b/chrome/browser/chromeos/cros/update_library.cc
index 44c7d76..d4d48caf 100644
--- a/chrome/browser/chromeos/cros/update_library.cc
+++ b/chrome/browser/chromeos/cros/update_library.cc
@@ -36,6 +36,10 @@ class UpdateLibraryImpl : public UpdateLibrary {
observers_.RemoveObserver(observer);
}
+ bool HasObserver(Observer* observer) {
+ return observers_.HasObserver(observer);
+ }
+
void RequestUpdateCheck(chromeos::UpdateCallback callback, void* user_data) {
if (CrosLibrary::Get()->EnsureLoaded())
chromeos::RequestUpdateCheck(callback, user_data);
@@ -48,18 +52,15 @@ class UpdateLibraryImpl : public UpdateLibrary {
return RebootIfUpdated();
}
- bool SetReleaseTrack(const std::string& track) {
- if (!CrosLibrary::Get()->EnsureLoaded())
- return false;
-
- return chromeos::SetTrack(track);
+ void SetReleaseTrack(const std::string& track) {
+ if (CrosLibrary::Get()->EnsureLoaded())
+ chromeos::SetUpdateTrack(track);
}
- std::string GetReleaseTrack() {
- if (!CrosLibrary::Get()->EnsureLoaded())
- return "";
-
- return chromeos::GetTrack();
+ void GetReleaseTrack(chromeos::UpdateTrackCallback callback,
+ void* user_data) {
+ if (CrosLibrary::Get()->EnsureLoaded())
+ chromeos::RequestUpdateTrack(callback, user_data);
}
const UpdateLibrary::Status& status() const {
@@ -117,13 +118,18 @@ class UpdateLibraryStubImpl : public UpdateLibrary {
~UpdateLibraryStubImpl() {}
void AddObserver(Observer* observer) {}
void RemoveObserver(Observer* observer) {}
+ bool HasObserver(Observer* observer) { return false; }
void RequestUpdateCheck(chromeos::UpdateCallback callback, void* user_data) {
if (callback)
callback(user_data, UPDATE_RESULT_FAILED, "stub update");
}
bool RebootAfterUpdate() { return false; }
- bool SetReleaseTrack(const std::string& track) { return false; }
- std::string GetReleaseTrack() { return "beta-channel"; }
+ void SetReleaseTrack(const std::string& track) { }
+ void GetReleaseTrack(chromeos::UpdateTrackCallback callback,
+ void* user_data) {
+ if (callback)
+ callback(user_data, "beta-channel");
+ }
const UpdateLibrary::Status& status() const {
return status_;
}
diff --git a/chrome/browser/chromeos/cros/update_library.h b/chrome/browser/chromeos/cros/update_library.h
index 8fe31cf..cf90722 100644
--- a/chrome/browser/chromeos/cros/update_library.h
+++ b/chrome/browser/chromeos/cros/update_library.h
@@ -61,6 +61,7 @@ class UpdateLibrary {
virtual ~UpdateLibrary() {}
virtual void AddObserver(Observer* observer) = 0;
virtual void RemoveObserver(Observer* observer) = 0;
+ virtual bool HasObserver(Observer* observer) = 0;
// Requests an update check and calls |callback| when completed.
virtual void RequestUpdateCheck(chromeos::UpdateCallback callback,
@@ -71,11 +72,12 @@ class UpdateLibrary {
// Sets the release track (channel). |track| should look like
// "beta-channel" and "dev-channel". Returns true on success.
- virtual bool SetReleaseTrack(const std::string& track) = 0;
+ virtual void SetReleaseTrack(const std::string& track) = 0;
- // Returns the release track (channel). On error, returns an empty
- // string.
- virtual std::string GetReleaseTrack() = 0;
+ // Calls |callback| with the release track (channel). On error, calls
+ // |callback| with NULL.
+ virtual void GetReleaseTrack(chromeos::UpdateTrackCallback callback,
+ void* user_data) = 0;
virtual const Status& status() const = 0;
diff --git a/chrome/browser/ui/webui/options/about_page_handler.cc b/chrome/browser/ui/webui/options/about_page_handler.cc
index c6c8fca..3326706 100644
--- a/chrome/browser/ui/webui/options/about_page_handler.cc
+++ b/chrome/browser/ui/webui/options/about_page_handler.cc
@@ -72,6 +72,8 @@ class AboutPageHandler::UpdateObserver
explicit UpdateObserver(AboutPageHandler* handler) : page_handler_(handler) {}
virtual ~UpdateObserver() {}
+ AboutPageHandler* page_handler() const { return page_handler_; }
+
private:
virtual void UpdateStatusChanged(chromeos::UpdateLibrary* object) {
page_handler_->UpdateStatus(object->status());
@@ -277,12 +279,6 @@ void AboutPageHandler::PageReady(const ListValue* args) {
chromeos::UpdateLibrary* update_library =
chromeos::CrosLibrary::Get()->GetUpdateLibrary();
- // Update the channel information.
- std::string channel = update_library->GetReleaseTrack();
- scoped_ptr<Value> channel_string(Value::CreateStringValue(channel));
- web_ui_->CallJavascriptFunction("AboutPage.updateSelectedOptionCallback",
- *channel_string);
-
update_observer_.reset(new UpdateObserver(this));
update_library->AddObserver(update_observer_.get());
@@ -294,6 +290,11 @@ void AboutPageHandler::PageReady(const ListValue* args) {
// already complete, update_observer_ won't receive a notification.
// This is why we manually update the WebUI page above.
CheckNow(NULL);
+
+ // Request the channel information. Use the observer to track the about
+ // page handler and ensure it does not get deleted before the callback.
+ update_library->GetReleaseTrack(UpdateSelectedChannel,
+ update_observer_.get());
#endif
}
@@ -417,4 +418,23 @@ void AboutPageHandler::OnOSVersion(chromeos::VersionLoader::Handle handle,
*version_string);
}
}
-#endif
+
+// Callback from UpdateEngine with channel information.
+// static
+void AboutPageHandler::UpdateSelectedChannel(void* user_data,
+ const char* channel) {
+ if (!user_data || !channel) {
+ LOG(WARNING) << "UpdateSelectedChannel returned NULL.";
+ return;
+ }
+ UpdateObserver* observer = static_cast<UpdateObserver*>(user_data);
+ if (chromeos::CrosLibrary::Get()->GetUpdateLibrary()->HasObserver(observer)) {
+ // If UpdateLibrary still has the observer, then the page handler is valid.
+ AboutPageHandler* handler = observer->page_handler();
+ scoped_ptr<Value> channel_string(Value::CreateStringValue(channel));
+ handler->web_ui_->CallJavascriptFunction(
+ "AboutPage.updateSelectedOptionCallback", *channel_string);
+ }
+}
+
+#endif // defined(OS_CHROMEOS)
diff --git a/chrome/browser/ui/webui/options/about_page_handler.h b/chrome/browser/ui/webui/options/about_page_handler.h
index 7199fd1..45400d3 100644
--- a/chrome/browser/ui/webui/options/about_page_handler.h
+++ b/chrome/browser/ui/webui/options/about_page_handler.h
@@ -44,6 +44,9 @@ class AboutPageHandler : public OptionsPageUIHandler {
std::string version);
void UpdateStatus(const chromeos::UpdateLibrary::Status& status);
+ // UpdateEngine Callback handler.
+ static void UpdateSelectedChannel(void* user_data, const char* channel);
+
// Handles asynchronously loading the version.
chromeos::VersionLoader loader_;