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/basictypes.h" | |
7 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
8 #include "base/string_util.h" | 9 #include "base/observer_list.h" |
9 #include "chrome/browser/chromeos/cros/cros_library.h" | 10 #include "chrome/browser/chromeos/cros/cros_library.h" |
10 #include "content/browser/browser_thread.h" | 11 #include "content/browser/browser_thread.h" |
11 | 12 |
12 namespace chromeos { | 13 namespace chromeos { |
13 | 14 |
14 class UpdateLibraryImpl : public UpdateLibrary { | 15 class UpdateLibraryImpl : public UpdateLibrary { |
15 public: | 16 public: |
16 UpdateLibraryImpl() | 17 UpdateLibraryImpl() : status_connection_(NULL) { |
17 : status_connection_(NULL) { | 18 if (CrosLibrary::Get()->EnsureLoaded()) |
18 if (CrosLibrary::Get()->EnsureLoaded()) { | |
19 Init(); | 19 Init(); |
stevenjb
2011/08/05 00:01:42
We should make Init() virtual for this class also
tfarina
2011/08/05 00:03:53
Sure, I'll do. It was in my TODO list. I was plann
| |
20 } | |
21 } | 20 } |
22 | 21 |
23 virtual ~UpdateLibraryImpl() { | 22 virtual ~UpdateLibraryImpl() { |
24 if (status_connection_) { | 23 if (status_connection_) { |
25 DisconnectUpdateProgress(status_connection_); | 24 chromeos::DisconnectUpdateProgress(status_connection_); |
25 status_connection_ = NULL; | |
26 } | 26 } |
27 } | 27 } |
28 | 28 |
29 void AddObserver(Observer* observer) { | 29 void AddObserver(Observer* observer) { |
30 observers_.AddObserver(observer); | 30 observers_.AddObserver(observer); |
31 } | 31 } |
32 | 32 |
33 void RemoveObserver(Observer* observer) { | 33 void RemoveObserver(Observer* observer) { |
34 observers_.RemoveObserver(observer); | 34 observers_.RemoveObserver(observer); |
35 } | 35 } |
(...skipping 23 matching lines...) Expand all Loading... | |
59 void* user_data) { | 59 void* user_data) { |
60 if (CrosLibrary::Get()->EnsureLoaded()) | 60 if (CrosLibrary::Get()->EnsureLoaded()) |
61 chromeos::RequestUpdateTrack(callback, user_data); | 61 chromeos::RequestUpdateTrack(callback, user_data); |
62 } | 62 } |
63 | 63 |
64 const UpdateLibrary::Status& status() const { | 64 const UpdateLibrary::Status& status() const { |
65 return status_; | 65 return status_; |
66 } | 66 } |
67 | 67 |
68 private: | 68 private: |
69 static void ChangedHandler(void* object, | 69 static void ChangedHandler(void* object, const UpdateProgress& status) { |
70 const UpdateProgress& status) { | 70 UpdateLibraryImpl* impl = static_cast<UpdateLibraryImpl*>(object); |
71 UpdateLibraryImpl* updater = static_cast<UpdateLibraryImpl*>(object); | 71 impl->UpdateStatus(Status(status)); |
72 updater->UpdateStatus(Status(status)); | |
73 } | 72 } |
74 | 73 |
75 void Init() { | 74 void Init() { |
76 status_connection_ = MonitorUpdateStatus(&ChangedHandler, this); | 75 status_connection_ = chromeos::MonitorUpdateStatus(&ChangedHandler, this); |
77 // Asynchronously load the initial state. | 76 // Asynchronously load the initial state. |
78 RequestUpdateStatus(&ChangedHandler, this); | 77 RequestUpdateStatus(&ChangedHandler, this); |
79 } | 78 } |
80 | 79 |
81 void UpdateStatus(const Status& status) { | 80 void UpdateStatus(const Status& status) { |
82 // Make sure we run on UI thread. | 81 // Make sure we run on UI thread. |
83 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { | 82 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { |
84 BrowserThread::PostTask( | 83 BrowserThread::PostTask( |
85 BrowserThread::UI, FROM_HERE, | 84 BrowserThread::UI, FROM_HERE, |
86 NewRunnableMethod(this, &UpdateLibraryImpl::UpdateStatus, status)); | 85 NewRunnableMethod(this, &UpdateLibraryImpl::UpdateStatus, status)); |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
137 return new UpdateLibraryStubImpl(); | 136 return new UpdateLibraryStubImpl(); |
138 else | 137 else |
139 return new UpdateLibraryImpl(); | 138 return new UpdateLibraryImpl(); |
140 } | 139 } |
141 | 140 |
142 } // namespace chromeos | 141 } // namespace chromeos |
143 | 142 |
144 // Allows InvokeLater without adding refcounting. This class is a Singleton and | 143 // Allows InvokeLater without adding refcounting. This class is a Singleton and |
145 // won't be deleted until it's last InvokeLater is run. | 144 // won't be deleted until it's last InvokeLater is run. |
146 DISABLE_RUNNABLE_METHOD_REFCOUNT(chromeos::UpdateLibraryImpl); | 145 DISABLE_RUNNABLE_METHOD_REFCOUNT(chromeos::UpdateLibraryImpl); |
OLD | NEW |