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

Side by Side Diff: chrome/browser/extensions/api/easy_unlock_private/easy_unlock_private_api.cc

Issue 820673004: json_schema_compiler: Use std::vector<char> for binary values. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@simplify_json_schema
Patch Set: Created 5 years, 11 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "chrome/browser/extensions/api/easy_unlock_private/easy_unlock_private_ api.h" 5 #include "chrome/browser/extensions/api/easy_unlock_private/easy_unlock_private_ api.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/lazy_instance.h" 10 #include "base/lazy_instance.h"
(...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after
340 base::Bind(&EasyUnlockPrivatePerformECDHKeyAgreementFunction::OnData, 340 base::Bind(&EasyUnlockPrivatePerformECDHKeyAgreementFunction::OnData,
341 this)); 341 this));
342 return true; 342 return true;
343 } 343 }
344 344
345 void EasyUnlockPrivatePerformECDHKeyAgreementFunction::OnData( 345 void EasyUnlockPrivatePerformECDHKeyAgreementFunction::OnData(
346 const std::string& secret_key) { 346 const std::string& secret_key) {
347 // TODO(tbarzic): Improve error handling. 347 // TODO(tbarzic): Improve error handling.
348 if (!secret_key.empty()) { 348 if (!secret_key.empty()) {
349 results_ = easy_unlock_private::PerformECDHKeyAgreement::Results::Create( 349 results_ = easy_unlock_private::PerformECDHKeyAgreement::Results::Create(
350 secret_key); 350 std::vector<char>(secret_key.begin(), secret_key.end()));
351 } 351 }
352 SendResponse(true); 352 SendResponse(true);
353 } 353 }
354 354
355 EasyUnlockPrivateGenerateEcP256KeyPairFunction:: 355 EasyUnlockPrivateGenerateEcP256KeyPairFunction::
356 EasyUnlockPrivateGenerateEcP256KeyPairFunction() {} 356 EasyUnlockPrivateGenerateEcP256KeyPairFunction() {}
357 357
358 EasyUnlockPrivateGenerateEcP256KeyPairFunction:: 358 EasyUnlockPrivateGenerateEcP256KeyPairFunction::
359 ~EasyUnlockPrivateGenerateEcP256KeyPairFunction() {} 359 ~EasyUnlockPrivateGenerateEcP256KeyPairFunction() {}
360 360
361 bool EasyUnlockPrivateGenerateEcP256KeyPairFunction::RunAsync() { 361 bool EasyUnlockPrivateGenerateEcP256KeyPairFunction::RunAsync() {
362 GetCryptoDelegate(browser_context())->GenerateEcP256KeyPair( 362 GetCryptoDelegate(browser_context())->GenerateEcP256KeyPair(
363 base::Bind(&EasyUnlockPrivateGenerateEcP256KeyPairFunction::OnData, 363 base::Bind(&EasyUnlockPrivateGenerateEcP256KeyPairFunction::OnData,
364 this)); 364 this));
365 return true; 365 return true;
366 } 366 }
367 367
368 void EasyUnlockPrivateGenerateEcP256KeyPairFunction::OnData( 368 void EasyUnlockPrivateGenerateEcP256KeyPairFunction::OnData(
369 const std::string& private_key, 369 const std::string& private_key,
370 const std::string& public_key) { 370 const std::string& public_key) {
371 // TODO(tbarzic): Improve error handling. 371 // TODO(tbarzic): Improve error handling.
372 if (!public_key.empty() && !private_key.empty()) { 372 if (!public_key.empty() && !private_key.empty()) {
373 results_ = easy_unlock_private::GenerateEcP256KeyPair::Results::Create( 373 results_ = easy_unlock_private::GenerateEcP256KeyPair::Results::Create(
374 public_key, private_key); 374 std::vector<char>(public_key.begin(), public_key.end()),
375 std::vector<char>(private_key.begin(), private_key.end()));
375 } 376 }
376 SendResponse(true); 377 SendResponse(true);
377 } 378 }
378 379
379 EasyUnlockPrivateCreateSecureMessageFunction:: 380 EasyUnlockPrivateCreateSecureMessageFunction::
380 EasyUnlockPrivateCreateSecureMessageFunction() {} 381 EasyUnlockPrivateCreateSecureMessageFunction() {}
381 382
382 EasyUnlockPrivateCreateSecureMessageFunction:: 383 EasyUnlockPrivateCreateSecureMessageFunction::
383 ~EasyUnlockPrivateCreateSecureMessageFunction() {} 384 ~EasyUnlockPrivateCreateSecureMessageFunction() {}
384 385
385 bool EasyUnlockPrivateCreateSecureMessageFunction::RunAsync() { 386 bool EasyUnlockPrivateCreateSecureMessageFunction::RunAsync() {
386 scoped_ptr<easy_unlock_private::CreateSecureMessage::Params> params = 387 scoped_ptr<easy_unlock_private::CreateSecureMessage::Params> params =
387 easy_unlock_private::CreateSecureMessage::Params::Create(*args_); 388 easy_unlock_private::CreateSecureMessage::Params::Create(*args_);
388 EXTENSION_FUNCTION_VALIDATE(params); 389 EXTENSION_FUNCTION_VALIDATE(params);
389 390
390 GetCryptoDelegate(browser_context())->CreateSecureMessage( 391 GetCryptoDelegate(browser_context())->CreateSecureMessage(
391 *params, 392 *params,
392 base::Bind(&EasyUnlockPrivateCreateSecureMessageFunction::OnData, 393 base::Bind(&EasyUnlockPrivateCreateSecureMessageFunction::OnData,
393 this)); 394 this));
394 return true; 395 return true;
395 } 396 }
396 397
397 void EasyUnlockPrivateCreateSecureMessageFunction::OnData( 398 void EasyUnlockPrivateCreateSecureMessageFunction::OnData(
398 const std::string& message) { 399 const std::string& message) {
399 // TODO(tbarzic): Improve error handling. 400 // TODO(tbarzic): Improve error handling.
400 if (!message.empty()) { 401 if (!message.empty()) {
401 results_ = easy_unlock_private::CreateSecureMessage::Results::Create( 402 results_ = easy_unlock_private::CreateSecureMessage::Results::Create(
402 message); 403 std::vector<char>(message.begin(), message.end()));
403 } 404 }
404 SendResponse(true); 405 SendResponse(true);
405 } 406 }
406 407
407 EasyUnlockPrivateUnwrapSecureMessageFunction:: 408 EasyUnlockPrivateUnwrapSecureMessageFunction::
408 EasyUnlockPrivateUnwrapSecureMessageFunction() {} 409 EasyUnlockPrivateUnwrapSecureMessageFunction() {}
409 410
410 EasyUnlockPrivateUnwrapSecureMessageFunction:: 411 EasyUnlockPrivateUnwrapSecureMessageFunction::
411 ~EasyUnlockPrivateUnwrapSecureMessageFunction() {} 412 ~EasyUnlockPrivateUnwrapSecureMessageFunction() {}
412 413
413 bool EasyUnlockPrivateUnwrapSecureMessageFunction::RunAsync() { 414 bool EasyUnlockPrivateUnwrapSecureMessageFunction::RunAsync() {
414 scoped_ptr<easy_unlock_private::UnwrapSecureMessage::Params> params = 415 scoped_ptr<easy_unlock_private::UnwrapSecureMessage::Params> params =
415 easy_unlock_private::UnwrapSecureMessage::Params::Create(*args_); 416 easy_unlock_private::UnwrapSecureMessage::Params::Create(*args_);
416 EXTENSION_FUNCTION_VALIDATE(params); 417 EXTENSION_FUNCTION_VALIDATE(params);
417 418
418 GetCryptoDelegate(browser_context())->UnwrapSecureMessage( 419 GetCryptoDelegate(browser_context())->UnwrapSecureMessage(
419 *params, 420 *params,
420 base::Bind(&EasyUnlockPrivateUnwrapSecureMessageFunction::OnData, 421 base::Bind(&EasyUnlockPrivateUnwrapSecureMessageFunction::OnData,
421 this)); 422 this));
422 return true; 423 return true;
423 } 424 }
424 425
425 void EasyUnlockPrivateUnwrapSecureMessageFunction::OnData( 426 void EasyUnlockPrivateUnwrapSecureMessageFunction::OnData(
426 const std::string& data) { 427 const std::string& data) {
427 // TODO(tbarzic): Improve error handling. 428 // TODO(tbarzic): Improve error handling.
428 if (!data.empty()) 429 if (!data.empty()) {
429 results_ = easy_unlock_private::UnwrapSecureMessage::Results::Create(data); 430 results_ = easy_unlock_private::UnwrapSecureMessage::Results::Create(
431 std::vector<char>(data.begin(), data.end()));
432 }
430 SendResponse(true); 433 SendResponse(true);
431 } 434 }
432 435
433 EasyUnlockPrivateSeekBluetoothDeviceByAddressFunction:: 436 EasyUnlockPrivateSeekBluetoothDeviceByAddressFunction::
434 EasyUnlockPrivateSeekBluetoothDeviceByAddressFunction() {} 437 EasyUnlockPrivateSeekBluetoothDeviceByAddressFunction() {}
435 438
436 EasyUnlockPrivateSeekBluetoothDeviceByAddressFunction:: 439 EasyUnlockPrivateSeekBluetoothDeviceByAddressFunction::
437 ~EasyUnlockPrivateSeekBluetoothDeviceByAddressFunction() {} 440 ~EasyUnlockPrivateSeekBluetoothDeviceByAddressFunction() {}
438 441
439 bool EasyUnlockPrivateSeekBluetoothDeviceByAddressFunction::RunAsync() { 442 bool EasyUnlockPrivateSeekBluetoothDeviceByAddressFunction::RunAsync() {
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
616 EasyUnlockService::Get(profile)->GetChallenge(); 619 EasyUnlockService::Get(profile)->GetChallenge();
617 if (!challenge.empty() && !params->nonce.empty()) { 620 if (!challenge.empty() && !params->nonce.empty()) {
618 EasyUnlockTpmKeyManager* key_manager = 621 EasyUnlockTpmKeyManager* key_manager =
619 EasyUnlockTpmKeyManagerFactory::GetInstance()->Get(profile); 622 EasyUnlockTpmKeyManagerFactory::GetInstance()->Get(profile);
620 if (!key_manager) { 623 if (!key_manager) {
621 SetError("No EasyUnlockTpmKeyManager."); 624 SetError("No EasyUnlockTpmKeyManager.");
622 return false; 625 return false;
623 } 626 }
624 key_manager->SignUsingTpmKey( 627 key_manager->SignUsingTpmKey(
625 EasyUnlockService::Get(profile)->GetUserEmail(), 628 EasyUnlockService::Get(profile)->GetUserEmail(),
626 params->nonce, 629 std::string(params->nonce.begin(), params->nonce.end()),
627 base::Bind(&EasyUnlockPrivateGetSignInChallengeFunction::OnDone, 630 base::Bind(&EasyUnlockPrivateGetSignInChallengeFunction::OnDone, this,
628 this,
629 challenge)); 631 challenge));
630 } else { 632 } else {
631 OnDone(challenge, std::string()); 633 OnDone(challenge, std::string());
632 } 634 }
633 return true; 635 return true;
634 #else // if !defined(OS_CHROMEOS) 636 #else // if !defined(OS_CHROMEOS)
635 SetError("Sign-in not supported."); 637 SetError("Sign-in not supported.");
636 return false; 638 return false;
637 #endif // defined(OS_CHROMEOS) 639 #endif // defined(OS_CHROMEOS)
638 } 640 }
639 641
640 void EasyUnlockPrivateGetSignInChallengeFunction::OnDone( 642 void EasyUnlockPrivateGetSignInChallengeFunction::OnDone(
641 const std::string& challenge, 643 const std::string& challenge,
642 const std::string& signed_nonce) { 644 const std::string& signed_nonce) {
643 results_ = easy_unlock_private::GetSignInChallenge::Results::Create( 645 results_ = easy_unlock_private::GetSignInChallenge::Results::Create(
644 challenge, signed_nonce); 646 std::vector<char>(challenge.begin(), challenge.end()),
647 std::vector<char>(signed_nonce.begin(), signed_nonce.end()));
645 SendResponse(true); 648 SendResponse(true);
646 } 649 }
647 650
648 EasyUnlockPrivateTrySignInSecretFunction:: 651 EasyUnlockPrivateTrySignInSecretFunction::
649 EasyUnlockPrivateTrySignInSecretFunction() { 652 EasyUnlockPrivateTrySignInSecretFunction() {
650 } 653 }
651 654
652 EasyUnlockPrivateTrySignInSecretFunction:: 655 EasyUnlockPrivateTrySignInSecretFunction::
653 ~EasyUnlockPrivateTrySignInSecretFunction() { 656 ~EasyUnlockPrivateTrySignInSecretFunction() {
654 } 657 }
655 658
656 bool EasyUnlockPrivateTrySignInSecretFunction::RunSync() { 659 bool EasyUnlockPrivateTrySignInSecretFunction::RunSync() {
657 scoped_ptr<easy_unlock_private::TrySignInSecret::Params> params( 660 scoped_ptr<easy_unlock_private::TrySignInSecret::Params> params(
658 easy_unlock_private::TrySignInSecret::Params::Create(*args_)); 661 easy_unlock_private::TrySignInSecret::Params::Create(*args_));
659 EXTENSION_FUNCTION_VALIDATE(params.get()); 662 EXTENSION_FUNCTION_VALIDATE(params.get());
660 663
661 Profile* profile = Profile::FromBrowserContext(browser_context()); 664 Profile* profile = Profile::FromBrowserContext(browser_context());
662 EasyUnlockService::Get(profile)->FinalizeSignin(params->sign_in_secret); 665 EasyUnlockService::Get(profile)->FinalizeSignin(std::string(
666 params->sign_in_secret.begin(), params->sign_in_secret.end()));
663 return true; 667 return true;
664 } 668 }
665 669
666 EasyUnlockPrivateGetUserInfoFunction::EasyUnlockPrivateGetUserInfoFunction() { 670 EasyUnlockPrivateGetUserInfoFunction::EasyUnlockPrivateGetUserInfoFunction() {
667 } 671 }
668 672
669 EasyUnlockPrivateGetUserInfoFunction::~EasyUnlockPrivateGetUserInfoFunction() { 673 EasyUnlockPrivateGetUserInfoFunction::~EasyUnlockPrivateGetUserInfoFunction() {
670 } 674 }
671 675
672 bool EasyUnlockPrivateGetUserInfoFunction::RunSync() { 676 bool EasyUnlockPrivateGetUserInfoFunction::RunSync() {
(...skipping 25 matching lines...) Expand all
698 #if defined(OS_CHROMEOS) 702 #if defined(OS_CHROMEOS)
699 EasyUnlockService* service = 703 EasyUnlockService* service =
700 EasyUnlockService::Get(Profile::FromBrowserContext(browser_context())); 704 EasyUnlockService::Get(Profile::FromBrowserContext(browser_context()));
701 const std::vector<ui::ScaleFactor>& supported_scale_factors = 705 const std::vector<ui::ScaleFactor>& supported_scale_factors =
702 ui::GetSupportedScaleFactors(); 706 ui::GetSupportedScaleFactors();
703 707
704 base::RefCountedMemory* user_image = 708 base::RefCountedMemory* user_image =
705 chromeos::options::UserImageSource::GetUserImage( 709 chromeos::options::UserImageSource::GetUserImage(
706 service->GetUserEmail(), supported_scale_factors.back()); 710 service->GetUserEmail(), supported_scale_factors.back());
707 711
708 results_ = easy_unlock_private::GetUserImage::Results::Create(std::string( 712 results_ =
709 reinterpret_cast<const char*>(user_image->front()), user_image->size())); 713 easy_unlock_private::GetUserImage::Results::Create(std::vector<char>(
714 user_image->front(), user_image->front() + user_image->size()));
710 #else 715 #else
711 // TODO(tengs): Find a way to get the profile picture for non-ChromeOS 716 // TODO(tengs): Find a way to get the profile picture for non-ChromeOS
712 // devices. 717 // devices.
713 results_ = easy_unlock_private::GetUserImage::Results::Create(""); 718 results_ = easy_unlock_private::GetUserImage::Results::Create("");
714 SetError("Not supported on non-ChromeOS platforms."); 719 SetError("Not supported on non-ChromeOS platforms.");
715 #endif 720 #endif
716 return true; 721 return true;
717 } 722 }
718 723
719 EasyUnlockPrivateGetConnectionInfoFunction:: 724 EasyUnlockPrivateGetConnectionInfoFunction::
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
754 scoped_ptr<base::ListValue> results(new base::ListValue()); 759 scoped_ptr<base::ListValue> results(new base::ListValue());
755 results->AppendInteger(connection_info.rssi); 760 results->AppendInteger(connection_info.rssi);
756 results->AppendInteger(connection_info.transmit_power); 761 results->AppendInteger(connection_info.transmit_power);
757 results->AppendInteger(connection_info.max_transmit_power); 762 results->AppendInteger(connection_info.max_transmit_power);
758 SetResultList(results.Pass()); 763 SetResultList(results.Pass());
759 SendResponse(true); 764 SendResponse(true);
760 } 765 }
761 766
762 } // namespace api 767 } // namespace api
763 } // namespace extensions 768 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698