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

Side by Side Diff: chrome/browser/extensions/api/gcd_private/gcd_private_api.cc

Issue 434733003: Added function to get list of networks with prefetched passwords. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Thu 07/31/2014 14:34:51.93 Created 6 years, 4 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 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/gcd_private/gcd_private_api.h" 5 #include "chrome/browser/extensions/api/gcd_private/gcd_private_api.h"
6 6
7 #include "base/lazy_instance.h" 7 #include "base/lazy_instance.h"
8 #include "base/memory/linked_ptr.h" 8 #include "base/memory/linked_ptr.h"
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/memory/scoped_vector.h" 10 #include "base/memory/scoped_vector.h"
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 void SendMessage(int session_id, 129 void SendMessage(int session_id,
130 const std::string& api, 130 const std::string& api,
131 const base::DictionaryValue& input, 131 const base::DictionaryValue& input,
132 MessageResponseCallback callback); 132 MessageResponseCallback callback);
133 133
134 void RequestWifiPassword(const std::string& ssid, 134 void RequestWifiPassword(const std::string& ssid,
135 const SuccessCallback& callback); 135 const SuccessCallback& callback);
136 136
137 void RemoveSession(int session_id); 137 void RemoveSession(int session_id);
138 138
139 scoped_ptr<base::ListValue> GetPrefetchedSSIDList();
140
139 private: 141 private:
140 typedef std::map<std::string /* id_string */, 142 typedef std::map<std::string /* id_string */,
141 linked_ptr<api::gcd_private::GCDDevice> > GCDDeviceMap; 143 linked_ptr<api::gcd_private::GCDDevice> > GCDDeviceMap;
142 144
143 typedef std::map<int /* session id*/, linked_ptr<GcdPrivateSessionHolder> > 145 typedef std::map<int /* session id*/, linked_ptr<GcdPrivateSessionHolder> >
144 GCDSessionMap; 146 GCDSessionMap;
145 147
146 typedef std::map<std::string /* ssid */, std::string /* password */> 148 typedef std::map<std::string /* ssid */, std::string /* password */>
147 PasswordMap; 149 PasswordMap;
148 150
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after
384 const std::string& api, 386 const std::string& api,
385 const base::DictionaryValue& input, 387 const base::DictionaryValue& input,
386 MessageResponseCallback callback) { 388 MessageResponseCallback callback) {
387 const base::DictionaryValue* input_actual = &input; 389 const base::DictionaryValue* input_actual = &input;
388 #if defined(ENABLE_WIFI_BOOTSTRAPPING) 390 #if defined(ENABLE_WIFI_BOOTSTRAPPING)
389 scoped_ptr<base::DictionaryValue> input_cloned; 391 scoped_ptr<base::DictionaryValue> input_cloned;
390 392
391 if (api == kPrivatAPISetup) { 393 if (api == kPrivatAPISetup) {
392 const base::DictionaryValue* wifi = NULL; 394 const base::DictionaryValue* wifi = NULL;
393 395
394 if (input.GetDictionary(kPrivetKeyWifi, &wifi) && 396 if (input.GetDictionary(kPrivetKeyWifi, &wifi)) {
395 !wifi->HasKey(kPrivetKeyPassphrase)) {
396 // If the message is a setup message, has a wifi section, try sending the
397 // passphrase.
398 std::string ssid; 397 std::string ssid;
399 398
400 if (!wifi->GetString(kPrivetKeySSID, &ssid)) { 399 if (!wifi->GetString(kPrivetKeySSID, &ssid)) {
401 callback.Run(gcd_private::STATUS_SETUPPARSEERROR, 400 callback.Run(gcd_private::STATUS_SETUPPARSEERROR,
402 base::DictionaryValue()); 401 base::DictionaryValue());
403 return; 402 return;
404 } 403 }
405 404
406 PasswordMap::iterator found = wifi_passwords_.find(ssid); 405 if (!wifi->HasKey(kPrivetKeyPassphrase)) {
407 if (found == wifi_passwords_.end()) { 406 // If the message is a setup message, has a wifi section, try sending
408 callback.Run(gcd_private::STATUS_WIFIPASSWORDERROR, 407 // the passphrase.
409 base::DictionaryValue()); 408
410 return; 409 PasswordMap::iterator found = wifi_passwords_.find(ssid);
410 if (found == wifi_passwords_.end()) {
411 callback.Run(gcd_private::STATUS_WIFIPASSWORDERROR,
412 base::DictionaryValue());
413 return;
414 }
415
416 input_cloned.reset(input.DeepCopy());
417 input_cloned->SetString(kPrivetKeyPassphraseDotted, found->second);
418 input_actual = input_cloned.get();
411 } 419 }
412
413 input_cloned.reset(input.DeepCopy());
414 input_cloned->SetString(kPrivetKeyPassphraseDotted, found->second);
415 input_actual = input_cloned.get();
416 } 420 }
417 } 421 }
418 #endif 422 #endif
419 423
420 GCDSessionMap::iterator found = sessions_.find(session_id); 424 GCDSessionMap::iterator found = sessions_.find(session_id);
421 425
422 if (found == sessions_.end()) { 426 if (found == sessions_.end()) {
423 callback.Run(gcd_private::STATUS_UNKNOWNSESSIONERROR, 427 callback.Run(gcd_private::STATUS_UNKNOWNSESSIONERROR,
424 base::DictionaryValue()); 428 base::DictionaryValue());
425 return; 429 return;
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
460 wifi_manager_->Start(); 464 wifi_manager_->Start();
461 } 465 }
462 } 466 }
463 467
464 #endif 468 #endif
465 469
466 void GcdPrivateAPIImpl::RemoveSession(int session_id) { 470 void GcdPrivateAPIImpl::RemoveSession(int session_id) {
467 sessions_.erase(session_id); 471 sessions_.erase(session_id);
468 } 472 }
469 473
474 scoped_ptr<base::ListValue> GcdPrivateAPIImpl::GetPrefetchedSSIDList() {
475 scoped_ptr<base::ListValue> retval(new base::ListValue);
476
477 #if defined(ENABLE_WIFI_BOOTSTRAPPING)
478 for (PasswordMap::iterator i = wifi_passwords_.begin();
479 i != wifi_passwords_.end();
480 i++) {
481 retval->AppendString(i->first);
482 }
483 #endif
484
485 return retval.Pass();
486 }
487
470 GcdPrivateRequest::GcdPrivateRequest( 488 GcdPrivateRequest::GcdPrivateRequest(
471 const std::string& api, 489 const std::string& api,
472 const base::DictionaryValue& input, 490 const base::DictionaryValue& input,
473 const GcdPrivateAPIImpl::MessageResponseCallback& callback, 491 const GcdPrivateAPIImpl::MessageResponseCallback& callback,
474 GcdPrivateSessionHolder* session_holder) 492 GcdPrivateSessionHolder* session_holder)
475 : api_(api), 493 : api_(api),
476 input_(input.DeepCopy()), 494 input_(input.DeepCopy()),
477 callback_(callback), 495 callback_(callback),
478 session_holder_(session_holder) { 496 session_holder_(session_holder) {
479 } 497 }
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
679 GcdPrivateQueryForNewLocalDevicesFunction() { 697 GcdPrivateQueryForNewLocalDevicesFunction() {
680 } 698 }
681 699
682 GcdPrivateQueryForNewLocalDevicesFunction:: 700 GcdPrivateQueryForNewLocalDevicesFunction::
683 ~GcdPrivateQueryForNewLocalDevicesFunction() { 701 ~GcdPrivateQueryForNewLocalDevicesFunction() {
684 } 702 }
685 703
686 bool GcdPrivateQueryForNewLocalDevicesFunction::RunSync() { 704 bool GcdPrivateQueryForNewLocalDevicesFunction::RunSync() {
687 GcdPrivateAPIImpl* gcd_api = GcdPrivateAPIImpl::Get(GetProfile()); 705 GcdPrivateAPIImpl* gcd_api = GcdPrivateAPIImpl::Get(GetProfile());
688 706
689 if (!gcd_api)
690 return false;
691
692 if (!gcd_api->QueryForDevices()) { 707 if (!gcd_api->QueryForDevices()) {
693 error_ = 708 error_ =
694 "You must first subscribe to onDeviceStateChanged or onDeviceRemoved " 709 "You must first subscribe to onDeviceStateChanged or onDeviceRemoved "
695 "notifications"; 710 "notifications";
696 return false; 711 return false;
697 } 712 }
698 713
699 return true; 714 return true;
700 } 715 }
701 716
702 GcdPrivatePrefetchWifiPasswordFunction:: 717 GcdPrivatePrefetchWifiPasswordFunction::
703 GcdPrivatePrefetchWifiPasswordFunction() { 718 GcdPrivatePrefetchWifiPasswordFunction() {
704 } 719 }
705 720
706 GcdPrivatePrefetchWifiPasswordFunction:: 721 GcdPrivatePrefetchWifiPasswordFunction::
707 ~GcdPrivatePrefetchWifiPasswordFunction() { 722 ~GcdPrivatePrefetchWifiPasswordFunction() {
708 } 723 }
709 724
710 bool GcdPrivatePrefetchWifiPasswordFunction::RunAsync() { 725 bool GcdPrivatePrefetchWifiPasswordFunction::RunAsync() {
711 scoped_ptr<gcd_private::PrefetchWifiPassword::Params> params = 726 scoped_ptr<gcd_private::PrefetchWifiPassword::Params> params =
712 gcd_private::PrefetchWifiPassword::Params::Create(*args_); 727 gcd_private::PrefetchWifiPassword::Params::Create(*args_);
713 728
714 if (!params) 729 if (!params)
715 return false; 730 return false;
716 731
717 GcdPrivateAPIImpl* gcd_api = GcdPrivateAPIImpl::Get(GetProfile()); 732 GcdPrivateAPIImpl* gcd_api = GcdPrivateAPIImpl::Get(GetProfile());
718 733
719 if (!gcd_api)
720 return false;
721
722 gcd_api->RequestWifiPassword( 734 gcd_api->RequestWifiPassword(
723 params->ssid, 735 params->ssid,
724 base::Bind(&GcdPrivatePrefetchWifiPasswordFunction::OnResponse, this)); 736 base::Bind(&GcdPrivatePrefetchWifiPasswordFunction::OnResponse, this));
725 737
726 return true; 738 return true;
727 } 739 }
728 740
729 void GcdPrivatePrefetchWifiPasswordFunction::OnResponse(bool response) { 741 void GcdPrivatePrefetchWifiPasswordFunction::OnResponse(bool response) {
730 scoped_ptr<base::FundamentalValue> response_value( 742 scoped_ptr<base::FundamentalValue> response_value(
731 new base::FundamentalValue(response)); 743 new base::FundamentalValue(response));
732 SetResult(response_value.release()); 744 SetResult(response_value.release());
733 SendResponse(true); 745 SendResponse(true);
734 } 746 }
735 747
736 GcdPrivateEstablishSessionFunction::GcdPrivateEstablishSessionFunction() { 748 GcdPrivateEstablishSessionFunction::GcdPrivateEstablishSessionFunction() {
737 } 749 }
738 750
739 GcdPrivateEstablishSessionFunction::~GcdPrivateEstablishSessionFunction() { 751 GcdPrivateEstablishSessionFunction::~GcdPrivateEstablishSessionFunction() {
740 } 752 }
741 753
742 bool GcdPrivateEstablishSessionFunction::RunAsync() { 754 bool GcdPrivateEstablishSessionFunction::RunAsync() {
743 scoped_ptr<gcd_private::EstablishSession::Params> params = 755 scoped_ptr<gcd_private::EstablishSession::Params> params =
744 gcd_private::EstablishSession::Params::Create(*args_); 756 gcd_private::EstablishSession::Params::Create(*args_);
745 757
746 if (!params) 758 if (!params)
747 return false; 759 return false;
748 760
749 GcdPrivateAPIImpl* gcd_api = GcdPrivateAPIImpl::Get(GetProfile()); 761 GcdPrivateAPIImpl* gcd_api = GcdPrivateAPIImpl::Get(GetProfile());
750 762
751 if (!gcd_api)
752 return false;
753
754 gcd_api->EstablishSession( 763 gcd_api->EstablishSession(
755 params->ip_address, 764 params->ip_address,
756 params->port, 765 params->port,
757 base::Bind(&GcdPrivateEstablishSessionFunction::OnConfirmCodeCallback, 766 base::Bind(&GcdPrivateEstablishSessionFunction::OnConfirmCodeCallback,
758 this)); 767 this));
759 768
760 return true; 769 return true;
761 } 770 }
762 771
763 void GcdPrivateEstablishSessionFunction::OnConfirmCodeCallback( 772 void GcdPrivateEstablishSessionFunction::OnConfirmCodeCallback(
(...skipping 14 matching lines...) Expand all
778 787
779 bool GcdPrivateConfirmCodeFunction::RunAsync() { 788 bool GcdPrivateConfirmCodeFunction::RunAsync() {
780 scoped_ptr<gcd_private::ConfirmCode::Params> params = 789 scoped_ptr<gcd_private::ConfirmCode::Params> params =
781 gcd_private::ConfirmCode::Params::Create(*args_); 790 gcd_private::ConfirmCode::Params::Create(*args_);
782 791
783 if (!params) 792 if (!params)
784 return false; 793 return false;
785 794
786 GcdPrivateAPIImpl* gcd_api = GcdPrivateAPIImpl::Get(GetProfile()); 795 GcdPrivateAPIImpl* gcd_api = GcdPrivateAPIImpl::Get(GetProfile());
787 796
788 if (!gcd_api)
789 return false;
790
791 gcd_api->ConfirmCode( 797 gcd_api->ConfirmCode(
792 params->session_id, 798 params->session_id,
793 base::Bind(&GcdPrivateConfirmCodeFunction::OnSessionEstablishedCallback, 799 base::Bind(&GcdPrivateConfirmCodeFunction::OnSessionEstablishedCallback,
794 this)); 800 this));
795 801
796 return true; 802 return true;
797 } 803 }
798 804
799 void GcdPrivateConfirmCodeFunction::OnSessionEstablishedCallback( 805 void GcdPrivateConfirmCodeFunction::OnSessionEstablishedCallback(
800 api::gcd_private::Status status) { 806 api::gcd_private::Status status) {
801 results_ = gcd_private::ConfirmCode::Results::Create(status); 807 results_ = gcd_private::ConfirmCode::Results::Create(status);
802 SendResponse(true); 808 SendResponse(true);
803 } 809 }
804 810
805 GcdPrivateSendMessageFunction::GcdPrivateSendMessageFunction() { 811 GcdPrivateSendMessageFunction::GcdPrivateSendMessageFunction() {
806 } 812 }
807 813
808 GcdPrivateSendMessageFunction::~GcdPrivateSendMessageFunction() { 814 GcdPrivateSendMessageFunction::~GcdPrivateSendMessageFunction() {
809 } 815 }
810 816
811 bool GcdPrivateSendMessageFunction::RunAsync() { 817 bool GcdPrivateSendMessageFunction::RunAsync() {
812 scoped_ptr<gcd_private::PassMessage::Params> params = 818 scoped_ptr<gcd_private::PassMessage::Params> params =
813 gcd_private::PassMessage::Params::Create(*args_); 819 gcd_private::PassMessage::Params::Create(*args_);
814 820
815 if (!params) 821 if (!params)
816 return false; 822 return false;
817 823
818 GcdPrivateAPIImpl* gcd_api = GcdPrivateAPIImpl::Get(GetProfile()); 824 GcdPrivateAPIImpl* gcd_api = GcdPrivateAPIImpl::Get(GetProfile());
819 825
820 if (!gcd_api)
821 return false;
822 826
823 gcd_api->SendMessage( 827 gcd_api->SendMessage(
824 params->session_id, 828 params->session_id,
825 params->api, 829 params->api,
826 params->input.additional_properties, 830 params->input.additional_properties,
827 base::Bind(&GcdPrivateSendMessageFunction::OnMessageSentCallback, this)); 831 base::Bind(&GcdPrivateSendMessageFunction::OnMessageSentCallback, this));
828 832
829 return true; 833 return true;
830 } 834 }
831 835
(...skipping 15 matching lines...) Expand all
847 851
848 bool GcdPrivateTerminateSessionFunction::RunAsync() { 852 bool GcdPrivateTerminateSessionFunction::RunAsync() {
849 scoped_ptr<gcd_private::TerminateSession::Params> params = 853 scoped_ptr<gcd_private::TerminateSession::Params> params =
850 gcd_private::TerminateSession::Params::Create(*args_); 854 gcd_private::TerminateSession::Params::Create(*args_);
851 855
852 if (!params) 856 if (!params)
853 return false; 857 return false;
854 858
855 GcdPrivateAPIImpl* gcd_api = GcdPrivateAPIImpl::Get(GetProfile()); 859 GcdPrivateAPIImpl* gcd_api = GcdPrivateAPIImpl::Get(GetProfile());
856 860
857 if (!gcd_api)
858 return false;
859
860 gcd_api->RemoveSession(params->session_id); 861 gcd_api->RemoveSession(params->session_id);
861 862
862 SendResponse(true); 863 SendResponse(true);
863 return true; 864 return true;
864 } 865 }
865 866
866 GcdPrivateGetCommandDefinitionsFunction:: 867 GcdPrivateGetCommandDefinitionsFunction::
867 GcdPrivateGetCommandDefinitionsFunction() { 868 GcdPrivateGetCommandDefinitionsFunction() {
868 } 869 }
869 870
870 GcdPrivateGetCommandDefinitionsFunction:: 871 GcdPrivateGetCommandDefinitionsFunction::
871 ~GcdPrivateGetCommandDefinitionsFunction() { 872 ~GcdPrivateGetCommandDefinitionsFunction() {
872 } 873 }
873 874
875 GcdPrivateGetPrefetchedWifiNameListFunction::
876 GcdPrivateGetPrefetchedWifiNameListFunction() {
877 }
878
879 GcdPrivateGetPrefetchedWifiNameListFunction::
880 ~GcdPrivateGetPrefetchedWifiNameListFunction() {
881 }
882
883 bool GcdPrivateGetPrefetchedWifiNameListFunction::RunSync() {
884 GcdPrivateAPIImpl* gcd_api = GcdPrivateAPIImpl::Get(GetProfile());
885
886 scoped_ptr<base::ListValue> ssid_list = gcd_api->GetPrefetchedSSIDList();
887
888 SetResult(ssid_list.release());
889
890 return true;
891 }
892
874 bool GcdPrivateGetCommandDefinitionsFunction::RunAsync() { 893 bool GcdPrivateGetCommandDefinitionsFunction::RunAsync() {
875 return false; 894 return false;
876 } 895 }
877 896
878 GcdPrivateInsertCommandFunction::GcdPrivateInsertCommandFunction() { 897 GcdPrivateInsertCommandFunction::GcdPrivateInsertCommandFunction() {
879 } 898 }
880 899
881 GcdPrivateInsertCommandFunction::~GcdPrivateInsertCommandFunction() { 900 GcdPrivateInsertCommandFunction::~GcdPrivateInsertCommandFunction() {
882 } 901 }
883 902
(...skipping 25 matching lines...) Expand all
909 } 928 }
910 929
911 GcdPrivateGetCommandsListFunction::~GcdPrivateGetCommandsListFunction() { 930 GcdPrivateGetCommandsListFunction::~GcdPrivateGetCommandsListFunction() {
912 } 931 }
913 932
914 bool GcdPrivateGetCommandsListFunction::RunAsync() { 933 bool GcdPrivateGetCommandsListFunction::RunAsync() {
915 return false; 934 return false;
916 } 935 }
917 936
918 } // namespace extensions 937 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698