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

Side by Side Diff: components/gcm_driver/gcm_driver_desktop.cc

Issue 2697793004: Push API: Validate storage before returning cached subscriptions (Closed)
Patch Set: Fix include Created 3 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
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 "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"
11 #include "base/files/file_path.h" 11 #include "base/files/file_path.h"
12 #include "base/location.h" 12 #include "base/location.h"
13 #include "base/logging.h" 13 #include "base/logging.h"
14 #include "base/macros.h" 14 #include "base/macros.h"
15 #include "base/memory/ptr_util.h" 15 #include "base/memory/ptr_util.h"
16 #include "base/metrics/histogram_macros.h" 16 #include "base/metrics/histogram_macros.h"
17 #include "base/profiler/scoped_tracker.h" 17 #include "base/profiler/scoped_tracker.h"
18 #include "base/sequenced_task_runner.h" 18 #include "base/sequenced_task_runner.h"
19 #include "base/task_runner_util.h"
19 #include "base/threading/sequenced_worker_pool.h" 20 #include "base/threading/sequenced_worker_pool.h"
20 #include "build/build_config.h" 21 #include "build/build_config.h"
21 #include "components/gcm_driver/gcm_account_mapper.h" 22 #include "components/gcm_driver/gcm_account_mapper.h"
22 #include "components/gcm_driver/gcm_app_handler.h" 23 #include "components/gcm_driver/gcm_app_handler.h"
23 #include "components/gcm_driver/gcm_channel_status_syncer.h" 24 #include "components/gcm_driver/gcm_channel_status_syncer.h"
24 #include "components/gcm_driver/gcm_client_factory.h" 25 #include "components/gcm_driver/gcm_client_factory.h"
25 #include "components/gcm_driver/gcm_delayed_task_controller.h" 26 #include "components/gcm_driver/gcm_delayed_task_controller.h"
26 #include "components/gcm_driver/instance_id/instance_id_impl.h" 27 #include "components/gcm_driver/instance_id/instance_id_impl.h"
27 #include "components/gcm_driver/system_encryptor.h" 28 #include "components/gcm_driver/system_encryptor.h"
28 #include "google_apis/gcm/engine/account_mapping.h" 29 #include "google_apis/gcm/engine/account_mapping.h"
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 99
99 void AddInstanceIDData(const std::string& app_id, 100 void AddInstanceIDData(const std::string& app_id,
100 const std::string& instance_id, 101 const std::string& instance_id,
101 const std::string& extra_data); 102 const std::string& extra_data);
102 void RemoveInstanceIDData(const std::string& app_id); 103 void RemoveInstanceIDData(const std::string& app_id);
103 void GetInstanceIDData(const std::string& app_id); 104 void GetInstanceIDData(const std::string& app_id);
104 void GetToken(const std::string& app_id, 105 void GetToken(const std::string& app_id,
105 const std::string& authorized_entity, 106 const std::string& authorized_entity,
106 const std::string& scope, 107 const std::string& scope,
107 const std::map<std::string, std::string>& options); 108 const std::map<std::string, std::string>& options);
109 bool ValidateRegistration(std::unique_ptr<RegistrationInfo> registration_info,
110 const std::string& registration_id);
108 void DeleteToken(const std::string& app_id, 111 void DeleteToken(const std::string& app_id,
109 const std::string& authorized_entity, 112 const std::string& authorized_entity,
110 const std::string& scope); 113 const std::string& scope);
111 114
112 void RecordDecryptionFailure(const std::string& app_id, 115 void RecordDecryptionFailure(const std::string& app_id,
113 GCMEncryptionProvider::DecryptionResult result); 116 GCMEncryptionProvider::DecryptionResult result);
114 117
115 // For testing purpose. Can be called from UI thread. Use with care. 118 // For testing purpose. Can be called from UI thread. Use with care.
116 GCMClient* gcm_client_for_testing() const { return gcm_client_.get(); } 119 GCMClient* gcm_client_for_testing() const { return gcm_client_.get(); }
117 120
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after
328 const std::string& app_id, 331 const std::string& app_id,
329 const std::vector<std::string>& sender_ids) { 332 const std::vector<std::string>& sender_ids) {
330 DCHECK(io_thread_->RunsTasksOnCurrentThread()); 333 DCHECK(io_thread_->RunsTasksOnCurrentThread());
331 334
332 std::unique_ptr<GCMRegistrationInfo> gcm_info(new GCMRegistrationInfo); 335 std::unique_ptr<GCMRegistrationInfo> gcm_info(new GCMRegistrationInfo);
333 gcm_info->app_id = app_id; 336 gcm_info->app_id = app_id;
334 gcm_info->sender_ids = sender_ids; 337 gcm_info->sender_ids = sender_ids;
335 gcm_client_->Register(make_linked_ptr<RegistrationInfo>(gcm_info.release())); 338 gcm_client_->Register(make_linked_ptr<RegistrationInfo>(gcm_info.release()));
336 } 339 }
337 340
341 bool GCMDriverDesktop::IOWorker::ValidateRegistration(
342 std::unique_ptr<RegistrationInfo> registration_info,
343 const std::string& registration_id) {
344 DCHECK(io_thread_->RunsTasksOnCurrentThread());
345
346 return gcm_client_->ValidateRegistration(
347 make_linked_ptr(registration_info.release()), registration_id);
348 }
349
338 void GCMDriverDesktop::IOWorker::Unregister(const std::string& app_id) { 350 void GCMDriverDesktop::IOWorker::Unregister(const std::string& app_id) {
339 DCHECK(io_thread_->RunsTasksOnCurrentThread()); 351 DCHECK(io_thread_->RunsTasksOnCurrentThread());
340 352
341 std::unique_ptr<GCMRegistrationInfo> gcm_info(new GCMRegistrationInfo); 353 std::unique_ptr<GCMRegistrationInfo> gcm_info(new GCMRegistrationInfo);
342 gcm_info->app_id = app_id; 354 gcm_info->app_id = app_id;
343 gcm_client_->Unregister( 355 gcm_client_->Unregister(
344 make_linked_ptr<RegistrationInfo>(gcm_info.release())); 356 make_linked_ptr<RegistrationInfo>(gcm_info.release()));
345 } 357 }
346 358
347 void GCMDriverDesktop::IOWorker::Send(const std::string& app_id, 359 void GCMDriverDesktop::IOWorker::Send(const std::string& app_id,
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
553 base::Passed(&gcm_client_factory), 565 base::Passed(&gcm_client_factory),
554 chrome_build_info, 566 chrome_build_info,
555 store_path, 567 store_path,
556 request_context, 568 request_context,
557 blocking_task_runner)); 569 blocking_task_runner));
558 } 570 }
559 571
560 GCMDriverDesktop::~GCMDriverDesktop() { 572 GCMDriverDesktop::~GCMDriverDesktop() {
561 } 573 }
562 574
575 void GCMDriverDesktop::ValidateRegistration(
576 const std::string& app_id,
577 const std::vector<std::string>& sender_ids,
578 const std::string& registration_id,
579 const ValidateRegistrationCallback& callback) {
580 DCHECK(!app_id.empty());
581 DCHECK(!sender_ids.empty() && sender_ids.size() <= kMaxSenders);
582 DCHECK(!registration_id.empty());
583 DCHECK(!callback.is_null());
584 DCHECK(ui_thread_->RunsTasksOnCurrentThread());
585
586 GCMClient::Result result = EnsureStarted(GCMClient::IMMEDIATE_START);
587 if (result != GCMClient::SUCCESS) {
588 // Can't tell whether the registration is valid or not, so don't run the
589 // callback (let it hang indefinitely).
590 return;
591 }
592
593 // Only validating current state, so ignore pending register_callbacks_.
594
595 auto gcm_info = base::MakeUnique<GCMRegistrationInfo>();
596 gcm_info->app_id = app_id;
597 gcm_info->sender_ids = sender_ids;
598 // Normalize the sender IDs by making them sorted.
599 std::sort(gcm_info->sender_ids.begin(), gcm_info->sender_ids.end());
600
601 if (!delayed_task_controller_->CanRunTaskWithoutDelay()) {
602 delayed_task_controller_->AddTask(
603 base::Bind(&GCMDriverDesktop::DoValidateRegistration,
604 weak_ptr_factory_.GetWeakPtr(), base::Passed(&gcm_info),
605 registration_id, callback));
606 return;
607 }
608
609 DoValidateRegistration(std::move(gcm_info), registration_id, callback);
610 }
611
612 void GCMDriverDesktop::DoValidateRegistration(
613 std::unique_ptr<RegistrationInfo> registration_info,
614 const std::string& registration_id,
615 const ValidateRegistrationCallback& callback) {
616 base::PostTaskAndReplyWithResult(
617 io_thread_.get(), FROM_HERE,
618 base::Bind(&GCMDriverDesktop::IOWorker::ValidateRegistration,
619 base::Unretained(io_worker_.get()),
620 base::Passed(&registration_info), registration_id),
621 callback);
622 }
623
563 void GCMDriverDesktop::Shutdown() { 624 void GCMDriverDesktop::Shutdown() {
564 DCHECK(ui_thread_->RunsTasksOnCurrentThread()); 625 DCHECK(ui_thread_->RunsTasksOnCurrentThread());
565 626
566 Stop(); 627 Stop();
567 GCMDriver::Shutdown(); 628 GCMDriver::Shutdown();
568 629
569 // Dispose the syncer in order to release the reference to 630 // Dispose the syncer in order to release the reference to
570 // URLRequestContextGetter that needs to be done before IOThread gets 631 // URLRequestContextGetter that needs to be done before IOThread gets
571 // deleted. 632 // deleted.
572 gcm_channel_status_syncer_.reset(); 633 gcm_channel_status_syncer_.reset();
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after
887 io_thread_->PostTask( 948 io_thread_->PostTask(
888 FROM_HERE, 949 FROM_HERE,
889 base::Bind(&GCMDriverDesktop::IOWorker::GetToken, 950 base::Bind(&GCMDriverDesktop::IOWorker::GetToken,
890 base::Unretained(io_worker_.get()), 951 base::Unretained(io_worker_.get()),
891 app_id, 952 app_id,
892 authorized_entity, 953 authorized_entity,
893 scope, 954 scope,
894 options)); 955 options));
895 } 956 }
896 957
958 void GCMDriverDesktop::ValidateToken(const std::string& app_id,
959 const std::string& authorized_entity,
960 const std::string& scope,
961 const std::string& token,
962 const ValidateTokenCallback& callback) {
963 DCHECK(!app_id.empty());
964 DCHECK(!authorized_entity.empty());
965 DCHECK(!scope.empty());
966 DCHECK(!token.empty());
967 DCHECK(!callback.is_null());
968 DCHECK(ui_thread_->RunsTasksOnCurrentThread());
969
970 GCMClient::Result result = EnsureStarted(GCMClient::IMMEDIATE_START);
971 if (result != GCMClient::SUCCESS) {
972 // Can't tell whether the registration is valid or not, so don't run the
973 // callback (let it hang indefinitely).
974 return;
975 }
976
977 // Only validating current state, so ignore pending get_token_callbacks_.
978
979 auto instance_id_info = base::MakeUnique<InstanceIDTokenInfo>();
980 instance_id_info->app_id = app_id;
981 instance_id_info->authorized_entity = authorized_entity;
982 instance_id_info->scope = scope;
983
984 if (!delayed_task_controller_->CanRunTaskWithoutDelay()) {
985 delayed_task_controller_->AddTask(
986 base::Bind(&GCMDriverDesktop::DoValidateRegistration,
987 weak_ptr_factory_.GetWeakPtr(),
988 base::Passed(&instance_id_info), token, callback));
989 return;
990 }
991
992 DoValidateRegistration(std::move(instance_id_info), token, callback);
993 }
994
897 void GCMDriverDesktop::DeleteToken(const std::string& app_id, 995 void GCMDriverDesktop::DeleteToken(const std::string& app_id,
898 const std::string& authorized_entity, 996 const std::string& authorized_entity,
899 const std::string& scope, 997 const std::string& scope,
900 const DeleteTokenCallback& callback) { 998 const DeleteTokenCallback& callback) {
901 DCHECK(!app_id.empty()); 999 DCHECK(!app_id.empty());
902 DCHECK(!authorized_entity.empty()); 1000 DCHECK(!authorized_entity.empty());
903 DCHECK(!scope.empty()); 1001 DCHECK(!scope.empty());
904 DCHECK(!callback.is_null()); 1002 DCHECK(!callback.is_null());
905 DCHECK(ui_thread_->RunsTasksOnCurrentThread()); 1003 DCHECK(ui_thread_->RunsTasksOnCurrentThread());
906 1004
(...skipping 435 matching lines...) Expand 10 before | Expand all | Expand 10 after
1342 1440
1343 if (std::get<1>(a) < std::get<1>(b)) 1441 if (std::get<1>(a) < std::get<1>(b))
1344 return true; 1442 return true;
1345 if (std::get<1>(a) > std::get<1>(b)) 1443 if (std::get<1>(a) > std::get<1>(b))
1346 return false; 1444 return false;
1347 1445
1348 return std::get<2>(a) < std::get<2>(b); 1446 return std::get<2>(a) < std::get<2>(b);
1349 } 1447 }
1350 1448
1351 } // namespace gcm 1449 } // namespace gcm
OLDNEW
« no previous file with comments | « components/gcm_driver/gcm_driver_desktop.h ('k') | components/gcm_driver/instance_id/fake_gcm_driver_for_instance_id.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698