Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(202)

Side by Side Diff: chromeos/dbus/update_engine_client.cc

Issue 17437004: Implemented new channel switcher UI. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed FakeUpdateEngineClient. Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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 implementation:
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.
86 virtual void RemoveObserver(Observer* observer) OVERRIDE { 96 virtual void RemoveObserver(Observer* observer) OVERRIDE {
87 observers_.RemoveObserver(observer); 97 observers_.RemoveObserver(observer);
88 } 98 }
89 99
90 // UpdateEngineClient override.
91 virtual bool HasObserver(Observer* observer) OVERRIDE { 100 virtual bool HasObserver(Observer* observer) OVERRIDE {
92 return observers_.HasObserver(observer); 101 return observers_.HasObserver(observer);
93 } 102 }
94 103
95 // UpdateEngineClient override.
96 virtual void RequestUpdateCheck( 104 virtual void RequestUpdateCheck(
97 const UpdateCheckCallback& callback) OVERRIDE { 105 const UpdateCheckCallback& callback) OVERRIDE {
98 dbus::MethodCall method_call( 106 dbus::MethodCall method_call(
99 update_engine::kUpdateEngineInterface, 107 update_engine::kUpdateEngineInterface,
100 update_engine::kAttemptUpdate); 108 update_engine::kAttemptUpdate);
101 dbus::MessageWriter writer(&method_call); 109 dbus::MessageWriter writer(&method_call);
102 writer.AppendString(""); // Unused. 110 writer.AppendString(""); // Unused.
103 writer.AppendString(""); // Unused. 111 writer.AppendString(""); // Unused.
104 112
105 VLOG(1) << "Requesting an update check"; 113 VLOG(1) << "Requesting an update check";
106 update_engine_proxy_->CallMethod( 114 update_engine_proxy_->CallMethod(
107 &method_call, 115 &method_call,
108 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, 116 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
109 base::Bind(&UpdateEngineClientImpl::OnRequestUpdateCheck, 117 base::Bind(&UpdateEngineClientImpl::OnRequestUpdateCheck,
110 weak_ptr_factory_.GetWeakPtr(), 118 weak_ptr_factory_.GetWeakPtr(),
111 callback)); 119 callback));
112 } 120 }
113 121
114 // UpdateEngineClient override.
115 virtual void RebootAfterUpdate() OVERRIDE { 122 virtual void RebootAfterUpdate() OVERRIDE {
116 dbus::MethodCall method_call( 123 dbus::MethodCall method_call(
117 update_engine::kUpdateEngineInterface, 124 update_engine::kUpdateEngineInterface,
118 update_engine::kRebootIfNeeded); 125 update_engine::kRebootIfNeeded);
119 126
120 VLOG(1) << "Requesting a reboot"; 127 VLOG(1) << "Requesting a reboot";
121 update_engine_proxy_->CallMethod( 128 update_engine_proxy_->CallMethod(
122 &method_call, 129 &method_call,
123 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, 130 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
124 base::Bind(&UpdateEngineClientImpl::OnRebootAfterUpdate, 131 base::Bind(&UpdateEngineClientImpl::OnRebootAfterUpdate,
125 weak_ptr_factory_.GetWeakPtr())); 132 weak_ptr_factory_.GetWeakPtr()));
126 } 133 }
127 134
128 // UpdateEngineClient override.
129 virtual void SetReleaseTrack(const std::string& track) OVERRIDE { 135 virtual void SetReleaseTrack(const std::string& track) OVERRIDE {
130 dbus::MethodCall method_call( 136 dbus::MethodCall method_call(
131 update_engine::kUpdateEngineInterface, 137 update_engine::kUpdateEngineInterface,
132 update_engine::kSetTrack); 138 update_engine::kSetTrack);
133 dbus::MessageWriter writer(&method_call); 139 dbus::MessageWriter writer(&method_call);
134 writer.AppendString(track); 140 writer.AppendString(track);
135 141
136 VLOG(1) << "Requesting to set the release track to " << track; 142 VLOG(1) << "Requesting to set the release track to " << track;
137 update_engine_proxy_->CallMethod( 143 update_engine_proxy_->CallMethod(
138 &method_call, 144 &method_call,
139 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, 145 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
140 base::Bind(&UpdateEngineClientImpl::OnSetReleaseTrack, 146 base::Bind(&UpdateEngineClientImpl::OnSetReleaseTrack,
141 weak_ptr_factory_.GetWeakPtr())); 147 weak_ptr_factory_.GetWeakPtr()));
142 } 148 }
143 149
144 // UpdateEngineClient override.
145 virtual void GetReleaseTrack( 150 virtual void GetReleaseTrack(
146 const GetReleaseTrackCallback& callback) OVERRIDE { 151 const GetReleaseTrackCallback& callback) OVERRIDE {
147 dbus::MethodCall method_call( 152 dbus::MethodCall method_call(
148 update_engine::kUpdateEngineInterface, 153 update_engine::kUpdateEngineInterface,
149 update_engine::kGetTrack); 154 update_engine::kGetTrack);
150 155
151 VLOG(1) << "Requesting to get the current release track"; 156 VLOG(1) << "Requesting to get the current release track";
152 update_engine_proxy_->CallMethod( 157 update_engine_proxy_->CallMethod(
153 &method_call, 158 &method_call,
154 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, 159 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
155 base::Bind(&UpdateEngineClientImpl::OnGetReleaseTrack, 160 base::Bind(&UpdateEngineClientImpl::OnGetReleaseTrack,
156 weak_ptr_factory_.GetWeakPtr(), 161 weak_ptr_factory_.GetWeakPtr(),
157 callback)); 162 callback));
158 } 163 }
159 164
160 // UpdateEngineClient override.
161 virtual Status GetLastStatus() OVERRIDE { 165 virtual Status GetLastStatus() OVERRIDE {
162 return last_status_; 166 return last_status_;
163 } 167 }
164 168
169 virtual void SetChannel(const std::string& target_channel,
170 bool is_powerwash_allowed) OVERRIDE {
171 if (!IsValidChannel(target_channel)) {
172 LOG(ERROR) << "Invalid channel name: " << target_channel;
173 return;
174 }
175
176 dbus::MethodCall method_call(
177 update_engine::kUpdateEngineInterface,
178 update_engine::kSetChannel);
179 dbus::MessageWriter writer(&method_call);
180 writer.AppendString(target_channel);
181 writer.AppendBool(is_powerwash_allowed);
182
183 VLOG(1) << "Requesting to set channel: "
184 << "target_channel=" << target_channel << ", "
185 << "is_powerwash_allowed=" << is_powerwash_allowed;
186 update_engine_proxy_->CallMethod(
187 &method_call,
188 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
189 base::Bind(&UpdateEngineClientImpl::OnSetChannel,
190 weak_ptr_factory_.GetWeakPtr()));
191 }
192
193 virtual void GetChannel(bool get_current_channel,
194 const GetChannelCallback& callback) OVERRIDE {
195 dbus::MethodCall method_call(
196 update_engine::kUpdateEngineInterface,
197 update_engine::kGetChannel);
198 dbus::MessageWriter writer(&method_call);
199 writer.AppendBool(get_current_channel);
200
201 VLOG(1) << "Requesting to get channel, get_current_channel="
202 << get_current_channel;
203 update_engine_proxy_->CallMethod(
204 &method_call,
205 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
206 base::Bind(&UpdateEngineClientImpl::OnGetChannel,
207 weak_ptr_factory_.GetWeakPtr(),
208 callback));
209 }
210
165 private: 211 private:
166 void GetUpdateEngineStatus() { 212 void GetUpdateEngineStatus() {
167 dbus::MethodCall method_call( 213 dbus::MethodCall method_call(
168 update_engine::kUpdateEngineInterface, 214 update_engine::kUpdateEngineInterface,
169 update_engine::kGetStatus); 215 update_engine::kGetStatus);
170 update_engine_proxy_->CallMethodWithErrorCallback( 216 update_engine_proxy_->CallMethodWithErrorCallback(
171 &method_call, 217 &method_call,
172 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, 218 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
173 base::Bind(&UpdateEngineClientImpl::OnGetStatus, 219 base::Bind(&UpdateEngineClientImpl::OnGetStatus,
174 weak_ptr_factory_.GetWeakPtr()), 220 weak_ptr_factory_.GetWeakPtr()),
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
244 status.status = UpdateStatusFromString(current_operation); 290 status.status = UpdateStatusFromString(current_operation);
245 last_status_ = status; 291 last_status_ = status;
246 FOR_EACH_OBSERVER(Observer, observers_, UpdateStatusChanged(status)); 292 FOR_EACH_OBSERVER(Observer, observers_, UpdateStatusChanged(status));
247 } 293 }
248 294
249 // Called when GetStatus call failed. 295 // Called when GetStatus call failed.
250 void OnGetStatusError(dbus::ErrorResponse* error) { 296 void OnGetStatusError(dbus::ErrorResponse* error) {
251 LOG(ERROR) << "GetStatus request failed with error: " << error->ToString(); 297 LOG(ERROR) << "GetStatus request failed with error: " << error->ToString();
252 } 298 }
253 299
300 // Called when a response for SetReleaseTrack() is received.
301 void OnSetChannel(dbus::Response* response) {
302 if (!response) {
303 LOG(ERROR) << "Failed to request setting channel";
304 return;
305 }
306 VLOG(1) << "Succeeded to set channel";
307 }
308
309 // Called when a response for GetChannel() is received.
310 void OnGetChannel(const GetReleaseTrackCallback& callback,
311 dbus::Response* response) {
312 if (!response) {
313 LOG(ERROR) << "Failed to request getting channel";
314 callback.Run("");
315 return;
316 }
317 dbus::MessageReader reader(response);
318 std::string channel;
319 if (!reader.PopString(&channel)) {
320 LOG(ERROR) << "Incorrect response: " << response->ToString();
321 callback.Run("");
322 return;
323 }
324 VLOG(1) << "The channel received: " << channel;
325 callback.Run(channel);
326 }
327
254 // Called when a status update signal is received. 328 // Called when a status update signal is received.
255 void StatusUpdateReceived(dbus::Signal* signal) { 329 void StatusUpdateReceived(dbus::Signal* signal) {
256 VLOG(1) << "Status update signal received: " << signal->ToString(); 330 VLOG(1) << "Status update signal received: " << signal->ToString();
257 dbus::MessageReader reader(signal); 331 dbus::MessageReader reader(signal);
258 int64 last_checked_time = 0; 332 int64 last_checked_time = 0;
259 double progress = 0.0; 333 double progress = 0.0;
260 std::string current_operation; 334 std::string current_operation;
261 std::string new_version; 335 std::string new_version;
262 int64_t new_size = 0; 336 int64_t new_size = 0;
263 if (!(reader.PopInt64(&last_checked_time) && 337 if (!(reader.PopInt64(&last_checked_time) &&
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
295 // Note: This should remain the last member so it'll be destroyed and 369 // Note: This should remain the last member so it'll be destroyed and
296 // invalidate its weak pointers before any other members are destroyed. 370 // invalidate its weak pointers before any other members are destroyed.
297 base::WeakPtrFactory<UpdateEngineClientImpl> weak_ptr_factory_; 371 base::WeakPtrFactory<UpdateEngineClientImpl> weak_ptr_factory_;
298 372
299 DISALLOW_COPY_AND_ASSIGN(UpdateEngineClientImpl); 373 DISALLOW_COPY_AND_ASSIGN(UpdateEngineClientImpl);
300 }; 374 };
301 375
302 // The UpdateEngineClient implementation used on Linux desktop, 376 // The UpdateEngineClient implementation used on Linux desktop,
303 // which does nothing. 377 // which does nothing.
304 class UpdateEngineClientStubImpl : public UpdateEngineClient { 378 class UpdateEngineClientStubImpl : public UpdateEngineClient {
305 // UpdateEngineClient overrides. 379 // UpdateEngineClient implementation:
306 virtual void AddObserver(Observer* observer) OVERRIDE {} 380 virtual void AddObserver(Observer* observer) OVERRIDE {}
307 virtual void RemoveObserver(Observer* observer) OVERRIDE {} 381 virtual void RemoveObserver(Observer* observer) OVERRIDE {}
308 virtual bool HasObserver(Observer* observer) OVERRIDE { return false; } 382 virtual bool HasObserver(Observer* observer) OVERRIDE { return false; }
309 383
310 virtual void RequestUpdateCheck( 384 virtual void RequestUpdateCheck(
311 const UpdateCheckCallback& callback) OVERRIDE { 385 const UpdateCheckCallback& callback) OVERRIDE {
312 callback.Run(UPDATE_RESULT_NOTIMPLEMENTED); 386 callback.Run(UPDATE_RESULT_NOTIMPLEMENTED);
313 } 387 }
314 virtual void RebootAfterUpdate() OVERRIDE {} 388 virtual void RebootAfterUpdate() OVERRIDE {}
315 virtual void SetReleaseTrack(const std::string& track) OVERRIDE {} 389 virtual void SetReleaseTrack(const std::string& track) OVERRIDE {}
316 virtual void GetReleaseTrack( 390 virtual void GetReleaseTrack(
317 const GetReleaseTrackCallback& callback) OVERRIDE { 391 const GetReleaseTrackCallback& callback) OVERRIDE {
318 callback.Run("beta-channel"); 392 callback.Run("beta-channel");
319 } 393 }
320 virtual Status GetLastStatus() OVERRIDE { return Status(); } 394 virtual Status GetLastStatus() OVERRIDE { return Status(); }
395 virtual void SetChannel(const std::string& target_channel,
396 bool is_powerwash_allowed) OVERRIDE {
397 LOG(INFO) << "Requesting to set channel: "
398 << "target_channel=" << target_channel << ", "
399 << "is_powerwash_allowed=" << is_powerwash_allowed;
400 }
401 virtual void GetChannel(bool get_current_channel,
402 const GetChannelCallback& callback) OVERRIDE {
403 LOG(INFO) << "Requesting to get channel, get_current_channel="
404 << get_current_channel;
405 callback.Run("beta-channel");
406 }
321 }; 407 };
322 408
323 UpdateEngineClient::UpdateEngineClient() { 409 UpdateEngineClient::UpdateEngineClient() {
324 } 410 }
325 411
326 UpdateEngineClient::~UpdateEngineClient() { 412 UpdateEngineClient::~UpdateEngineClient() {
327 } 413 }
328 414
329 // static 415 // static
330 UpdateEngineClient::UpdateCheckCallback 416 UpdateEngineClient::UpdateCheckCallback
331 UpdateEngineClient::EmptyUpdateCheckCallback() { 417 UpdateEngineClient::EmptyUpdateCheckCallback() {
332 return base::Bind(&EmptyUpdateCheckCallbackBody); 418 return base::Bind(&EmptyUpdateCheckCallbackBody);
333 } 419 }
334 420
335 // static 421 // static
336 UpdateEngineClient* UpdateEngineClient::Create( 422 UpdateEngineClient* UpdateEngineClient::Create(
337 DBusClientImplementationType type, 423 DBusClientImplementationType type,
338 dbus::Bus* bus) { 424 dbus::Bus* bus) {
339 if (type == REAL_DBUS_CLIENT_IMPLEMENTATION) 425 if (type == REAL_DBUS_CLIENT_IMPLEMENTATION)
340 return new UpdateEngineClientImpl(bus); 426 return new UpdateEngineClientImpl(bus);
341 DCHECK_EQ(STUB_DBUS_CLIENT_IMPLEMENTATION, type); 427 DCHECK_EQ(STUB_DBUS_CLIENT_IMPLEMENTATION, type);
342 return new UpdateEngineClientStubImpl(); 428 return new UpdateEngineClientStubImpl();
343 } 429 }
344 430
345 } // namespace chromeos 431 } // namespace chromeos
OLDNEW
« chrome/browser/ui/webui/help/help_handler.cc ('K') | « chromeos/dbus/update_engine_client.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698