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

Side by Side Diff: chromeos_update_engine.cc

Issue 6648007: Libcros changes for issue_12743: Add async RequestUpdateCheck call. (Closed) Base URL: ssh://git@gitrw.chromium.org:9222/cros.git@master
Patch Set: Incrament libcros API to 111 Created 9 years, 9 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
« no previous file with comments | « chromeos_update_engine.h ('k') | load.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium OS Authors. All rights reserved. 1 // Copyright (c) 2010 The Chromium OS 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_update_engine.h" 5 #include "chromeos_update_engine.h"
6 #include <cstring> 6 #include <cstring>
7 #include "chromeos/dbus/dbus.h" 7 #include "chromeos/dbus/dbus.h"
8 #include "chromeos/string.h" 8 #include "chromeos/string.h"
9 #include "marshal.glibmarshal.h" 9 #include "marshal.glibmarshal.h"
10 10
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
206 kUpdateEngineServiceInterface); 206 kUpdateEngineServiceInterface);
207 GError* error = NULL; 207 GError* error = NULL;
208 208
209 gboolean rc = org_chromium_UpdateEngineInterface_attempt_update( 209 gboolean rc = org_chromium_UpdateEngineInterface_attempt_update(
210 update_proxy.gproxy(), "", "", &error); 210 update_proxy.gproxy(), "", "", &error);
211 LOG_IF(ERROR, rc == FALSE) << "Error checking for update: " 211 LOG_IF(ERROR, rc == FALSE) << "Error checking for update: "
212 << GetGErrorMessage(error); 212 << GetGErrorMessage(error);
213 return rc == TRUE; 213 return rc == TRUE;
214 } 214 }
215 215
216 namespace {
217
218 struct UpdateEngineCallbackData {
219 UpdateEngineCallbackData(UpdateCallback cb, void* data)
220 : callback(cb), user_data(data) {
221 proxy = new dbus::Proxy(dbus::GetSystemBusConnection(),
222 kUpdateEngineServiceName,
223 kUpdateEngineServicePath,
224 kUpdateEngineServiceInterface);
225 }
226 virtual ~UpdateEngineCallbackData() {
227 delete proxy;
228 }
229 UpdateCallback callback;
230 void* user_data;
231 dbus::Proxy* proxy;
petkov 2011/03/08 22:49:18 any reason why this is not a scoped_ptr? then you
232 };
233
234 // Note: org_chromium_UpdateEngineInterface wraps the DBus calls and provides
235 // its own callback and data, which in turn calls this callback.
236 void UpdateEngineNotify(DBusGProxy* gproxy, GError* error, void* user_data) {
237 UpdateEngineCallbackData* cb_data =
238 static_cast<UpdateEngineCallbackData*>(user_data);
239 if (error) {
240 const char* msg = GetGErrorMessage(error);
241 LOG(WARNING) << "UpdateEngine DBus Error: " << msg;
242 if (cb_data->callback)
243 cb_data->callback(cb_data->user_data, UPDATE_RESULT_FAILED, msg);
244 } else {
245 if (cb_data->callback)
246 cb_data->callback(cb_data->user_data, UPDATE_RESULT_SUCCESS, NULL);
247 }
248 delete cb_data;
249 }
250
251 } // namespace
252
253 extern "C"
254 void ChromeOSRequestUpdateCheck(UpdateCallback callback, void* user_data) {
255 UpdateEngineCallbackData* cb_data =
256 new UpdateEngineCallbackData(callback, user_data);
257 DBusGProxyCall* call_id =
258 org_chromium_UpdateEngineInterface_attempt_update_async(
259 cb_data->proxy->gproxy(), "", "", &UpdateEngineNotify, cb_data);
260 if (!call_id) {
261 LOG(ERROR) << "NULL call_id";
262 if (callback)
263 callback(user_data, UPDATE_RESULT_DBUS_FAILED, NULL);
264 delete cb_data;
265 }
266 }
267
216 extern "C" 268 extern "C"
217 bool ChromeOSRebootIfUpdated() { 269 bool ChromeOSRebootIfUpdated() {
218 dbus::BusConnection bus = dbus::GetSystemBusConnection(); 270 dbus::BusConnection bus = dbus::GetSystemBusConnection();
219 dbus::Proxy update_proxy(bus, 271 dbus::Proxy update_proxy(bus,
220 kUpdateEngineServiceName, 272 kUpdateEngineServiceName,
221 kUpdateEngineServicePath, 273 kUpdateEngineServicePath,
222 kUpdateEngineServiceInterface); 274 kUpdateEngineServiceInterface);
223 GError* error = NULL; 275 GError* error = NULL;
224 276
225 gboolean rc = org_chromium_UpdateEngineInterface_reboot_if_needed( 277 gboolean rc = org_chromium_UpdateEngineInterface_reboot_if_needed(
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
263 << GetGErrorMessage(error); 315 << GetGErrorMessage(error);
264 if (!rc || track == NULL) { 316 if (!rc || track == NULL) {
265 return ""; 317 return "";
266 } 318 }
267 std::string output = track; 319 std::string output = track;
268 g_free(track); 320 g_free(track);
269 return output; 321 return output;
270 } 322 }
271 323
272 } // namespace chromeos 324 } // namespace chromeos
OLDNEW
« no previous file with comments | « chromeos_update_engine.h ('k') | load.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698