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

Side by Side Diff: chromeos_login.cc

Issue 6772019: [cros] Change Store/RetrievePolicy to use a GArray (Closed) Base URL: http://git.chromium.org/git/cros.git@master
Patch Set: DCHECK and delete Created 9 years, 8 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_cros_api.h ('k') | no next file » | 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_login.h" // NOLINT 5 #include "chromeos_login.h" // NOLINT
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include <base/basictypes.h> 9 #include <base/basictypes.h>
10 #include <base/logging.h> 10 #include <base/logging.h>
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
222 } 222 }
223 223
224 extern "C" 224 extern "C"
225 bool ChromeOSRetrievePropertySafe(const char* name, Property** OUT_property) { 225 bool ChromeOSRetrievePropertySafe(const char* name, Property** OUT_property) {
226 DCHECK(OUT_property); 226 DCHECK(OUT_property);
227 GArray* sig; 227 GArray* sig;
228 gchar* value = NULL; 228 gchar* value = NULL;
229 if (!ChromeOSLoginHelpers::RetrievePropertyHelper(name, &value, &sig)) 229 if (!ChromeOSLoginHelpers::RetrievePropertyHelper(name, &value, &sig))
230 return false; 230 return false;
231 *OUT_property = ChromeOSLoginHelpers::CreateProperty(name, value, sig); 231 *OUT_property = ChromeOSLoginHelpers::CreateProperty(name, value, sig);
232 g_array_free(sig, false);
233 g_free(value);
232 return true; 234 return true;
233 } 235 }
234 236
235 extern "C" 237 extern "C"
236 bool ChromeOSSetOwnerKey(const std::vector<uint8>& public_key_der) { 238 bool ChromeOSSetOwnerKey(const std::vector<uint8>& public_key_der) {
237 // TODO(cmasone): Remove this code, once we're sure NOTREACHED isn't hit. 239 // TODO(cmasone): Remove this code, once we're sure NOTREACHED isn't hit.
238 NOTREACHED() << "ChromeOSSetOwnerKey is deprecated"; 240 NOTREACHED() << "ChromeOSSetOwnerKey is deprecated";
239 GArray* key_der = 241 GArray* key_der =
240 ChromeOSLoginHelpers::CreateGArrayFromBytes(&public_key_der[0], 242 ChromeOSLoginHelpers::CreateGArrayFromBytes(&public_key_der[0],
241 public_key_der.size()); 243 public_key_der.size());
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
456 delete cb_data; 458 delete cb_data;
457 } 459 }
458 460
459 void RetrievePolicyNotify(DBusGProxy* gproxy, 461 void RetrievePolicyNotify(DBusGProxy* gproxy,
460 DBusGProxyCall* call_id, 462 DBusGProxyCall* call_id,
461 void* user_data) { 463 void* user_data) {
462 CallbackData<RetrievePolicyCallback>* cb_data = 464 CallbackData<RetrievePolicyCallback>* cb_data =
463 reinterpret_cast<CallbackData<RetrievePolicyCallback>*>(user_data); 465 reinterpret_cast<CallbackData<RetrievePolicyCallback>*>(user_data);
464 DCHECK(cb_data); 466 DCHECK(cb_data);
465 glib::ScopedError error; 467 glib::ScopedError error;
466 gchar* policy_blob = NULL; 468 GArray* policy_blob = NULL;
467 if (!::dbus_g_proxy_end_call(gproxy, 469 if (!::dbus_g_proxy_end_call(gproxy,
468 call_id, 470 call_id,
469 &Resetter(&error).lvalue(), 471 &Resetter(&error).lvalue(),
470 G_TYPE_STRING, &policy_blob, 472 DBUS_TYPE_G_UCHAR_ARRAY, &policy_blob,
471 G_TYPE_INVALID)) { 473 G_TYPE_INVALID)) {
472 LOG(ERROR) << login_manager::kSessionManagerRetrievePolicy 474 LOG(ERROR) << login_manager::kSessionManagerRetrievePolicy
473 << " failed: " << SCOPED_SAFE_MESSAGE(error); 475 << " failed: " << SCOPED_SAFE_MESSAGE(error);
474 } 476 }
475 cb_data->callback(cb_data->object, policy_blob); 477 if (policy_blob) {
476 if (policy_blob) 478 std::string policy(policy_blob->data, policy_blob->len);
477 g_free(policy_blob); 479 cb_data->callback(cb_data->object, policy.c_str());
480 g_array_free(policy_blob, TRUE);
481 } else {
482 cb_data->callback(cb_data->object, NULL);
483 }
478 } 484 }
479 485
480 extern "C" 486 extern "C"
481 void ChromeOSRetrievePolicy(RetrievePolicyCallback callback, void* delegate) { 487 void ChromeOSRetrievePolicy(RetrievePolicyCallback callback, void* delegate) {
482 DCHECK(delegate); 488 DCHECK(delegate);
483 CallbackData<RetrievePolicyCallback>* cb_data = 489 CallbackData<RetrievePolicyCallback>* cb_data =
484 new CallbackData<RetrievePolicyCallback>(callback, delegate); 490 new CallbackData<RetrievePolicyCallback>(callback, delegate);
485 DBusGProxyCall* call_id = 491 DBusGProxyCall* call_id =
486 ::dbus_g_proxy_begin_call(cb_data->proxy.gproxy(), 492 ::dbus_g_proxy_begin_call(cb_data->proxy.gproxy(),
487 login_manager::kSessionManagerRetrievePolicy, 493 login_manager::kSessionManagerRetrievePolicy,
(...skipping 24 matching lines...) Expand all
512 LOG(ERROR) << login_manager::kSessionManagerStorePolicy 518 LOG(ERROR) << login_manager::kSessionManagerStorePolicy
513 << " failed: " << SCOPED_SAFE_MESSAGE(error); 519 << " failed: " << SCOPED_SAFE_MESSAGE(error);
514 } 520 }
515 cb_data->callback(cb_data->object, success); 521 cb_data->callback(cb_data->object, success);
516 } 522 }
517 523
518 extern "C" 524 extern "C"
519 void ChromeOSStorePolicy(const char* prop, 525 void ChromeOSStorePolicy(const char* prop,
520 StorePolicyCallback callback, 526 StorePolicyCallback callback,
521 void* delegate) { 527 void* delegate) {
528 DCHECK(prop);
522 DCHECK(delegate); 529 DCHECK(delegate);
523 CallbackData<StorePolicyCallback>* cb_data = 530 CallbackData<StorePolicyCallback>* cb_data =
524 new CallbackData<StorePolicyCallback>(callback, delegate); 531 new CallbackData<StorePolicyCallback>(callback, delegate);
532 GArray* policy = g_array_new(FALSE, FALSE, 1);
533 policy->data = const_cast<gchar*>(prop); // This just gets copied below.
534 policy->len = strlen(prop);
525 DBusGProxyCall* call_id = 535 DBusGProxyCall* call_id =
526 ::dbus_g_proxy_begin_call(cb_data->proxy.gproxy(), 536 ::dbus_g_proxy_begin_call(cb_data->proxy.gproxy(),
527 login_manager::kSessionManagerStorePolicy, 537 login_manager::kSessionManagerStorePolicy,
528 &StorePolicyNotify, 538 &StorePolicyNotify,
529 cb_data, 539 cb_data,
530 &DeleteCallbackData<StorePolicyCallback>, 540 &DeleteCallbackData<StorePolicyCallback>,
531 G_TYPE_STRING, prop, 541 DBUS_TYPE_G_UCHAR_ARRAY, policy,
532 G_TYPE_INVALID); 542 G_TYPE_INVALID);
533 if (!call_id) { 543 if (!call_id) {
534 LOG(ERROR) << "StorePolicy async call failed"; 544 LOG(ERROR) << "StorePolicy async call failed";
535 delete cb_data; 545 delete cb_data;
536 callback(delegate, false); 546 callback(delegate, false);
537 } 547 }
548 g_array_free(policy, FALSE);
538 } 549 }
539 550
540 } // namespace chromeos 551 } // namespace chromeos
OLDNEW
« no previous file with comments | « chromeos_cros_api.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698