| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/cros/update_library.h" | 5 #include "chrome/browser/chromeos/cros/update_library.h" |
| 6 | 6 |
| 7 #include "base/message_loop.h" | 7 #include "base/message_loop.h" |
| 8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
| 9 #include "chrome/browser/chromeos/cros/cros_library.h" | 9 #include "chrome/browser/chromeos/cros/cros_library.h" |
| 10 #include "content/browser/browser_thread.h" | 10 #include "content/browser/browser_thread.h" |
| 11 #include "content/common/notification_service.h" | 11 #include "content/common/notification_service.h" |
| 12 #include "content/common/notification_type.h" | 12 #include "content/common/notification_type.h" |
| 13 | 13 |
| 14 namespace chromeos { | 14 namespace chromeos { |
| 15 | 15 |
| 16 class UpdateLibraryImpl : public UpdateLibrary { | 16 class UpdateLibraryImpl : public UpdateLibrary { |
| 17 public: | 17 public: |
| 18 UpdateLibraryImpl() | 18 UpdateLibraryImpl() |
| 19 : status_connection_(NULL) { | 19 : status_connection_(NULL) { |
| 20 if (CrosLibrary::Get()->EnsureLoaded()) { | 20 if (CrosLibrary::Get()->EnsureLoaded()) { |
| 21 Init(); | 21 Init(); |
| 22 } | 22 } |
| 23 } | 23 } |
| 24 | 24 |
| 25 ~UpdateLibraryImpl() { | 25 virtual ~UpdateLibraryImpl() { |
| 26 if (status_connection_) { | 26 if (status_connection_) { |
| 27 DisconnectUpdateProgress(status_connection_); | 27 DisconnectUpdateProgress(status_connection_); |
| 28 } | 28 } |
| 29 } | 29 } |
| 30 | 30 |
| 31 void AddObserver(Observer* observer) { | 31 void AddObserver(Observer* observer) { |
| 32 observers_.AddObserver(observer); | 32 observers_.AddObserver(observer); |
| 33 } | 33 } |
| 34 | 34 |
| 35 void RemoveObserver(Observer* observer) { | 35 void RemoveObserver(Observer* observer) { |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 | 69 |
| 70 private: | 70 private: |
| 71 static void ChangedHandler(void* object, | 71 static void ChangedHandler(void* object, |
| 72 const UpdateProgress& status) { | 72 const UpdateProgress& status) { |
| 73 UpdateLibraryImpl* updater = static_cast<UpdateLibraryImpl*>(object); | 73 UpdateLibraryImpl* updater = static_cast<UpdateLibraryImpl*>(object); |
| 74 updater->UpdateStatus(Status(status)); | 74 updater->UpdateStatus(Status(status)); |
| 75 } | 75 } |
| 76 | 76 |
| 77 void Init() { | 77 void Init() { |
| 78 status_connection_ = MonitorUpdateStatus(&ChangedHandler, this); | 78 status_connection_ = MonitorUpdateStatus(&ChangedHandler, this); |
| 79 // Asynchronously load the initial state. |
| 80 RequestUpdateStatus(&ChangedHandler, this); |
| 79 } | 81 } |
| 80 | 82 |
| 81 void UpdateStatus(const Status& status) { | 83 void UpdateStatus(const Status& status) { |
| 82 // Make sure we run on UI thread. | 84 // Make sure we run on UI thread. |
| 83 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { | 85 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { |
| 84 BrowserThread::PostTask( | 86 BrowserThread::PostTask( |
| 85 BrowserThread::UI, FROM_HERE, | 87 BrowserThread::UI, FROM_HERE, |
| 86 NewRunnableMethod(this, &UpdateLibraryImpl::UpdateStatus, status)); | 88 NewRunnableMethod(this, &UpdateLibraryImpl::UpdateStatus, status)); |
| 87 return; | 89 return; |
| 88 } | 90 } |
| (...skipping 19 matching lines...) Expand all Loading... |
| 108 | 110 |
| 109 // The latest power status. | 111 // The latest power status. |
| 110 Status status_; | 112 Status status_; |
| 111 | 113 |
| 112 DISALLOW_COPY_AND_ASSIGN(UpdateLibraryImpl); | 114 DISALLOW_COPY_AND_ASSIGN(UpdateLibraryImpl); |
| 113 }; | 115 }; |
| 114 | 116 |
| 115 class UpdateLibraryStubImpl : public UpdateLibrary { | 117 class UpdateLibraryStubImpl : public UpdateLibrary { |
| 116 public: | 118 public: |
| 117 UpdateLibraryStubImpl() {} | 119 UpdateLibraryStubImpl() {} |
| 118 ~UpdateLibraryStubImpl() {} | 120 virtual ~UpdateLibraryStubImpl() {} |
| 119 void AddObserver(Observer* observer) {} | 121 void AddObserver(Observer* observer) {} |
| 120 void RemoveObserver(Observer* observer) {} | 122 void RemoveObserver(Observer* observer) {} |
| 121 bool HasObserver(Observer* observer) { return false; } | 123 bool HasObserver(Observer* observer) { return false; } |
| 122 void RequestUpdateCheck(chromeos::UpdateCallback callback, void* user_data) { | 124 void RequestUpdateCheck(chromeos::UpdateCallback callback, void* user_data) { |
| 123 if (callback) | 125 if (callback) |
| 124 callback(user_data, UPDATE_RESULT_FAILED, "stub update"); | 126 callback(user_data, UPDATE_RESULT_FAILED, "stub update"); |
| 125 } | 127 } |
| 126 bool RebootAfterUpdate() { return false; } | 128 bool RebootAfterUpdate() { return false; } |
| 127 void SetReleaseTrack(const std::string& track) { } | 129 void SetReleaseTrack(const std::string& track) { } |
| 128 void GetReleaseTrack(chromeos::UpdateTrackCallback callback, | 130 void GetReleaseTrack(chromeos::UpdateTrackCallback callback, |
| (...skipping 17 matching lines...) Expand all Loading... |
| 146 return new UpdateLibraryStubImpl(); | 148 return new UpdateLibraryStubImpl(); |
| 147 else | 149 else |
| 148 return new UpdateLibraryImpl(); | 150 return new UpdateLibraryImpl(); |
| 149 } | 151 } |
| 150 | 152 |
| 151 } // namespace chromeos | 153 } // namespace chromeos |
| 152 | 154 |
| 153 // Allows InvokeLater without adding refcounting. This class is a Singleton and | 155 // Allows InvokeLater without adding refcounting. This class is a Singleton and |
| 154 // won't be deleted until it's last InvokeLater is run. | 156 // won't be deleted until it's last InvokeLater is run. |
| 155 DISABLE_RUNNABLE_METHOD_REFCOUNT(chromeos::UpdateLibraryImpl); | 157 DISABLE_RUNNABLE_METHOD_REFCOUNT(chromeos::UpdateLibraryImpl); |
| OLD | NEW |