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

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

Issue 1126233004: Persist Instance ID data to GCM store. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix mac Created 5 years, 7 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
« no previous file with comments | « components/gcm_driver/gcm_driver_desktop.h ('k') | components/gcm_driver/instance_id/BUILD.gn » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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"
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 const GCMClient::OutgoingMessage& message); 80 const GCMClient::OutgoingMessage& message);
81 void GetGCMStatistics(bool clear_logs); 81 void GetGCMStatistics(bool clear_logs);
82 void SetGCMRecording(bool recording); 82 void SetGCMRecording(bool recording);
83 83
84 void SetAccountTokens( 84 void SetAccountTokens(
85 const std::vector<GCMClient::AccountTokenInfo>& account_tokens); 85 const std::vector<GCMClient::AccountTokenInfo>& account_tokens);
86 void UpdateAccountMapping(const AccountMapping& account_mapping); 86 void UpdateAccountMapping(const AccountMapping& account_mapping);
87 void RemoveAccountMapping(const std::string& account_id); 87 void RemoveAccountMapping(const std::string& account_id);
88 void SetLastTokenFetchTime(const base::Time& time); 88 void SetLastTokenFetchTime(const base::Time& time);
89 void WakeFromSuspendForHeartbeat(bool wake); 89 void WakeFromSuspendForHeartbeat(bool wake);
90 void AddInstanceIDData(const std::string& app_id,
91 const std::string& instance_id_data);
92 void RemoveInstanceIDData(const std::string& app_id);
93 void GetInstanceIDData(const std::string& app_id);
90 94
91 // For testing purpose. Can be called from UI thread. Use with care. 95 // For testing purpose. Can be called from UI thread. Use with care.
92 GCMClient* gcm_client_for_testing() const { return gcm_client_.get(); } 96 GCMClient* gcm_client_for_testing() const { return gcm_client_.get(); }
93 97
94 private: 98 private:
95 scoped_refptr<base::SequencedTaskRunner> ui_thread_; 99 scoped_refptr<base::SequencedTaskRunner> ui_thread_;
96 scoped_refptr<base::SequencedTaskRunner> io_thread_; 100 scoped_refptr<base::SequencedTaskRunner> io_thread_;
97 101
98 base::WeakPtr<GCMDriverDesktop> service_; 102 base::WeakPtr<GCMDriverDesktop> service_;
99 103
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after
336 gcm_client_->RemoveAccountMapping(account_id); 340 gcm_client_->RemoveAccountMapping(account_id);
337 } 341 }
338 342
339 void GCMDriverDesktop::IOWorker::SetLastTokenFetchTime(const base::Time& time) { 343 void GCMDriverDesktop::IOWorker::SetLastTokenFetchTime(const base::Time& time) {
340 DCHECK(io_thread_->RunsTasksOnCurrentThread()); 344 DCHECK(io_thread_->RunsTasksOnCurrentThread());
341 345
342 if (gcm_client_.get()) 346 if (gcm_client_.get())
343 gcm_client_->SetLastTokenFetchTime(time); 347 gcm_client_->SetLastTokenFetchTime(time);
344 } 348 }
345 349
350 void GCMDriverDesktop::IOWorker::AddInstanceIDData(
351 const std::string& app_id,
352 const std::string& instance_id_data) {
353 DCHECK(io_thread_->RunsTasksOnCurrentThread());
354
355 if (gcm_client_.get())
356 gcm_client_->AddInstanceIDData(app_id, instance_id_data);
357 }
358
359 void GCMDriverDesktop::IOWorker::RemoveInstanceIDData(
360 const std::string& app_id) {
361 DCHECK(io_thread_->RunsTasksOnCurrentThread());
362
363 if (gcm_client_.get())
364 gcm_client_->RemoveInstanceIDData(app_id);
365 }
366
367 void GCMDriverDesktop::IOWorker::GetInstanceIDData(
368 const std::string& app_id) {
369 DCHECK(io_thread_->RunsTasksOnCurrentThread());
370
371 std::string instance_id_data;
372 if (gcm_client_.get())
373 instance_id_data = gcm_client_->GetInstanceIDData(app_id);
374
375 ui_thread_->PostTask(
376 FROM_HERE,
377 base::Bind(&GCMDriverDesktop::GetInstanceIDDataFinished,
378 service_, app_id, instance_id_data));
379 }
380
346 void GCMDriverDesktop::IOWorker::WakeFromSuspendForHeartbeat(bool wake) { 381 void GCMDriverDesktop::IOWorker::WakeFromSuspendForHeartbeat(bool wake) {
347 #if defined(OS_CHROMEOS) 382 #if defined(OS_CHROMEOS)
348 DCHECK(io_thread_->RunsTasksOnCurrentThread()); 383 DCHECK(io_thread_->RunsTasksOnCurrentThread());
349 384
350 scoped_ptr<base::Timer> timer; 385 scoped_ptr<base::Timer> timer;
351 if (wake) 386 if (wake)
352 timer.reset(new timers::SimpleAlarmTimer()); 387 timer.reset(new timers::SimpleAlarmTimer());
353 else 388 else
354 timer.reset(new base::Timer(true, false)); 389 timer.reset(new base::Timer(true, false));
355 390
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after
652 687
653 last_token_fetch_time_ = time; 688 last_token_fetch_time_ = time;
654 689
655 io_thread_->PostTask( 690 io_thread_->PostTask(
656 FROM_HERE, 691 FROM_HERE,
657 base::Bind(&GCMDriverDesktop::IOWorker::SetLastTokenFetchTime, 692 base::Bind(&GCMDriverDesktop::IOWorker::SetLastTokenFetchTime,
658 base::Unretained(io_worker_.get()), 693 base::Unretained(io_worker_.get()),
659 time)); 694 time));
660 } 695 }
661 696
697 InstanceIDStore* GCMDriverDesktop::GetInstanceIDStore() {
698 return this;
699 }
700
701 void GCMDriverDesktop::AddInstanceIDData(
702 const std::string& app_id,
703 const std::string& instance_id_data) {
704 DCHECK(ui_thread_->RunsTasksOnCurrentThread());
705
706 io_thread_->PostTask(
707 FROM_HERE,
708 base::Bind(&GCMDriverDesktop::IOWorker::AddInstanceIDData,
709 base::Unretained(io_worker_.get()),
710 app_id,
711 instance_id_data));
712 }
713
714 void GCMDriverDesktop::RemoveInstanceIDData(const std::string& app_id) {
715 DCHECK(ui_thread_->RunsTasksOnCurrentThread());
716
717 io_thread_->PostTask(
718 FROM_HERE,
719 base::Bind(&GCMDriverDesktop::IOWorker::RemoveInstanceIDData,
720 base::Unretained(io_worker_.get()),
721 app_id));
722 }
723
724 void GCMDriverDesktop::GetInstanceIDData(
725 const std::string& app_id,
726 const GetInstanceIDDataCallback& callback) {
727 DCHECK(!get_instance_id_data_callbacks_.count(app_id));
728 get_instance_id_data_callbacks_[app_id] = callback;
729 io_thread_->PostTask(
730 FROM_HERE,
731 base::Bind(&GCMDriverDesktop::IOWorker::GetInstanceIDData,
732 base::Unretained(io_worker_.get()),
733 app_id));
734 }
735
736 void GCMDriverDesktop::GetInstanceIDDataFinished(
737 const std::string& app_id,
738 const std::string& instance_id_data) {
739 DCHECK(get_instance_id_data_callbacks_.count(app_id));
740 get_instance_id_data_callbacks_[app_id].Run(instance_id_data);
741 get_instance_id_data_callbacks_.erase(app_id);
742 }
743
662 void GCMDriverDesktop::WakeFromSuspendForHeartbeat(bool wake) { 744 void GCMDriverDesktop::WakeFromSuspendForHeartbeat(bool wake) {
663 DCHECK(ui_thread_->RunsTasksOnCurrentThread()); 745 DCHECK(ui_thread_->RunsTasksOnCurrentThread());
664 746
665 wake_from_suspend_enabled_ = wake; 747 wake_from_suspend_enabled_ = wake;
666 748
667 // The GCM service has not been initialized. 749 // The GCM service has not been initialized.
668 if (!delayed_task_controller_) 750 if (!delayed_task_controller_)
669 return; 751 return;
670 752
671 if (!delayed_task_controller_->CanRunTaskWithoutDelay()) { 753 if (!delayed_task_controller_->CanRunTaskWithoutDelay()) {
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
841 DCHECK(ui_thread_->RunsTasksOnCurrentThread()); 923 DCHECK(ui_thread_->RunsTasksOnCurrentThread());
842 924
843 // Normally request_gcm_statistics_callback_ would not be null. 925 // Normally request_gcm_statistics_callback_ would not be null.
844 if (!request_gcm_statistics_callback_.is_null()) 926 if (!request_gcm_statistics_callback_.is_null())
845 request_gcm_statistics_callback_.Run(stats); 927 request_gcm_statistics_callback_.Run(stats);
846 else 928 else
847 LOG(WARNING) << "request_gcm_statistics_callback_ is NULL."; 929 LOG(WARNING) << "request_gcm_statistics_callback_ is NULL.";
848 } 930 }
849 931
850 } // namespace gcm 932 } // namespace gcm
OLDNEW
« no previous file with comments | « components/gcm_driver/gcm_driver_desktop.h ('k') | components/gcm_driver/instance_id/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698