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

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: Used scoped_ptr in callback data. 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
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),
221 user_data(data),
222 proxy(new dbus::Proxy(dbus::GetSystemBusConnection(),
223 kUpdateEngineServiceName,
224 kUpdateEngineServicePath,
225 kUpdateEngineServiceInterface)) {}
226 UpdateCallback callback;
227 void* user_data;
228 scoped_ptr<dbus::Proxy> proxy;
petkov 2011/03/09 00:32:09 actually, does this need to be a pointer at all?
229 };
230
231 // Note: org_chromium_UpdateEngineInterface wraps the DBus calls and provides
232 // its own callback and data, which in turn calls this callback.
233 void UpdateEngineNotify(DBusGProxy* gproxy, GError* error, void* user_data) {
234 UpdateEngineCallbackData* cb_data =
235 static_cast<UpdateEngineCallbackData*>(user_data);
236 if (error) {
237 const char* msg = GetGErrorMessage(error);
238 LOG(WARNING) << "UpdateEngine DBus Error: " << msg;
239 if (cb_data->callback)
240 cb_data->callback(cb_data->user_data, UPDATE_RESULT_FAILED, msg);
241 } else {
242 if (cb_data->callback)
243 cb_data->callback(cb_data->user_data, UPDATE_RESULT_SUCCESS, NULL);
244 }
245 delete cb_data;
246 }
247
248 } // namespace
249
250 extern "C"
251 void ChromeOSRequestUpdateCheck(UpdateCallback callback, void* user_data) {
252 UpdateEngineCallbackData* cb_data =
253 new UpdateEngineCallbackData(callback, user_data);
254 DBusGProxyCall* call_id =
255 org_chromium_UpdateEngineInterface_attempt_update_async(
256 cb_data->proxy->gproxy(), "", "", &UpdateEngineNotify, cb_data);
257 if (!call_id) {
258 LOG(ERROR) << "NULL call_id";
259 if (callback)
260 callback(user_data, UPDATE_RESULT_DBUS_FAILED, NULL);
261 delete cb_data;
262 }
263 }
264
216 extern "C" 265 extern "C"
217 bool ChromeOSRebootIfUpdated() { 266 bool ChromeOSRebootIfUpdated() {
218 dbus::BusConnection bus = dbus::GetSystemBusConnection(); 267 dbus::BusConnection bus = dbus::GetSystemBusConnection();
219 dbus::Proxy update_proxy(bus, 268 dbus::Proxy update_proxy(bus,
220 kUpdateEngineServiceName, 269 kUpdateEngineServiceName,
221 kUpdateEngineServicePath, 270 kUpdateEngineServicePath,
222 kUpdateEngineServiceInterface); 271 kUpdateEngineServiceInterface);
223 GError* error = NULL; 272 GError* error = NULL;
224 273
225 gboolean rc = org_chromium_UpdateEngineInterface_reboot_if_needed( 274 gboolean rc = org_chromium_UpdateEngineInterface_reboot_if_needed(
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
263 << GetGErrorMessage(error); 312 << GetGErrorMessage(error);
264 if (!rc || track == NULL) { 313 if (!rc || track == NULL) {
265 return ""; 314 return "";
266 } 315 }
267 std::string output = track; 316 std::string output = track;
268 g_free(track); 317 g_free(track);
269 return output; 318 return output;
270 } 319 }
271 320
272 } // namespace chromeos 321 } // namespace chromeos
OLDNEW
« chromeos_network.cc ('K') | « chromeos_update_engine.h ('k') | load.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698