Chromium Code Reviews| 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" |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 155 base::Bind(&UpdateEngineClientImpl::OnGetReleaseTrack, | 155 base::Bind(&UpdateEngineClientImpl::OnGetReleaseTrack, |
| 156 weak_ptr_factory_.GetWeakPtr(), | 156 weak_ptr_factory_.GetWeakPtr(), |
| 157 callback)); | 157 callback)); |
| 158 } | 158 } |
| 159 | 159 |
| 160 // UpdateEngineClient override. | 160 // UpdateEngineClient override. |
| 161 virtual Status GetLastStatus() OVERRIDE { | 161 virtual Status GetLastStatus() OVERRIDE { |
| 162 return last_status_; | 162 return last_status_; |
| 163 } | 163 } |
| 164 | 164 |
| 165 // UpdateEngineClient override. | |
| 166 virtual void SetChannel(const std::string& target_channel, | |
| 167 bool is_powerwash_allowed) OVERRIDE { | |
| 168 dbus::MethodCall method_call( | |
|
Nikita (slow)
2013/06/21 12:21:33
Check somewhere that target_channel value is valid
ygorshenin1
2013/06/21 17:24:58
Done, enum constants will be added in a separate C
| |
| 169 update_engine::kUpdateEngineInterface, | |
| 170 update_engine::kSetChannel); | |
| 171 dbus::MessageWriter writer(&method_call); | |
| 172 writer.AppendString(target_channel); | |
| 173 writer.AppendBool(is_powerwash_allowed); | |
| 174 VLOG(1) << "Requesting to set channel: " | |
| 175 << "target_channel=" << target_channel << ", " | |
| 176 << "is_powerwash_allowed=" << is_powerwash_allowed; | |
| 177 update_engine_proxy_->CallMethod( | |
| 178 &method_call, | |
| 179 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, | |
| 180 base::Bind(&UpdateEngineClientImpl::OnSetChannel, | |
| 181 weak_ptr_factory_.GetWeakPtr())); | |
| 182 } | |
| 183 | |
| 184 // UpdateEngineClient override. | |
| 185 virtual void GetChannel(bool get_current_channel, | |
| 186 const GetChannelCallback& callback) OVERRIDE { | |
| 187 dbus::MethodCall method_call( | |
| 188 update_engine::kUpdateEngineInterface, | |
| 189 update_engine::kGetChannel); | |
| 190 dbus::MessageWriter writer(&method_call); | |
| 191 writer.AppendBool(get_current_channel); | |
| 192 | |
|
Nikita (slow)
2013/06/21 12:21:33
nit: drop empty line
ygorshenin1
2013/06/21 17:24:58
All other methods in this file have an empty line
| |
| 193 VLOG(1) << "Requesting to get channel, get_current_channel=" | |
| 194 << get_current_channel; | |
| 195 update_engine_proxy_->CallMethod( | |
| 196 &method_call, | |
| 197 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, | |
| 198 base::Bind(&UpdateEngineClientImpl::OnGetChannel, | |
| 199 weak_ptr_factory_.GetWeakPtr(), | |
| 200 callback)); | |
| 201 } | |
| 202 | |
| 165 private: | 203 private: |
| 166 void GetUpdateEngineStatus() { | 204 void GetUpdateEngineStatus() { |
| 167 dbus::MethodCall method_call( | 205 dbus::MethodCall method_call( |
| 168 update_engine::kUpdateEngineInterface, | 206 update_engine::kUpdateEngineInterface, |
| 169 update_engine::kGetStatus); | 207 update_engine::kGetStatus); |
| 170 update_engine_proxy_->CallMethodWithErrorCallback( | 208 update_engine_proxy_->CallMethodWithErrorCallback( |
| 171 &method_call, | 209 &method_call, |
| 172 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, | 210 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, |
| 173 base::Bind(&UpdateEngineClientImpl::OnGetStatus, | 211 base::Bind(&UpdateEngineClientImpl::OnGetStatus, |
| 174 weak_ptr_factory_.GetWeakPtr()), | 212 weak_ptr_factory_.GetWeakPtr()), |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 244 status.status = UpdateStatusFromString(current_operation); | 282 status.status = UpdateStatusFromString(current_operation); |
| 245 last_status_ = status; | 283 last_status_ = status; |
| 246 FOR_EACH_OBSERVER(Observer, observers_, UpdateStatusChanged(status)); | 284 FOR_EACH_OBSERVER(Observer, observers_, UpdateStatusChanged(status)); |
| 247 } | 285 } |
| 248 | 286 |
| 249 // Called when GetStatus call failed. | 287 // Called when GetStatus call failed. |
| 250 void OnGetStatusError(dbus::ErrorResponse* error) { | 288 void OnGetStatusError(dbus::ErrorResponse* error) { |
| 251 LOG(ERROR) << "GetStatus request failed with error: " << error->ToString(); | 289 LOG(ERROR) << "GetStatus request failed with error: " << error->ToString(); |
| 252 } | 290 } |
| 253 | 291 |
| 292 // Called when a response for SetReleaseTrack() is received. | |
| 293 void OnSetChannel(dbus::Response* response) { | |
| 294 if (!response) { | |
| 295 LOG(ERROR) << "Failed to request setting channel"; | |
| 296 return; | |
| 297 } | |
| 298 LOG(ERROR) << "Succeeded to set channel"; | |
| 299 } | |
| 300 | |
| 301 // Called when a response for GetChannel() is received. | |
| 302 void OnGetChannel(const GetReleaseTrackCallback& callback, | |
| 303 dbus::Response* response) { | |
| 304 if (!response) { | |
| 305 LOG(ERROR) << "Failed to request getting channel"; | |
| 306 callback.Run(""); | |
| 307 return; | |
| 308 } | |
| 309 dbus::MessageReader reader(response); | |
| 310 std::string channel; | |
| 311 if (!reader.PopString(&channel)) { | |
| 312 LOG(ERROR) << "Incorrect response: " << response->ToString(); | |
| 313 callback.Run(""); | |
| 314 return; | |
| 315 } | |
| 316 VLOG(1) << "The channel received: " << channel; | |
| 317 callback.Run(channel); | |
| 318 } | |
| 319 | |
| 254 // Called when a status update signal is received. | 320 // Called when a status update signal is received. |
| 255 void StatusUpdateReceived(dbus::Signal* signal) { | 321 void StatusUpdateReceived(dbus::Signal* signal) { |
| 256 VLOG(1) << "Status update signal received: " << signal->ToString(); | 322 VLOG(1) << "Status update signal received: " << signal->ToString(); |
| 257 dbus::MessageReader reader(signal); | 323 dbus::MessageReader reader(signal); |
| 258 int64 last_checked_time = 0; | 324 int64 last_checked_time = 0; |
| 259 double progress = 0.0; | 325 double progress = 0.0; |
| 260 std::string current_operation; | 326 std::string current_operation; |
| 261 std::string new_version; | 327 std::string new_version; |
| 262 int64_t new_size = 0; | 328 int64_t new_size = 0; |
| 263 if (!(reader.PopInt64(&last_checked_time) && | 329 if (!(reader.PopInt64(&last_checked_time) && |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 311 const UpdateCheckCallback& callback) OVERRIDE { | 377 const UpdateCheckCallback& callback) OVERRIDE { |
| 312 callback.Run(UPDATE_RESULT_NOTIMPLEMENTED); | 378 callback.Run(UPDATE_RESULT_NOTIMPLEMENTED); |
| 313 } | 379 } |
| 314 virtual void RebootAfterUpdate() OVERRIDE {} | 380 virtual void RebootAfterUpdate() OVERRIDE {} |
| 315 virtual void SetReleaseTrack(const std::string& track) OVERRIDE {} | 381 virtual void SetReleaseTrack(const std::string& track) OVERRIDE {} |
| 316 virtual void GetReleaseTrack( | 382 virtual void GetReleaseTrack( |
| 317 const GetReleaseTrackCallback& callback) OVERRIDE { | 383 const GetReleaseTrackCallback& callback) OVERRIDE { |
| 318 callback.Run("beta-channel"); | 384 callback.Run("beta-channel"); |
| 319 } | 385 } |
| 320 virtual Status GetLastStatus() OVERRIDE { return Status(); } | 386 virtual Status GetLastStatus() OVERRIDE { return Status(); } |
| 387 virtual void SetChannel(const std::string& target_channel, | |
| 388 bool is_powerwash_allowed) OVERRIDE { | |
| 389 LOG(ERROR) << "Requesting to set channel: " | |
|
Nikita (slow)
2013/06/21 12:21:33
LOG(INFO)?
ygorshenin1
2013/06/21 17:24:59
Done.
| |
| 390 << "target_channel=" << target_channel << ", " | |
| 391 << "is_powerwash_allowed=" << is_powerwash_allowed; | |
| 392 } | |
| 393 virtual void GetChannel(bool get_current_channel, | |
| 394 const GetChannelCallback& callback) OVERRIDE { | |
| 395 LOG(ERROR) << "Requesting to get channel, get_current_channel=" | |
|
Nikita (slow)
2013/06/21 12:21:33
LOG(INFO)?
ygorshenin1
2013/06/21 17:24:59
Done.
| |
| 396 << get_current_channel; | |
| 397 callback.Run("beta-channel"); | |
| 398 } | |
| 321 }; | 399 }; |
| 322 | 400 |
| 323 UpdateEngineClient::UpdateEngineClient() { | 401 UpdateEngineClient::UpdateEngineClient() { |
| 324 } | 402 } |
| 325 | 403 |
| 326 UpdateEngineClient::~UpdateEngineClient() { | 404 UpdateEngineClient::~UpdateEngineClient() { |
| 327 } | 405 } |
| 328 | 406 |
| 329 // static | 407 // static |
| 330 UpdateEngineClient::UpdateCheckCallback | 408 UpdateEngineClient::UpdateCheckCallback |
| 331 UpdateEngineClient::EmptyUpdateCheckCallback() { | 409 UpdateEngineClient::EmptyUpdateCheckCallback() { |
| 332 return base::Bind(&EmptyUpdateCheckCallbackBody); | 410 return base::Bind(&EmptyUpdateCheckCallbackBody); |
| 333 } | 411 } |
| 334 | 412 |
| 335 // static | 413 // static |
| 336 UpdateEngineClient* UpdateEngineClient::Create( | 414 UpdateEngineClient* UpdateEngineClient::Create( |
| 337 DBusClientImplementationType type, | 415 DBusClientImplementationType type, |
| 338 dbus::Bus* bus) { | 416 dbus::Bus* bus) { |
| 339 if (type == REAL_DBUS_CLIENT_IMPLEMENTATION) | 417 if (type == REAL_DBUS_CLIENT_IMPLEMENTATION) |
| 340 return new UpdateEngineClientImpl(bus); | 418 return new UpdateEngineClientImpl(bus); |
| 341 DCHECK_EQ(STUB_DBUS_CLIENT_IMPLEMENTATION, type); | 419 DCHECK_EQ(STUB_DBUS_CLIENT_IMPLEMENTATION, type); |
| 342 return new UpdateEngineClientStubImpl(); | 420 return new UpdateEngineClientStubImpl(); |
| 343 } | 421 } |
| 344 | 422 |
| 345 } // namespace chromeos | 423 } // namespace chromeos |
| OLD | NEW |