| 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/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 // The UpdateEngineClient implementation used in production. | 76 // The UpdateEngineClient implementation used in production. |
| 77 class UpdateEngineClientImpl : public UpdateEngineClient { | 77 class UpdateEngineClientImpl : public UpdateEngineClient { |
| 78 public: | 78 public: |
| 79 UpdateEngineClientImpl() | 79 UpdateEngineClientImpl() |
| 80 : update_engine_proxy_(NULL), last_status_(), weak_ptr_factory_(this) {} | 80 : update_engine_proxy_(NULL), last_status_(), weak_ptr_factory_(this) {} |
| 81 | 81 |
| 82 virtual ~UpdateEngineClientImpl() { | 82 virtual ~UpdateEngineClientImpl() { |
| 83 } | 83 } |
| 84 | 84 |
| 85 // UpdateEngineClient implementation: | 85 // UpdateEngineClient implementation: |
| 86 virtual void AddObserver(Observer* observer) OVERRIDE { | 86 virtual void AddObserver(Observer* observer) override { |
| 87 observers_.AddObserver(observer); | 87 observers_.AddObserver(observer); |
| 88 } | 88 } |
| 89 | 89 |
| 90 virtual void RemoveObserver(Observer* observer) OVERRIDE { | 90 virtual void RemoveObserver(Observer* observer) override { |
| 91 observers_.RemoveObserver(observer); | 91 observers_.RemoveObserver(observer); |
| 92 } | 92 } |
| 93 | 93 |
| 94 virtual bool HasObserver(Observer* observer) OVERRIDE { | 94 virtual bool HasObserver(Observer* observer) override { |
| 95 return observers_.HasObserver(observer); | 95 return observers_.HasObserver(observer); |
| 96 } | 96 } |
| 97 | 97 |
| 98 virtual void RequestUpdateCheck( | 98 virtual void RequestUpdateCheck( |
| 99 const UpdateCheckCallback& callback) OVERRIDE { | 99 const UpdateCheckCallback& callback) override { |
| 100 dbus::MethodCall method_call( | 100 dbus::MethodCall method_call( |
| 101 update_engine::kUpdateEngineInterface, | 101 update_engine::kUpdateEngineInterface, |
| 102 update_engine::kAttemptUpdate); | 102 update_engine::kAttemptUpdate); |
| 103 dbus::MessageWriter writer(&method_call); | 103 dbus::MessageWriter writer(&method_call); |
| 104 writer.AppendString(""); // Unused. | 104 writer.AppendString(""); // Unused. |
| 105 writer.AppendString(""); // Unused. | 105 writer.AppendString(""); // Unused. |
| 106 | 106 |
| 107 VLOG(1) << "Requesting an update check"; | 107 VLOG(1) << "Requesting an update check"; |
| 108 update_engine_proxy_->CallMethod( | 108 update_engine_proxy_->CallMethod( |
| 109 &method_call, | 109 &method_call, |
| 110 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, | 110 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, |
| 111 base::Bind(&UpdateEngineClientImpl::OnRequestUpdateCheck, | 111 base::Bind(&UpdateEngineClientImpl::OnRequestUpdateCheck, |
| 112 weak_ptr_factory_.GetWeakPtr(), | 112 weak_ptr_factory_.GetWeakPtr(), |
| 113 callback)); | 113 callback)); |
| 114 } | 114 } |
| 115 | 115 |
| 116 virtual void RebootAfterUpdate() OVERRIDE { | 116 virtual void RebootAfterUpdate() override { |
| 117 dbus::MethodCall method_call( | 117 dbus::MethodCall method_call( |
| 118 update_engine::kUpdateEngineInterface, | 118 update_engine::kUpdateEngineInterface, |
| 119 update_engine::kRebootIfNeeded); | 119 update_engine::kRebootIfNeeded); |
| 120 | 120 |
| 121 VLOG(1) << "Requesting a reboot"; | 121 VLOG(1) << "Requesting a reboot"; |
| 122 update_engine_proxy_->CallMethod( | 122 update_engine_proxy_->CallMethod( |
| 123 &method_call, | 123 &method_call, |
| 124 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, | 124 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, |
| 125 base::Bind(&UpdateEngineClientImpl::OnRebootAfterUpdate, | 125 base::Bind(&UpdateEngineClientImpl::OnRebootAfterUpdate, |
| 126 weak_ptr_factory_.GetWeakPtr())); | 126 weak_ptr_factory_.GetWeakPtr())); |
| 127 } | 127 } |
| 128 | 128 |
| 129 virtual void Rollback() OVERRIDE { | 129 virtual void Rollback() override { |
| 130 VLOG(1) << "Requesting a rollback"; | 130 VLOG(1) << "Requesting a rollback"; |
| 131 dbus::MethodCall method_call( | 131 dbus::MethodCall method_call( |
| 132 update_engine::kUpdateEngineInterface, | 132 update_engine::kUpdateEngineInterface, |
| 133 update_engine::kAttemptRollback); | 133 update_engine::kAttemptRollback); |
| 134 dbus::MessageWriter writer(&method_call); | 134 dbus::MessageWriter writer(&method_call); |
| 135 writer.AppendBool(true /* powerwash */); | 135 writer.AppendBool(true /* powerwash */); |
| 136 | 136 |
| 137 update_engine_proxy_->CallMethod( | 137 update_engine_proxy_->CallMethod( |
| 138 &method_call, | 138 &method_call, |
| 139 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, | 139 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, |
| 140 base::Bind(&UpdateEngineClientImpl::OnRollback, | 140 base::Bind(&UpdateEngineClientImpl::OnRollback, |
| 141 weak_ptr_factory_.GetWeakPtr())); | 141 weak_ptr_factory_.GetWeakPtr())); |
| 142 } | 142 } |
| 143 | 143 |
| 144 | 144 |
| 145 virtual void CanRollbackCheck( | 145 virtual void CanRollbackCheck( |
| 146 const RollbackCheckCallback& callback) OVERRIDE { | 146 const RollbackCheckCallback& callback) override { |
| 147 dbus::MethodCall method_call( | 147 dbus::MethodCall method_call( |
| 148 update_engine::kUpdateEngineInterface, | 148 update_engine::kUpdateEngineInterface, |
| 149 update_engine::kCanRollback); | 149 update_engine::kCanRollback); |
| 150 | 150 |
| 151 VLOG(1) << "Requesting to get rollback availability status"; | 151 VLOG(1) << "Requesting to get rollback availability status"; |
| 152 update_engine_proxy_->CallMethod( | 152 update_engine_proxy_->CallMethod( |
| 153 &method_call, | 153 &method_call, |
| 154 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, | 154 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, |
| 155 base::Bind(&UpdateEngineClientImpl::OnCanRollbackCheck, | 155 base::Bind(&UpdateEngineClientImpl::OnCanRollbackCheck, |
| 156 weak_ptr_factory_.GetWeakPtr(), | 156 weak_ptr_factory_.GetWeakPtr(), |
| 157 callback)); | 157 callback)); |
| 158 } | 158 } |
| 159 | 159 |
| 160 virtual Status GetLastStatus() OVERRIDE { | 160 virtual Status GetLastStatus() override { |
| 161 return last_status_; | 161 return last_status_; |
| 162 } | 162 } |
| 163 | 163 |
| 164 virtual void SetChannel(const std::string& target_channel, | 164 virtual void SetChannel(const std::string& target_channel, |
| 165 bool is_powerwash_allowed) OVERRIDE { | 165 bool is_powerwash_allowed) override { |
| 166 if (!IsValidChannel(target_channel)) { | 166 if (!IsValidChannel(target_channel)) { |
| 167 LOG(ERROR) << "Invalid channel name: " << target_channel; | 167 LOG(ERROR) << "Invalid channel name: " << target_channel; |
| 168 return; | 168 return; |
| 169 } | 169 } |
| 170 | 170 |
| 171 dbus::MethodCall method_call( | 171 dbus::MethodCall method_call( |
| 172 update_engine::kUpdateEngineInterface, | 172 update_engine::kUpdateEngineInterface, |
| 173 update_engine::kSetChannel); | 173 update_engine::kSetChannel); |
| 174 dbus::MessageWriter writer(&method_call); | 174 dbus::MessageWriter writer(&method_call); |
| 175 writer.AppendString(target_channel); | 175 writer.AppendString(target_channel); |
| 176 writer.AppendBool(is_powerwash_allowed); | 176 writer.AppendBool(is_powerwash_allowed); |
| 177 | 177 |
| 178 VLOG(1) << "Requesting to set channel: " | 178 VLOG(1) << "Requesting to set channel: " |
| 179 << "target_channel=" << target_channel << ", " | 179 << "target_channel=" << target_channel << ", " |
| 180 << "is_powerwash_allowed=" << is_powerwash_allowed; | 180 << "is_powerwash_allowed=" << is_powerwash_allowed; |
| 181 update_engine_proxy_->CallMethod( | 181 update_engine_proxy_->CallMethod( |
| 182 &method_call, | 182 &method_call, |
| 183 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, | 183 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, |
| 184 base::Bind(&UpdateEngineClientImpl::OnSetChannel, | 184 base::Bind(&UpdateEngineClientImpl::OnSetChannel, |
| 185 weak_ptr_factory_.GetWeakPtr())); | 185 weak_ptr_factory_.GetWeakPtr())); |
| 186 } | 186 } |
| 187 | 187 |
| 188 virtual void GetChannel(bool get_current_channel, | 188 virtual void GetChannel(bool get_current_channel, |
| 189 const GetChannelCallback& callback) OVERRIDE { | 189 const GetChannelCallback& callback) override { |
| 190 dbus::MethodCall method_call( | 190 dbus::MethodCall method_call( |
| 191 update_engine::kUpdateEngineInterface, | 191 update_engine::kUpdateEngineInterface, |
| 192 update_engine::kGetChannel); | 192 update_engine::kGetChannel); |
| 193 dbus::MessageWriter writer(&method_call); | 193 dbus::MessageWriter writer(&method_call); |
| 194 writer.AppendBool(get_current_channel); | 194 writer.AppendBool(get_current_channel); |
| 195 | 195 |
| 196 VLOG(1) << "Requesting to get channel, get_current_channel=" | 196 VLOG(1) << "Requesting to get channel, get_current_channel=" |
| 197 << get_current_channel; | 197 << get_current_channel; |
| 198 update_engine_proxy_->CallMethod( | 198 update_engine_proxy_->CallMethod( |
| 199 &method_call, | 199 &method_call, |
| 200 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, | 200 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, |
| 201 base::Bind(&UpdateEngineClientImpl::OnGetChannel, | 201 base::Bind(&UpdateEngineClientImpl::OnGetChannel, |
| 202 weak_ptr_factory_.GetWeakPtr(), | 202 weak_ptr_factory_.GetWeakPtr(), |
| 203 callback)); | 203 callback)); |
| 204 } | 204 } |
| 205 | 205 |
| 206 protected: | 206 protected: |
| 207 virtual void Init(dbus::Bus* bus) OVERRIDE { | 207 virtual void Init(dbus::Bus* bus) override { |
| 208 update_engine_proxy_ = bus->GetObjectProxy( | 208 update_engine_proxy_ = bus->GetObjectProxy( |
| 209 update_engine::kUpdateEngineServiceName, | 209 update_engine::kUpdateEngineServiceName, |
| 210 dbus::ObjectPath(update_engine::kUpdateEngineServicePath)); | 210 dbus::ObjectPath(update_engine::kUpdateEngineServicePath)); |
| 211 | 211 |
| 212 // Monitor the D-Bus signal for brightness changes. Only the power | 212 // Monitor the D-Bus signal for brightness changes. Only the power |
| 213 // manager knows the actual brightness level. We don't cache the | 213 // manager knows the actual brightness level. We don't cache the |
| 214 // brightness level in Chrome as it will make things less reliable. | 214 // brightness level in Chrome as it will make things less reliable. |
| 215 update_engine_proxy_->ConnectToSignal( | 215 update_engine_proxy_->ConnectToSignal( |
| 216 update_engine::kUpdateEngineInterface, | 216 update_engine::kUpdateEngineInterface, |
| 217 update_engine::kStatusUpdate, | 217 update_engine::kStatusUpdate, |
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 395 | 395 |
| 396 // The UpdateEngineClient implementation used on Linux desktop, | 396 // The UpdateEngineClient implementation used on Linux desktop, |
| 397 // which does nothing. | 397 // which does nothing. |
| 398 class UpdateEngineClientStubImpl : public UpdateEngineClient { | 398 class UpdateEngineClientStubImpl : public UpdateEngineClient { |
| 399 public: | 399 public: |
| 400 UpdateEngineClientStubImpl() | 400 UpdateEngineClientStubImpl() |
| 401 : current_channel_(kReleaseChannelBeta), | 401 : current_channel_(kReleaseChannelBeta), |
| 402 target_channel_(kReleaseChannelBeta) {} | 402 target_channel_(kReleaseChannelBeta) {} |
| 403 | 403 |
| 404 // UpdateEngineClient implementation: | 404 // UpdateEngineClient implementation: |
| 405 virtual void Init(dbus::Bus* bus) OVERRIDE {} | 405 virtual void Init(dbus::Bus* bus) override {} |
| 406 virtual void AddObserver(Observer* observer) OVERRIDE {} | 406 virtual void AddObserver(Observer* observer) override {} |
| 407 virtual void RemoveObserver(Observer* observer) OVERRIDE {} | 407 virtual void RemoveObserver(Observer* observer) override {} |
| 408 virtual bool HasObserver(Observer* observer) OVERRIDE { return false; } | 408 virtual bool HasObserver(Observer* observer) override { return false; } |
| 409 | 409 |
| 410 virtual void RequestUpdateCheck( | 410 virtual void RequestUpdateCheck( |
| 411 const UpdateCheckCallback& callback) OVERRIDE { | 411 const UpdateCheckCallback& callback) override { |
| 412 callback.Run(UPDATE_RESULT_NOTIMPLEMENTED); | 412 callback.Run(UPDATE_RESULT_NOTIMPLEMENTED); |
| 413 } | 413 } |
| 414 virtual void RebootAfterUpdate() OVERRIDE {} | 414 virtual void RebootAfterUpdate() override {} |
| 415 virtual void Rollback() OVERRIDE {} | 415 virtual void Rollback() override {} |
| 416 virtual void CanRollbackCheck( | 416 virtual void CanRollbackCheck( |
| 417 const RollbackCheckCallback& callback) OVERRIDE { | 417 const RollbackCheckCallback& callback) override { |
| 418 callback.Run(true); | 418 callback.Run(true); |
| 419 } | 419 } |
| 420 virtual Status GetLastStatus() OVERRIDE { return Status(); } | 420 virtual Status GetLastStatus() override { return Status(); } |
| 421 virtual void SetChannel(const std::string& target_channel, | 421 virtual void SetChannel(const std::string& target_channel, |
| 422 bool is_powerwash_allowed) OVERRIDE { | 422 bool is_powerwash_allowed) override { |
| 423 VLOG(1) << "Requesting to set channel: " | 423 VLOG(1) << "Requesting to set channel: " |
| 424 << "target_channel=" << target_channel << ", " | 424 << "target_channel=" << target_channel << ", " |
| 425 << "is_powerwash_allowed=" << is_powerwash_allowed; | 425 << "is_powerwash_allowed=" << is_powerwash_allowed; |
| 426 target_channel_ = target_channel; | 426 target_channel_ = target_channel; |
| 427 } | 427 } |
| 428 virtual void GetChannel(bool get_current_channel, | 428 virtual void GetChannel(bool get_current_channel, |
| 429 const GetChannelCallback& callback) OVERRIDE { | 429 const GetChannelCallback& callback) override { |
| 430 VLOG(1) << "Requesting to get channel, get_current_channel=" | 430 VLOG(1) << "Requesting to get channel, get_current_channel=" |
| 431 << get_current_channel; | 431 << get_current_channel; |
| 432 if (get_current_channel) | 432 if (get_current_channel) |
| 433 callback.Run(current_channel_); | 433 callback.Run(current_channel_); |
| 434 else | 434 else |
| 435 callback.Run(target_channel_); | 435 callback.Run(target_channel_); |
| 436 } | 436 } |
| 437 | 437 |
| 438 std::string current_channel_; | 438 std::string current_channel_; |
| 439 std::string target_channel_; | 439 std::string target_channel_; |
| 440 }; | 440 }; |
| 441 | 441 |
| 442 // The UpdateEngineClient implementation used on Linux desktop, which | 442 // The UpdateEngineClient implementation used on Linux desktop, which |
| 443 // tries to emulate real update engine client. | 443 // tries to emulate real update engine client. |
| 444 class UpdateEngineClientFakeImpl : public UpdateEngineClientStubImpl { | 444 class UpdateEngineClientFakeImpl : public UpdateEngineClientStubImpl { |
| 445 public: | 445 public: |
| 446 UpdateEngineClientFakeImpl() : weak_factory_(this) { | 446 UpdateEngineClientFakeImpl() : weak_factory_(this) { |
| 447 } | 447 } |
| 448 | 448 |
| 449 virtual ~UpdateEngineClientFakeImpl() { | 449 virtual ~UpdateEngineClientFakeImpl() { |
| 450 } | 450 } |
| 451 | 451 |
| 452 // UpdateEngineClient implementation: | 452 // UpdateEngineClient implementation: |
| 453 virtual void AddObserver(Observer* observer) OVERRIDE { | 453 virtual void AddObserver(Observer* observer) override { |
| 454 if (observer) | 454 if (observer) |
| 455 observers_.AddObserver(observer); | 455 observers_.AddObserver(observer); |
| 456 } | 456 } |
| 457 | 457 |
| 458 virtual void RemoveObserver(Observer* observer) OVERRIDE { | 458 virtual void RemoveObserver(Observer* observer) override { |
| 459 if (observer) | 459 if (observer) |
| 460 observers_.RemoveObserver(observer); | 460 observers_.RemoveObserver(observer); |
| 461 } | 461 } |
| 462 | 462 |
| 463 virtual bool HasObserver(Observer* observer) OVERRIDE { | 463 virtual bool HasObserver(Observer* observer) override { |
| 464 return observers_.HasObserver(observer); | 464 return observers_.HasObserver(observer); |
| 465 } | 465 } |
| 466 | 466 |
| 467 virtual void RequestUpdateCheck( | 467 virtual void RequestUpdateCheck( |
| 468 const UpdateCheckCallback& callback) OVERRIDE { | 468 const UpdateCheckCallback& callback) override { |
| 469 if (last_status_.status != UPDATE_STATUS_IDLE) { | 469 if (last_status_.status != UPDATE_STATUS_IDLE) { |
| 470 callback.Run(UPDATE_RESULT_FAILED); | 470 callback.Run(UPDATE_RESULT_FAILED); |
| 471 return; | 471 return; |
| 472 } | 472 } |
| 473 callback.Run(UPDATE_RESULT_SUCCESS); | 473 callback.Run(UPDATE_RESULT_SUCCESS); |
| 474 last_status_.status = UPDATE_STATUS_CHECKING_FOR_UPDATE; | 474 last_status_.status = UPDATE_STATUS_CHECKING_FOR_UPDATE; |
| 475 last_status_.download_progress = 0.0; | 475 last_status_.download_progress = 0.0; |
| 476 last_status_.last_checked_time = 0; | 476 last_status_.last_checked_time = 0; |
| 477 last_status_.new_size = 0; | 477 last_status_.new_size = 0; |
| 478 base::MessageLoop::current()->PostDelayedTask( | 478 base::MessageLoop::current()->PostDelayedTask( |
| 479 FROM_HERE, | 479 FROM_HERE, |
| 480 base::Bind(&UpdateEngineClientFakeImpl::StateTransition, | 480 base::Bind(&UpdateEngineClientFakeImpl::StateTransition, |
| 481 weak_factory_.GetWeakPtr()), | 481 weak_factory_.GetWeakPtr()), |
| 482 base::TimeDelta::FromMilliseconds(kStateTransitionDefaultDelayMs)); | 482 base::TimeDelta::FromMilliseconds(kStateTransitionDefaultDelayMs)); |
| 483 } | 483 } |
| 484 | 484 |
| 485 virtual Status GetLastStatus() OVERRIDE { return last_status_; } | 485 virtual Status GetLastStatus() override { return last_status_; } |
| 486 | 486 |
| 487 private: | 487 private: |
| 488 void StateTransition() { | 488 void StateTransition() { |
| 489 UpdateStatusOperation next_status = UPDATE_STATUS_ERROR; | 489 UpdateStatusOperation next_status = UPDATE_STATUS_ERROR; |
| 490 int delay_ms = kStateTransitionDefaultDelayMs; | 490 int delay_ms = kStateTransitionDefaultDelayMs; |
| 491 switch (last_status_.status) { | 491 switch (last_status_.status) { |
| 492 case UPDATE_STATUS_ERROR: | 492 case UPDATE_STATUS_ERROR: |
| 493 case UPDATE_STATUS_IDLE: | 493 case UPDATE_STATUS_IDLE: |
| 494 case UPDATE_STATUS_UPDATED_NEED_REBOOT: | 494 case UPDATE_STATUS_UPDATED_NEED_REBOOT: |
| 495 case UPDATE_STATUS_REPORTING_ERROR_EVENT: | 495 case UPDATE_STATUS_REPORTING_ERROR_EVENT: |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 555 if (type == REAL_DBUS_CLIENT_IMPLEMENTATION) | 555 if (type == REAL_DBUS_CLIENT_IMPLEMENTATION) |
| 556 return new UpdateEngineClientImpl(); | 556 return new UpdateEngineClientImpl(); |
| 557 DCHECK_EQ(STUB_DBUS_CLIENT_IMPLEMENTATION, type); | 557 DCHECK_EQ(STUB_DBUS_CLIENT_IMPLEMENTATION, type); |
| 558 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kTestAutoUpdateUI)) | 558 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kTestAutoUpdateUI)) |
| 559 return new UpdateEngineClientFakeImpl(); | 559 return new UpdateEngineClientFakeImpl(); |
| 560 else | 560 else |
| 561 return new UpdateEngineClientStubImpl(); | 561 return new UpdateEngineClientStubImpl(); |
| 562 } | 562 } |
| 563 | 563 |
| 564 } // namespace chromeos | 564 } // namespace chromeos |
| OLD | NEW |