OLD | NEW |
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 "components/gcm_driver/gcm_driver_desktop.h" | 5 #include "components/gcm_driver/gcm_driver_desktop.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 void WakeFromSuspendForHeartbeat(bool wake); | 94 void WakeFromSuspendForHeartbeat(bool wake); |
95 void AddHeartbeatInterval(const std::string& scope, int interval_ms); | 95 void AddHeartbeatInterval(const std::string& scope, int interval_ms); |
96 void RemoveHeartbeatInterval(const std::string& scope); | 96 void RemoveHeartbeatInterval(const std::string& scope); |
97 | 97 |
98 void AddInstanceIDData(const std::string& app_id, | 98 void AddInstanceIDData(const std::string& app_id, |
99 const std::string& instance_id, | 99 const std::string& instance_id, |
100 const std::string& extra_data); | 100 const std::string& extra_data); |
101 void RemoveInstanceIDData(const std::string& app_id); | 101 void RemoveInstanceIDData(const std::string& app_id); |
102 void GetInstanceIDData(const std::string& app_id); | 102 void GetInstanceIDData(const std::string& app_id); |
103 void GetToken(const std::string& app_id, | 103 void GetToken(const std::string& app_id, |
| 104 bool use_subtype, |
104 const std::string& authorized_entity, | 105 const std::string& authorized_entity, |
105 const std::string& scope, | 106 const std::string& scope, |
106 const std::map<std::string, std::string>& options); | 107 const std::map<std::string, std::string>& options); |
107 void DeleteToken(const std::string& app_id, | 108 void DeleteToken(const std::string& app_id, |
| 109 bool use_subtype, |
108 const std::string& authorized_entity, | 110 const std::string& authorized_entity, |
109 const std::string& scope); | 111 const std::string& scope); |
110 | 112 |
111 void RecordDecryptionFailure(const std::string& app_id, | 113 void RecordDecryptionFailure(const std::string& app_id, |
112 GCMEncryptionProvider::DecryptionResult result); | 114 GCMEncryptionProvider::DecryptionResult result); |
113 | 115 |
114 // For testing purpose. Can be called from UI thread. Use with care. | 116 // For testing purpose. Can be called from UI thread. Use with care. |
115 GCMClient* gcm_client_for_testing() const { return gcm_client_.get(); } | 117 GCMClient* gcm_client_for_testing() const { return gcm_client_.get(); } |
116 | 118 |
117 private: | 119 private: |
(...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
436 gcm_client_->GetInstanceIDData(app_id, &instance_id, &extra_data); | 438 gcm_client_->GetInstanceIDData(app_id, &instance_id, &extra_data); |
437 | 439 |
438 ui_thread_->PostTask( | 440 ui_thread_->PostTask( |
439 FROM_HERE, | 441 FROM_HERE, |
440 base::Bind(&GCMDriverDesktop::GetInstanceIDDataFinished, | 442 base::Bind(&GCMDriverDesktop::GetInstanceIDDataFinished, |
441 service_, app_id, instance_id, extra_data)); | 443 service_, app_id, instance_id, extra_data)); |
442 } | 444 } |
443 | 445 |
444 void GCMDriverDesktop::IOWorker::GetToken( | 446 void GCMDriverDesktop::IOWorker::GetToken( |
445 const std::string& app_id, | 447 const std::string& app_id, |
| 448 bool use_subtype, |
446 const std::string& authorized_entity, | 449 const std::string& authorized_entity, |
447 const std::string& scope, | 450 const std::string& scope, |
448 const std::map<std::string, std::string>& options) { | 451 const std::map<std::string, std::string>& options) { |
449 DCHECK(io_thread_->RunsTasksOnCurrentThread()); | 452 DCHECK(io_thread_->RunsTasksOnCurrentThread()); |
450 | 453 |
451 std::unique_ptr<InstanceIDTokenInfo> instance_id_token_info( | 454 std::unique_ptr<InstanceIDTokenInfo> instance_id_token_info( |
452 new InstanceIDTokenInfo); | 455 new InstanceIDTokenInfo); |
453 instance_id_token_info->app_id = app_id; | 456 instance_id_token_info->app_id = app_id; |
| 457 instance_id_token_info->use_subtype = use_subtype; |
454 instance_id_token_info->authorized_entity = authorized_entity; | 458 instance_id_token_info->authorized_entity = authorized_entity; |
455 instance_id_token_info->scope = scope; | 459 instance_id_token_info->scope = scope; |
456 instance_id_token_info->options = options; | 460 instance_id_token_info->options = options; |
457 gcm_client_->Register( | 461 gcm_client_->Register( |
458 make_linked_ptr<RegistrationInfo>(instance_id_token_info.release())); | 462 make_linked_ptr<RegistrationInfo>(instance_id_token_info.release())); |
459 } | 463 } |
460 | 464 |
461 void GCMDriverDesktop::IOWorker::DeleteToken( | 465 void GCMDriverDesktop::IOWorker::DeleteToken( |
462 const std::string& app_id, | 466 const std::string& app_id, |
| 467 bool use_subtype, |
463 const std::string& authorized_entity, | 468 const std::string& authorized_entity, |
464 const std::string& scope) { | 469 const std::string& scope) { |
465 std::unique_ptr<InstanceIDTokenInfo> instance_id_token_info( | 470 std::unique_ptr<InstanceIDTokenInfo> instance_id_token_info( |
466 new InstanceIDTokenInfo); | 471 new InstanceIDTokenInfo); |
467 instance_id_token_info->app_id = app_id; | 472 instance_id_token_info->app_id = app_id; |
| 473 instance_id_token_info->use_subtype = use_subtype; |
468 instance_id_token_info->authorized_entity = authorized_entity; | 474 instance_id_token_info->authorized_entity = authorized_entity; |
469 instance_id_token_info->scope = scope; | 475 instance_id_token_info->scope = scope; |
470 gcm_client_->Unregister( | 476 gcm_client_->Unregister( |
471 make_linked_ptr<RegistrationInfo>(instance_id_token_info.release())); | 477 make_linked_ptr<RegistrationInfo>(instance_id_token_info.release())); |
472 } | 478 } |
473 | 479 |
474 void GCMDriverDesktop::IOWorker::WakeFromSuspendForHeartbeat(bool wake) { | 480 void GCMDriverDesktop::IOWorker::WakeFromSuspendForHeartbeat(bool wake) { |
475 #if defined(OS_CHROMEOS) | 481 #if defined(OS_CHROMEOS) |
476 DCHECK(io_thread_->RunsTasksOnCurrentThread()); | 482 DCHECK(io_thread_->RunsTasksOnCurrentThread()); |
477 | 483 |
(...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
817 base::Unretained(io_worker_.get()), | 823 base::Unretained(io_worker_.get()), |
818 time)); | 824 time)); |
819 } | 825 } |
820 | 826 |
821 InstanceIDHandler* GCMDriverDesktop::GetInstanceIDHandlerInternal() { | 827 InstanceIDHandler* GCMDriverDesktop::GetInstanceIDHandlerInternal() { |
822 return this; | 828 return this; |
823 } | 829 } |
824 | 830 |
825 void GCMDriverDesktop::GetToken( | 831 void GCMDriverDesktop::GetToken( |
826 const std::string& app_id, | 832 const std::string& app_id, |
| 833 bool use_subtype, |
827 const std::string& authorized_entity, | 834 const std::string& authorized_entity, |
828 const std::string& scope, | 835 const std::string& scope, |
829 const std::map<std::string, std::string>& options, | 836 const std::map<std::string, std::string>& options, |
830 const GetTokenCallback& callback) { | 837 const GetTokenCallback& callback) { |
831 DCHECK(!app_id.empty()); | 838 DCHECK(!app_id.empty()); |
832 DCHECK(!authorized_entity.empty()); | 839 DCHECK(!authorized_entity.empty()); |
833 DCHECK(!scope.empty()); | 840 DCHECK(!scope.empty()); |
834 DCHECK(!callback.is_null()); | 841 DCHECK(!callback.is_null()); |
835 DCHECK(ui_thread_->RunsTasksOnCurrentThread()); | 842 DCHECK(ui_thread_->RunsTasksOnCurrentThread()); |
836 | 843 |
837 GCMClient::Result result = EnsureStarted(GCMClient::IMMEDIATE_START); | 844 GCMClient::Result result = EnsureStarted(GCMClient::IMMEDIATE_START); |
838 if (result != GCMClient::SUCCESS) { | 845 if (result != GCMClient::SUCCESS) { |
839 callback.Run(std::string(), result); | 846 callback.Run(std::string(), result); |
840 return; | 847 return; |
841 } | 848 } |
842 | 849 |
843 // If previous GetToken operation is still in progress, bail out. | 850 // If previous GetToken operation is still in progress, bail out. |
844 TokenTuple tuple_key(app_id, authorized_entity, scope); | 851 TokenTuple tuple_key(app_id, authorized_entity, scope); |
845 if (get_token_callbacks_.find(tuple_key) != get_token_callbacks_.end()) { | 852 if (get_token_callbacks_.find(tuple_key) != get_token_callbacks_.end()) { |
846 callback.Run(std::string(), GCMClient::ASYNC_OPERATION_PENDING); | 853 callback.Run(std::string(), GCMClient::ASYNC_OPERATION_PENDING); |
847 return; | 854 return; |
848 } | 855 } |
849 | 856 |
850 get_token_callbacks_[tuple_key] = callback; | 857 get_token_callbacks_[tuple_key] = callback; |
851 | 858 |
852 // Delay the GetToken operation until GCMClient is ready. | 859 // Delay the GetToken operation until GCMClient is ready. |
853 if (!delayed_task_controller_->CanRunTaskWithoutDelay()) { | 860 if (!delayed_task_controller_->CanRunTaskWithoutDelay()) { |
854 delayed_task_controller_->AddTask( | 861 delayed_task_controller_->AddTask(base::Bind( |
855 base::Bind(&GCMDriverDesktop::DoGetToken, | 862 &GCMDriverDesktop::DoGetToken, weak_ptr_factory_.GetWeakPtr(), app_id, |
856 weak_ptr_factory_.GetWeakPtr(), | 863 use_subtype, authorized_entity, scope, options)); |
857 app_id, | |
858 authorized_entity, | |
859 scope, | |
860 options)); | |
861 return; | 864 return; |
862 } | 865 } |
863 | 866 |
864 DoGetToken(app_id, authorized_entity, scope, options); | 867 DoGetToken(app_id, use_subtype, authorized_entity, scope, options); |
865 } | 868 } |
866 | 869 |
867 void GCMDriverDesktop::DoGetToken( | 870 void GCMDriverDesktop::DoGetToken( |
868 const std::string& app_id, | 871 const std::string& app_id, |
| 872 bool use_subtype, |
869 const std::string& authorized_entity, | 873 const std::string& authorized_entity, |
870 const std::string& scope, | 874 const std::string& scope, |
871 const std::map<std::string, std::string>& options) { | 875 const std::map<std::string, std::string>& options) { |
872 DCHECK(ui_thread_->RunsTasksOnCurrentThread()); | 876 DCHECK(ui_thread_->RunsTasksOnCurrentThread()); |
873 | 877 |
874 TokenTuple tuple_key(app_id, authorized_entity, scope); | 878 TokenTuple tuple_key(app_id, authorized_entity, scope); |
875 auto callback_iter = get_token_callbacks_.find(tuple_key); | 879 auto callback_iter = get_token_callbacks_.find(tuple_key); |
876 if (callback_iter == get_token_callbacks_.end()) { | 880 if (callback_iter == get_token_callbacks_.end()) { |
877 // The callback could have been removed when the app is uninstalled. | 881 // The callback could have been removed when the app is uninstalled. |
878 return; | 882 return; |
879 } | 883 } |
880 | 884 |
881 io_thread_->PostTask( | 885 io_thread_->PostTask( |
882 FROM_HERE, | 886 FROM_HERE, base::Bind(&GCMDriverDesktop::IOWorker::GetToken, |
883 base::Bind(&GCMDriverDesktop::IOWorker::GetToken, | 887 base::Unretained(io_worker_.get()), app_id, |
884 base::Unretained(io_worker_.get()), | 888 use_subtype, authorized_entity, scope, options)); |
885 app_id, | |
886 authorized_entity, | |
887 scope, | |
888 options)); | |
889 } | 889 } |
890 | 890 |
891 void GCMDriverDesktop::DeleteToken(const std::string& app_id, | 891 void GCMDriverDesktop::DeleteToken(const std::string& app_id, |
| 892 bool use_subtype, |
892 const std::string& authorized_entity, | 893 const std::string& authorized_entity, |
893 const std::string& scope, | 894 const std::string& scope, |
894 const DeleteTokenCallback& callback) { | 895 const DeleteTokenCallback& callback) { |
895 DCHECK(!app_id.empty()); | 896 DCHECK(!app_id.empty()); |
896 DCHECK(!authorized_entity.empty()); | 897 DCHECK(!authorized_entity.empty()); |
897 DCHECK(!scope.empty()); | 898 DCHECK(!scope.empty()); |
898 DCHECK(!callback.is_null()); | 899 DCHECK(!callback.is_null()); |
899 DCHECK(ui_thread_->RunsTasksOnCurrentThread()); | 900 DCHECK(ui_thread_->RunsTasksOnCurrentThread()); |
900 | 901 |
901 GCMClient::Result result = EnsureStarted(GCMClient::IMMEDIATE_START); | 902 GCMClient::Result result = EnsureStarted(GCMClient::IMMEDIATE_START); |
902 if (result != GCMClient::SUCCESS) { | 903 if (result != GCMClient::SUCCESS) { |
903 callback.Run(result); | 904 callback.Run(result); |
904 return; | 905 return; |
905 } | 906 } |
906 | 907 |
907 // If previous GetToken operation is still in progress, bail out. | 908 // If previous GetToken operation is still in progress, bail out. |
908 TokenTuple tuple_key(app_id, authorized_entity, scope); | 909 TokenTuple tuple_key(app_id, authorized_entity, scope); |
909 if (delete_token_callbacks_.find(tuple_key) != | 910 if (delete_token_callbacks_.find(tuple_key) != |
910 delete_token_callbacks_.end()) { | 911 delete_token_callbacks_.end()) { |
911 callback.Run(GCMClient::ASYNC_OPERATION_PENDING); | 912 callback.Run(GCMClient::ASYNC_OPERATION_PENDING); |
912 return; | 913 return; |
913 } | 914 } |
914 | 915 |
915 delete_token_callbacks_[tuple_key] = callback; | 916 delete_token_callbacks_[tuple_key] = callback; |
916 | 917 |
917 // Delay the DeleteToken operation until GCMClient is ready. | 918 // Delay the DeleteToken operation until GCMClient is ready. |
918 if (!delayed_task_controller_->CanRunTaskWithoutDelay()) { | 919 if (!delayed_task_controller_->CanRunTaskWithoutDelay()) { |
919 delayed_task_controller_->AddTask( | 920 delayed_task_controller_->AddTask(base::Bind( |
920 base::Bind(&GCMDriverDesktop::DoDeleteToken, | 921 &GCMDriverDesktop::DoDeleteToken, weak_ptr_factory_.GetWeakPtr(), |
921 weak_ptr_factory_.GetWeakPtr(), | 922 app_id, use_subtype, authorized_entity, scope)); |
922 app_id, | |
923 authorized_entity, | |
924 scope)); | |
925 return; | 923 return; |
926 } | 924 } |
927 | 925 |
928 DoDeleteToken(app_id, authorized_entity, scope); | 926 DoDeleteToken(app_id, use_subtype, authorized_entity, scope); |
929 } | 927 } |
930 | 928 |
931 void GCMDriverDesktop::DoDeleteToken(const std::string& app_id, | 929 void GCMDriverDesktop::DoDeleteToken(const std::string& app_id, |
| 930 bool use_subtype, |
932 const std::string& authorized_entity, | 931 const std::string& authorized_entity, |
933 const std::string& scope) { | 932 const std::string& scope) { |
934 DCHECK(ui_thread_->RunsTasksOnCurrentThread()); | 933 DCHECK(ui_thread_->RunsTasksOnCurrentThread()); |
935 | 934 |
936 io_thread_->PostTask( | 935 io_thread_->PostTask(FROM_HERE, |
937 FROM_HERE, | 936 base::Bind(&GCMDriverDesktop::IOWorker::DeleteToken, |
938 base::Bind(&GCMDriverDesktop::IOWorker::DeleteToken, | 937 base::Unretained(io_worker_.get()), app_id, |
939 base::Unretained(io_worker_.get()), | 938 use_subtype, authorized_entity, scope)); |
940 app_id, | |
941 authorized_entity, | |
942 scope)); | |
943 } | 939 } |
944 | 940 |
945 void GCMDriverDesktop::AddInstanceIDData( | 941 void GCMDriverDesktop::AddInstanceIDData( |
946 const std::string& app_id, | 942 const std::string& app_id, |
947 const std::string& instance_id, | 943 const std::string& instance_id, |
948 const std::string& extra_data) { | 944 const std::string& extra_data) { |
949 DCHECK(ui_thread_->RunsTasksOnCurrentThread()); | 945 DCHECK(ui_thread_->RunsTasksOnCurrentThread()); |
950 | 946 |
951 GCMClient::Result result = EnsureStarted(GCMClient::IMMEDIATE_START); | 947 GCMClient::Result result = EnsureStarted(GCMClient::IMMEDIATE_START); |
952 if (result != GCMClient::SUCCESS) | 948 if (result != GCMClient::SUCCESS) |
(...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1320 | 1316 |
1321 if (std::get<1>(a) < std::get<1>(b)) | 1317 if (std::get<1>(a) < std::get<1>(b)) |
1322 return true; | 1318 return true; |
1323 if (std::get<1>(a) > std::get<1>(b)) | 1319 if (std::get<1>(a) > std::get<1>(b)) |
1324 return false; | 1320 return false; |
1325 | 1321 |
1326 return std::get<2>(a) < std::get<2>(b); | 1322 return std::get<2>(a) < std::get<2>(b); |
1327 } | 1323 } |
1328 | 1324 |
1329 } // namespace gcm | 1325 } // namespace gcm |
OLD | NEW |