OLD | NEW |
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 "chromeos/dbus/update_engine_client.h" | 5 #include "chromeos/dbus/update_engine_client.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/callback.h" | 8 #include "base/callback.h" |
9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
10 #include "dbus/bus.h" | 10 #include "dbus/bus.h" |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 virtual void RemoveObserver(Observer* observer) OVERRIDE { | 80 virtual void RemoveObserver(Observer* observer) OVERRIDE { |
81 observers_.RemoveObserver(observer); | 81 observers_.RemoveObserver(observer); |
82 } | 82 } |
83 | 83 |
84 // UpdateEngineClient override. | 84 // UpdateEngineClient override. |
85 virtual bool HasObserver(Observer* observer) OVERRIDE { | 85 virtual bool HasObserver(Observer* observer) OVERRIDE { |
86 return observers_.HasObserver(observer); | 86 return observers_.HasObserver(observer); |
87 } | 87 } |
88 | 88 |
89 // UpdateEngineClient override. | 89 // UpdateEngineClient override. |
90 virtual void RequestUpdateCheck(UpdateCheckCallback callback) OVERRIDE { | 90 virtual void RequestUpdateCheck( |
| 91 const UpdateCheckCallback& callback) OVERRIDE { |
91 dbus::MethodCall method_call( | 92 dbus::MethodCall method_call( |
92 update_engine::kUpdateEngineInterface, | 93 update_engine::kUpdateEngineInterface, |
93 update_engine::kAttemptUpdate); | 94 update_engine::kAttemptUpdate); |
94 dbus::MessageWriter writer(&method_call); | 95 dbus::MessageWriter writer(&method_call); |
95 writer.AppendString(""); // Unused. | 96 writer.AppendString(""); // Unused. |
96 writer.AppendString(""); // Unused. | 97 writer.AppendString(""); // Unused. |
97 | 98 |
98 VLOG(1) << "Requesting an update check"; | 99 VLOG(1) << "Requesting an update check"; |
99 update_engine_proxy_->CallMethod( | 100 update_engine_proxy_->CallMethod( |
100 &method_call, | 101 &method_call, |
(...skipping 27 matching lines...) Expand all Loading... |
128 | 129 |
129 VLOG(1) << "Requesting to set the release track to " << track; | 130 VLOG(1) << "Requesting to set the release track to " << track; |
130 update_engine_proxy_->CallMethod( | 131 update_engine_proxy_->CallMethod( |
131 &method_call, | 132 &method_call, |
132 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, | 133 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, |
133 base::Bind(&UpdateEngineClientImpl::OnSetReleaseTrack, | 134 base::Bind(&UpdateEngineClientImpl::OnSetReleaseTrack, |
134 weak_ptr_factory_.GetWeakPtr())); | 135 weak_ptr_factory_.GetWeakPtr())); |
135 } | 136 } |
136 | 137 |
137 // UpdateEngineClient override. | 138 // UpdateEngineClient override. |
138 virtual void GetReleaseTrack(GetReleaseTrackCallback callback) OVERRIDE { | 139 virtual void GetReleaseTrack( |
| 140 const GetReleaseTrackCallback& callback) OVERRIDE { |
139 dbus::MethodCall method_call( | 141 dbus::MethodCall method_call( |
140 update_engine::kUpdateEngineInterface, | 142 update_engine::kUpdateEngineInterface, |
141 update_engine::kGetTrack); | 143 update_engine::kGetTrack); |
142 | 144 |
143 VLOG(1) << "Requesting to get the current release track"; | 145 VLOG(1) << "Requesting to get the current release track"; |
144 update_engine_proxy_->CallMethod( | 146 update_engine_proxy_->CallMethod( |
145 &method_call, | 147 &method_call, |
146 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, | 148 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, |
147 base::Bind(&UpdateEngineClientImpl::OnGetReleaseTrack, | 149 base::Bind(&UpdateEngineClientImpl::OnGetReleaseTrack, |
148 weak_ptr_factory_.GetWeakPtr(), | 150 weak_ptr_factory_.GetWeakPtr(), |
149 callback)); | 151 callback)); |
150 } | 152 } |
151 | 153 |
152 // UpdateEngineClient override. | 154 // UpdateEngineClient override. |
153 virtual Status GetLastStatus() OVERRIDE { | 155 virtual Status GetLastStatus() OVERRIDE { |
154 return last_status_; | 156 return last_status_; |
155 } | 157 } |
156 | 158 |
157 private: | 159 private: |
158 // Called when a response for RequestUpdateCheck() is received. | 160 // Called when a response for RequestUpdateCheck() is received. |
159 void OnRequestUpdateCheck(UpdateCheckCallback callback, | 161 void OnRequestUpdateCheck(const UpdateCheckCallback& callback, |
160 dbus::Response* response) { | 162 dbus::Response* response) { |
161 if (!response) { | 163 if (!response) { |
162 LOG(ERROR) << "Failed to request update check"; | 164 LOG(ERROR) << "Failed to request update check"; |
163 callback.Run(UPDATE_RESULT_FAILED); | 165 callback.Run(UPDATE_RESULT_FAILED); |
164 return; | 166 return; |
165 } | 167 } |
166 callback.Run(UPDATE_RESULT_SUCCESS); | 168 callback.Run(UPDATE_RESULT_SUCCESS); |
167 } | 169 } |
168 | 170 |
169 // Called when a response for RebootAfterUpdate() is received. | 171 // Called when a response for RebootAfterUpdate() is received. |
170 void OnRebootAfterUpdate(dbus::Response* response) { | 172 void OnRebootAfterUpdate(dbus::Response* response) { |
171 if (!response) { | 173 if (!response) { |
172 LOG(ERROR) << "Failed to request rebooting after update"; | 174 LOG(ERROR) << "Failed to request rebooting after update"; |
173 return; | 175 return; |
174 } | 176 } |
175 } | 177 } |
176 | 178 |
177 // Called when a response for SetReleaseTrack() is received. | 179 // Called when a response for SetReleaseTrack() is received. |
178 void OnSetReleaseTrack(dbus::Response* response) { | 180 void OnSetReleaseTrack(dbus::Response* response) { |
179 if (!response) { | 181 if (!response) { |
180 LOG(ERROR) << "Failed to request setting release track"; | 182 LOG(ERROR) << "Failed to request setting release track"; |
181 return; | 183 return; |
182 } | 184 } |
183 } | 185 } |
184 | 186 |
185 // Called when a response for GetReleaseTrack() is received. | 187 // Called when a response for GetReleaseTrack() is received. |
186 void OnGetReleaseTrack(GetReleaseTrackCallback callback, | 188 void OnGetReleaseTrack(const GetReleaseTrackCallback& callback, |
187 dbus::Response* response) { | 189 dbus::Response* response) { |
188 if (!response) { | 190 if (!response) { |
189 LOG(ERROR) << "Failed to request getting release track"; | 191 LOG(ERROR) << "Failed to request getting release track"; |
190 callback.Run(""); | 192 callback.Run(""); |
191 return; | 193 return; |
192 } | 194 } |
193 dbus::MessageReader reader(response); | 195 dbus::MessageReader reader(response); |
194 std::string release_track; | 196 std::string release_track; |
195 if (!reader.PopString(&release_track)) { | 197 if (!reader.PopString(&release_track)) { |
196 LOG(ERROR) << "Incorrect response: " << response->ToString(); | 198 LOG(ERROR) << "Incorrect response: " << response->ToString(); |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
247 }; | 249 }; |
248 | 250 |
249 // The UpdateEngineClient implementation used on Linux desktop, | 251 // The UpdateEngineClient implementation used on Linux desktop, |
250 // which does nothing. | 252 // which does nothing. |
251 class UpdateEngineClientStubImpl : public UpdateEngineClient { | 253 class UpdateEngineClientStubImpl : public UpdateEngineClient { |
252 // UpdateEngineClient overrides. | 254 // UpdateEngineClient overrides. |
253 virtual void AddObserver(Observer* observer) OVERRIDE {} | 255 virtual void AddObserver(Observer* observer) OVERRIDE {} |
254 virtual void RemoveObserver(Observer* observer) OVERRIDE {} | 256 virtual void RemoveObserver(Observer* observer) OVERRIDE {} |
255 virtual bool HasObserver(Observer* observer) OVERRIDE { return false; } | 257 virtual bool HasObserver(Observer* observer) OVERRIDE { return false; } |
256 | 258 |
257 virtual void RequestUpdateCheck(UpdateCheckCallback callback) OVERRIDE { | 259 virtual void RequestUpdateCheck( |
| 260 const UpdateCheckCallback& callback) OVERRIDE { |
258 callback.Run(UPDATE_RESULT_NOTIMPLEMENTED); | 261 callback.Run(UPDATE_RESULT_NOTIMPLEMENTED); |
259 } | 262 } |
260 virtual void RebootAfterUpdate() OVERRIDE {} | 263 virtual void RebootAfterUpdate() OVERRIDE {} |
261 virtual void SetReleaseTrack(const std::string& track) OVERRIDE {} | 264 virtual void SetReleaseTrack(const std::string& track) OVERRIDE {} |
262 virtual void GetReleaseTrack(GetReleaseTrackCallback callback) OVERRIDE { | 265 virtual void GetReleaseTrack( |
| 266 const GetReleaseTrackCallback& callback) OVERRIDE { |
263 callback.Run("beta-channel"); | 267 callback.Run("beta-channel"); |
264 } | 268 } |
265 virtual Status GetLastStatus() OVERRIDE { return Status(); } | 269 virtual Status GetLastStatus() OVERRIDE { return Status(); } |
266 }; | 270 }; |
267 | 271 |
268 UpdateEngineClient::UpdateEngineClient() { | 272 UpdateEngineClient::UpdateEngineClient() { |
269 } | 273 } |
270 | 274 |
271 UpdateEngineClient::~UpdateEngineClient() { | 275 UpdateEngineClient::~UpdateEngineClient() { |
272 } | 276 } |
273 | 277 |
274 // static | 278 // static |
275 UpdateEngineClient::UpdateCheckCallback | 279 UpdateEngineClient::UpdateCheckCallback |
276 UpdateEngineClient::EmptyUpdateCheckCallback() { | 280 UpdateEngineClient::EmptyUpdateCheckCallback() { |
277 return base::Bind(&EmptyUpdateCheckCallbackBody); | 281 return base::Bind(&EmptyUpdateCheckCallbackBody); |
278 } | 282 } |
279 | 283 |
280 // static | 284 // static |
281 UpdateEngineClient* UpdateEngineClient::Create( | 285 UpdateEngineClient* UpdateEngineClient::Create( |
282 DBusClientImplementationType type, | 286 DBusClientImplementationType type, |
283 dbus::Bus* bus) { | 287 dbus::Bus* bus) { |
284 if (type == REAL_DBUS_CLIENT_IMPLEMENTATION) | 288 if (type == REAL_DBUS_CLIENT_IMPLEMENTATION) |
285 return new UpdateEngineClientImpl(bus); | 289 return new UpdateEngineClientImpl(bus); |
286 DCHECK_EQ(STUB_DBUS_CLIENT_IMPLEMENTATION, type); | 290 DCHECK_EQ(STUB_DBUS_CLIENT_IMPLEMENTATION, type); |
287 return new UpdateEngineClientStubImpl(); | 291 return new UpdateEngineClientStubImpl(); |
288 } | 292 } |
289 | 293 |
290 } // namespace chromeos | 294 } // namespace chromeos |
OLD | NEW |