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/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
10 #include "dbus/bus.h" | 10 #include "dbus/bus.h" |
11 #include "dbus/message.h" | 11 #include "dbus/message.h" |
12 #include "dbus/object_path.h" | 12 #include "dbus/object_path.h" |
13 #include "dbus/object_proxy.h" | 13 #include "dbus/object_proxy.h" |
14 #include "third_party/cros_system_api/dbus/service_constants.h" | 14 #include "third_party/cros_system_api/dbus/service_constants.h" |
15 | 15 |
16 namespace chromeos { | 16 namespace chromeos { |
17 | |
17 namespace { | 18 namespace { |
18 | 19 |
20 const char kReleaseChannelDev[] = "dev-channel"; | |
21 const char kReleaseChannelBeta[] = "beta-channel"; | |
22 const char kReleaseChannelStable[] = "stable-channel"; | |
23 | |
19 // Returns UPDATE_STATUS_ERROR on error. | 24 // Returns UPDATE_STATUS_ERROR on error. |
20 UpdateEngineClient::UpdateStatusOperation UpdateStatusFromString( | 25 UpdateEngineClient::UpdateStatusOperation UpdateStatusFromString( |
21 const std::string& str) { | 26 const std::string& str) { |
22 if (str == "UPDATE_STATUS_IDLE") | 27 if (str == "UPDATE_STATUS_IDLE") |
23 return UpdateEngineClient::UPDATE_STATUS_IDLE; | 28 return UpdateEngineClient::UPDATE_STATUS_IDLE; |
24 if (str == "UPDATE_STATUS_CHECKING_FOR_UPDATE") | 29 if (str == "UPDATE_STATUS_CHECKING_FOR_UPDATE") |
25 return UpdateEngineClient::UPDATE_STATUS_CHECKING_FOR_UPDATE; | 30 return UpdateEngineClient::UPDATE_STATUS_CHECKING_FOR_UPDATE; |
26 if (str == "UPDATE_STATUS_UPDATE_AVAILABLE") | 31 if (str == "UPDATE_STATUS_UPDATE_AVAILABLE") |
27 return UpdateEngineClient::UPDATE_STATUS_UPDATE_AVAILABLE; | 32 return UpdateEngineClient::UPDATE_STATUS_UPDATE_AVAILABLE; |
28 if (str == "UPDATE_STATUS_DOWNLOADING") | 33 if (str == "UPDATE_STATUS_DOWNLOADING") |
29 return UpdateEngineClient::UPDATE_STATUS_DOWNLOADING; | 34 return UpdateEngineClient::UPDATE_STATUS_DOWNLOADING; |
30 if (str == "UPDATE_STATUS_VERIFYING") | 35 if (str == "UPDATE_STATUS_VERIFYING") |
31 return UpdateEngineClient::UPDATE_STATUS_VERIFYING; | 36 return UpdateEngineClient::UPDATE_STATUS_VERIFYING; |
32 if (str == "UPDATE_STATUS_FINALIZING") | 37 if (str == "UPDATE_STATUS_FINALIZING") |
33 return UpdateEngineClient::UPDATE_STATUS_FINALIZING; | 38 return UpdateEngineClient::UPDATE_STATUS_FINALIZING; |
34 if (str == "UPDATE_STATUS_UPDATED_NEED_REBOOT") | 39 if (str == "UPDATE_STATUS_UPDATED_NEED_REBOOT") |
35 return UpdateEngineClient::UPDATE_STATUS_UPDATED_NEED_REBOOT; | 40 return UpdateEngineClient::UPDATE_STATUS_UPDATED_NEED_REBOOT; |
36 if (str == "UPDATE_STATUS_REPORTING_ERROR_EVENT") | 41 if (str == "UPDATE_STATUS_REPORTING_ERROR_EVENT") |
37 return UpdateEngineClient::UPDATE_STATUS_REPORTING_ERROR_EVENT; | 42 return UpdateEngineClient::UPDATE_STATUS_REPORTING_ERROR_EVENT; |
38 return UpdateEngineClient::UPDATE_STATUS_ERROR; | 43 return UpdateEngineClient::UPDATE_STATUS_ERROR; |
39 } | 44 } |
40 | 45 |
41 // Used in UpdateEngineClient::EmptyUpdateCheckCallback(). | 46 // Used in UpdateEngineClient::EmptyUpdateCheckCallback(). |
42 void EmptyUpdateCheckCallbackBody( | 47 void EmptyUpdateCheckCallbackBody( |
43 UpdateEngineClient::UpdateCheckResult unused_result) { | 48 UpdateEngineClient::UpdateCheckResult unused_result) { |
44 } | 49 } |
45 | 50 |
51 bool IsValidChannel(const std::string& channel) { | |
52 return channel == kReleaseChannelDev || | |
53 channel == kReleaseChannelBeta || | |
54 channel == kReleaseChannelStable; | |
55 } | |
56 | |
46 } // namespace | 57 } // namespace |
47 | 58 |
48 // The UpdateEngineClient implementation used in production. | 59 // The UpdateEngineClient implementation used in production. |
49 class UpdateEngineClientImpl : public UpdateEngineClient { | 60 class UpdateEngineClientImpl : public UpdateEngineClient { |
50 public: | 61 public: |
51 explicit UpdateEngineClientImpl(dbus::Bus* bus) | 62 explicit UpdateEngineClientImpl(dbus::Bus* bus) |
52 : update_engine_proxy_(NULL), | 63 : update_engine_proxy_(NULL), |
53 last_status_(), | 64 last_status_(), |
54 weak_ptr_factory_(this) { | 65 weak_ptr_factory_(this) { |
55 update_engine_proxy_ = bus->GetObjectProxy( | 66 update_engine_proxy_ = bus->GetObjectProxy( |
(...skipping 14 matching lines...) Expand all Loading... | |
70 // Get update engine status for the initial status. Update engine won't | 81 // Get update engine status for the initial status. Update engine won't |
71 // send StatusUpdate signal unless there is a status change. If chrome | 82 // send StatusUpdate signal unless there is a status change. If chrome |
72 // crashes after UPDATE_STATUS_UPDATED_NEED_REBOOT status is set, | 83 // crashes after UPDATE_STATUS_UPDATED_NEED_REBOOT status is set, |
73 // restarted chrome would not get this status. See crbug.com/154104. | 84 // restarted chrome would not get this status. See crbug.com/154104. |
74 GetUpdateEngineStatus(); | 85 GetUpdateEngineStatus(); |
75 } | 86 } |
76 | 87 |
77 virtual ~UpdateEngineClientImpl() { | 88 virtual ~UpdateEngineClientImpl() { |
78 } | 89 } |
79 | 90 |
80 // UpdateEngineClient override. | 91 // UpdateEngineClient override. |
James Hawkins
2013/06/25 15:11:58
Here and elsewhere: s/override/implementation/
Th
ygorshenin1
2013/06/25 15:55:22
Done.
| |
81 virtual void AddObserver(Observer* observer) OVERRIDE { | 92 virtual void AddObserver(Observer* observer) OVERRIDE { |
82 observers_.AddObserver(observer); | 93 observers_.AddObserver(observer); |
83 } | 94 } |
84 | 95 |
85 // UpdateEngineClient override. | 96 // UpdateEngineClient override. |
86 virtual void RemoveObserver(Observer* observer) OVERRIDE { | 97 virtual void RemoveObserver(Observer* observer) OVERRIDE { |
87 observers_.RemoveObserver(observer); | 98 observers_.RemoveObserver(observer); |
88 } | 99 } |
89 | 100 |
90 // UpdateEngineClient override. | 101 // UpdateEngineClient override. |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
155 base::Bind(&UpdateEngineClientImpl::OnGetReleaseTrack, | 166 base::Bind(&UpdateEngineClientImpl::OnGetReleaseTrack, |
156 weak_ptr_factory_.GetWeakPtr(), | 167 weak_ptr_factory_.GetWeakPtr(), |
157 callback)); | 168 callback)); |
158 } | 169 } |
159 | 170 |
160 // UpdateEngineClient override. | 171 // UpdateEngineClient override. |
161 virtual Status GetLastStatus() OVERRIDE { | 172 virtual Status GetLastStatus() OVERRIDE { |
162 return last_status_; | 173 return last_status_; |
163 } | 174 } |
164 | 175 |
176 // UpdateEngineClient override. | |
177 virtual void SetChannel(const std::string& target_channel, | |
178 bool is_powerwash_allowed) OVERRIDE { | |
179 if (!IsValidChannel(target_channel)) { | |
180 LOG(ERROR) << "Invalid channel name: " << target_channel; | |
181 return; | |
182 } | |
183 | |
184 dbus::MethodCall method_call( | |
185 update_engine::kUpdateEngineInterface, | |
186 update_engine::kSetChannel); | |
187 dbus::MessageWriter writer(&method_call); | |
188 writer.AppendString(target_channel); | |
189 writer.AppendBool(is_powerwash_allowed); | |
190 | |
191 VLOG(1) << "Requesting to set channel: " | |
192 << "target_channel=" << target_channel << ", " | |
193 << "is_powerwash_allowed=" << is_powerwash_allowed; | |
194 update_engine_proxy_->CallMethod( | |
195 &method_call, | |
196 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, | |
197 base::Bind(&UpdateEngineClientImpl::OnSetChannel, | |
198 weak_ptr_factory_.GetWeakPtr())); | |
199 } | |
200 | |
201 // UpdateEngineClient override. | |
202 virtual void GetChannel(bool get_current_channel, | |
203 const GetChannelCallback& callback) OVERRIDE { | |
204 dbus::MethodCall method_call( | |
205 update_engine::kUpdateEngineInterface, | |
206 update_engine::kGetChannel); | |
207 dbus::MessageWriter writer(&method_call); | |
208 writer.AppendBool(get_current_channel); | |
209 | |
210 VLOG(1) << "Requesting to get channel, get_current_channel=" | |
211 << get_current_channel; | |
212 update_engine_proxy_->CallMethod( | |
213 &method_call, | |
214 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, | |
215 base::Bind(&UpdateEngineClientImpl::OnGetChannel, | |
216 weak_ptr_factory_.GetWeakPtr(), | |
217 callback)); | |
218 } | |
219 | |
165 private: | 220 private: |
166 void GetUpdateEngineStatus() { | 221 void GetUpdateEngineStatus() { |
167 dbus::MethodCall method_call( | 222 dbus::MethodCall method_call( |
168 update_engine::kUpdateEngineInterface, | 223 update_engine::kUpdateEngineInterface, |
169 update_engine::kGetStatus); | 224 update_engine::kGetStatus); |
170 update_engine_proxy_->CallMethodWithErrorCallback( | 225 update_engine_proxy_->CallMethodWithErrorCallback( |
171 &method_call, | 226 &method_call, |
172 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, | 227 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, |
173 base::Bind(&UpdateEngineClientImpl::OnGetStatus, | 228 base::Bind(&UpdateEngineClientImpl::OnGetStatus, |
174 weak_ptr_factory_.GetWeakPtr()), | 229 weak_ptr_factory_.GetWeakPtr()), |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
244 status.status = UpdateStatusFromString(current_operation); | 299 status.status = UpdateStatusFromString(current_operation); |
245 last_status_ = status; | 300 last_status_ = status; |
246 FOR_EACH_OBSERVER(Observer, observers_, UpdateStatusChanged(status)); | 301 FOR_EACH_OBSERVER(Observer, observers_, UpdateStatusChanged(status)); |
247 } | 302 } |
248 | 303 |
249 // Called when GetStatus call failed. | 304 // Called when GetStatus call failed. |
250 void OnGetStatusError(dbus::ErrorResponse* error) { | 305 void OnGetStatusError(dbus::ErrorResponse* error) { |
251 LOG(ERROR) << "GetStatus request failed with error: " << error->ToString(); | 306 LOG(ERROR) << "GetStatus request failed with error: " << error->ToString(); |
252 } | 307 } |
253 | 308 |
309 // Called when a response for SetReleaseTrack() is received. | |
310 void OnSetChannel(dbus::Response* response) { | |
311 if (!response) { | |
312 LOG(ERROR) << "Failed to request setting channel"; | |
313 return; | |
314 } | |
315 VLOG(1) << "Succeeded to set channel"; | |
316 } | |
317 | |
318 // Called when a response for GetChannel() is received. | |
319 void OnGetChannel(const GetReleaseTrackCallback& callback, | |
320 dbus::Response* response) { | |
321 if (!response) { | |
322 LOG(ERROR) << "Failed to request getting channel"; | |
323 callback.Run(""); | |
324 return; | |
325 } | |
326 dbus::MessageReader reader(response); | |
327 std::string channel; | |
328 if (!reader.PopString(&channel)) { | |
329 LOG(ERROR) << "Incorrect response: " << response->ToString(); | |
330 callback.Run(""); | |
331 return; | |
332 } | |
333 VLOG(1) << "The channel received: " << channel; | |
334 callback.Run(channel); | |
335 } | |
336 | |
254 // Called when a status update signal is received. | 337 // Called when a status update signal is received. |
255 void StatusUpdateReceived(dbus::Signal* signal) { | 338 void StatusUpdateReceived(dbus::Signal* signal) { |
256 VLOG(1) << "Status update signal received: " << signal->ToString(); | 339 VLOG(1) << "Status update signal received: " << signal->ToString(); |
257 dbus::MessageReader reader(signal); | 340 dbus::MessageReader reader(signal); |
258 int64 last_checked_time = 0; | 341 int64 last_checked_time = 0; |
259 double progress = 0.0; | 342 double progress = 0.0; |
260 std::string current_operation; | 343 std::string current_operation; |
261 std::string new_version; | 344 std::string new_version; |
262 int64_t new_size = 0; | 345 int64_t new_size = 0; |
263 if (!(reader.PopInt64(&last_checked_time) && | 346 if (!(reader.PopInt64(&last_checked_time) && |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
311 const UpdateCheckCallback& callback) OVERRIDE { | 394 const UpdateCheckCallback& callback) OVERRIDE { |
312 callback.Run(UPDATE_RESULT_NOTIMPLEMENTED); | 395 callback.Run(UPDATE_RESULT_NOTIMPLEMENTED); |
313 } | 396 } |
314 virtual void RebootAfterUpdate() OVERRIDE {} | 397 virtual void RebootAfterUpdate() OVERRIDE {} |
315 virtual void SetReleaseTrack(const std::string& track) OVERRIDE {} | 398 virtual void SetReleaseTrack(const std::string& track) OVERRIDE {} |
316 virtual void GetReleaseTrack( | 399 virtual void GetReleaseTrack( |
317 const GetReleaseTrackCallback& callback) OVERRIDE { | 400 const GetReleaseTrackCallback& callback) OVERRIDE { |
318 callback.Run("beta-channel"); | 401 callback.Run("beta-channel"); |
319 } | 402 } |
320 virtual Status GetLastStatus() OVERRIDE { return Status(); } | 403 virtual Status GetLastStatus() OVERRIDE { return Status(); } |
404 virtual void SetChannel(const std::string& target_channel, | |
405 bool is_powerwash_allowed) OVERRIDE { | |
406 LOG(INFO) << "Requesting to set channel: " | |
407 << "target_channel=" << target_channel << ", " | |
408 << "is_powerwash_allowed=" << is_powerwash_allowed; | |
409 } | |
410 virtual void GetChannel(bool get_current_channel, | |
411 const GetChannelCallback& callback) OVERRIDE { | |
412 LOG(INFO) << "Requesting to get channel, get_current_channel=" | |
413 << get_current_channel; | |
414 callback.Run("beta-channel"); | |
415 } | |
321 }; | 416 }; |
322 | 417 |
323 UpdateEngineClient::UpdateEngineClient() { | 418 UpdateEngineClient::UpdateEngineClient() { |
324 } | 419 } |
325 | 420 |
326 UpdateEngineClient::~UpdateEngineClient() { | 421 UpdateEngineClient::~UpdateEngineClient() { |
327 } | 422 } |
328 | 423 |
329 // static | 424 // static |
330 UpdateEngineClient::UpdateCheckCallback | 425 UpdateEngineClient::UpdateCheckCallback |
331 UpdateEngineClient::EmptyUpdateCheckCallback() { | 426 UpdateEngineClient::EmptyUpdateCheckCallback() { |
332 return base::Bind(&EmptyUpdateCheckCallbackBody); | 427 return base::Bind(&EmptyUpdateCheckCallbackBody); |
333 } | 428 } |
334 | 429 |
335 // static | 430 // static |
336 UpdateEngineClient* UpdateEngineClient::Create( | 431 UpdateEngineClient* UpdateEngineClient::Create( |
337 DBusClientImplementationType type, | 432 DBusClientImplementationType type, |
338 dbus::Bus* bus) { | 433 dbus::Bus* bus) { |
339 if (type == REAL_DBUS_CLIENT_IMPLEMENTATION) | 434 if (type == REAL_DBUS_CLIENT_IMPLEMENTATION) |
340 return new UpdateEngineClientImpl(bus); | 435 return new UpdateEngineClientImpl(bus); |
341 DCHECK_EQ(STUB_DBUS_CLIENT_IMPLEMENTATION, type); | 436 DCHECK_EQ(STUB_DBUS_CLIENT_IMPLEMENTATION, type); |
342 return new UpdateEngineClientStubImpl(); | 437 return new UpdateEngineClientStubImpl(); |
343 } | 438 } |
344 | 439 |
345 } // namespace chromeos | 440 } // namespace chromeos |
OLD | NEW |