| 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 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 AddHeartbeatInterval(const std::string& scope, int interval_ms); |
| 91 void RemoveHeartbeatInterval(const std::string& scope); |
| 90 | 92 |
| 91 // For testing purpose. Can be called from UI thread. Use with care. | 93 // For testing purpose. Can be called from UI thread. Use with care. |
| 92 GCMClient* gcm_client_for_testing() const { return gcm_client_.get(); } | 94 GCMClient* gcm_client_for_testing() const { return gcm_client_.get(); } |
| 93 | 95 |
| 94 private: | 96 private: |
| 95 scoped_refptr<base::SequencedTaskRunner> ui_thread_; | 97 scoped_refptr<base::SequencedTaskRunner> ui_thread_; |
| 96 scoped_refptr<base::SequencedTaskRunner> io_thread_; | 98 scoped_refptr<base::SequencedTaskRunner> io_thread_; |
| 97 | 99 |
| 98 base::WeakPtr<GCMDriverDesktop> service_; | 100 base::WeakPtr<GCMDriverDesktop> service_; |
| 99 | 101 |
| (...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 350 scoped_ptr<base::Timer> timer; | 352 scoped_ptr<base::Timer> timer; |
| 351 if (wake) | 353 if (wake) |
| 352 timer.reset(new timers::SimpleAlarmTimer()); | 354 timer.reset(new timers::SimpleAlarmTimer()); |
| 353 else | 355 else |
| 354 timer.reset(new base::Timer(true, false)); | 356 timer.reset(new base::Timer(true, false)); |
| 355 | 357 |
| 356 gcm_client_->UpdateHeartbeatTimer(timer.Pass()); | 358 gcm_client_->UpdateHeartbeatTimer(timer.Pass()); |
| 357 #endif | 359 #endif |
| 358 } | 360 } |
| 359 | 361 |
| 362 void GCMDriverDesktop::IOWorker::AddHeartbeatInterval( |
| 363 const std::string& scope, |
| 364 int interval_ms) { |
| 365 DCHECK(io_thread_->RunsTasksOnCurrentThread()); |
| 366 gcm_client_->AddHeartbeatInterval(scope, interval_ms); |
| 367 } |
| 368 |
| 369 void GCMDriverDesktop::IOWorker::RemoveHeartbeatInterval( |
| 370 const std::string& scope) { |
| 371 DCHECK(io_thread_->RunsTasksOnCurrentThread()); |
| 372 gcm_client_->RemoveHeartbeatInterval(scope); |
| 373 } |
| 374 |
| 360 GCMDriverDesktop::GCMDriverDesktop( | 375 GCMDriverDesktop::GCMDriverDesktop( |
| 361 scoped_ptr<GCMClientFactory> gcm_client_factory, | 376 scoped_ptr<GCMClientFactory> gcm_client_factory, |
| 362 const GCMClient::ChromeBuildInfo& chrome_build_info, | 377 const GCMClient::ChromeBuildInfo& chrome_build_info, |
| 363 const std::string& channel_status_request_url, | 378 const std::string& channel_status_request_url, |
| 364 const std::string& user_agent, | 379 const std::string& user_agent, |
| 365 PrefService* prefs, | 380 PrefService* prefs, |
| 366 const base::FilePath& store_path, | 381 const base::FilePath& store_path, |
| 367 const scoped_refptr<net::URLRequestContextGetter>& request_context, | 382 const scoped_refptr<net::URLRequestContextGetter>& request_context, |
| 368 const scoped_refptr<base::SequencedTaskRunner>& ui_thread, | 383 const scoped_refptr<base::SequencedTaskRunner>& ui_thread, |
| 369 const scoped_refptr<base::SequencedTaskRunner>& io_thread, | 384 const scoped_refptr<base::SequencedTaskRunner>& io_thread, |
| (...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 679 | 694 |
| 680 // The GCMClient is ready so we can go ahead and post this task to the | 695 // The GCMClient is ready so we can go ahead and post this task to the |
| 681 // IOWorker. | 696 // IOWorker. |
| 682 io_thread_->PostTask( | 697 io_thread_->PostTask( |
| 683 FROM_HERE, | 698 FROM_HERE, |
| 684 base::Bind(&GCMDriverDesktop::IOWorker::WakeFromSuspendForHeartbeat, | 699 base::Bind(&GCMDriverDesktop::IOWorker::WakeFromSuspendForHeartbeat, |
| 685 base::Unretained(io_worker_.get()), | 700 base::Unretained(io_worker_.get()), |
| 686 wake_from_suspend_enabled_)); | 701 wake_from_suspend_enabled_)); |
| 687 } | 702 } |
| 688 | 703 |
| 704 void GCMDriverDesktop::AddHeartbeatInterval(const std::string& scope, |
| 705 int interval_ms) { |
| 706 DCHECK(ui_thread_->RunsTasksOnCurrentThread()); |
| 707 |
| 708 io_thread_->PostTask( |
| 709 FROM_HERE, |
| 710 base::Bind(&GCMDriverDesktop::IOWorker::AddHeartbeatInterval, |
| 711 base::Unretained(io_worker_.get()), |
| 712 scope, |
| 713 interval_ms)); |
| 714 } |
| 715 |
| 716 void GCMDriverDesktop::RemoveHeartbeatInterval(const std::string& scope) { |
| 717 DCHECK(ui_thread_->RunsTasksOnCurrentThread()); |
| 718 |
| 719 io_thread_->PostTask( |
| 720 FROM_HERE, |
| 721 base::Bind(&GCMDriverDesktop::IOWorker::RemoveHeartbeatInterval, |
| 722 base::Unretained(io_worker_.get()), |
| 723 scope)); |
| 724 } |
| 725 |
| 689 void GCMDriverDesktop::SetAccountTokens( | 726 void GCMDriverDesktop::SetAccountTokens( |
| 690 const std::vector<GCMClient::AccountTokenInfo>& account_tokens) { | 727 const std::vector<GCMClient::AccountTokenInfo>& account_tokens) { |
| 691 DCHECK(ui_thread_->RunsTasksOnCurrentThread()); | 728 DCHECK(ui_thread_->RunsTasksOnCurrentThread()); |
| 692 | 729 |
| 693 account_mapper_->SetAccountTokens(account_tokens); | 730 account_mapper_->SetAccountTokens(account_tokens); |
| 694 | 731 |
| 695 io_thread_->PostTask( | 732 io_thread_->PostTask( |
| 696 FROM_HERE, | 733 FROM_HERE, |
| 697 base::Bind(&GCMDriverDesktop::IOWorker::SetAccountTokens, | 734 base::Bind(&GCMDriverDesktop::IOWorker::SetAccountTokens, |
| 698 base::Unretained(io_worker_.get()), | 735 base::Unretained(io_worker_.get()), |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 841 DCHECK(ui_thread_->RunsTasksOnCurrentThread()); | 878 DCHECK(ui_thread_->RunsTasksOnCurrentThread()); |
| 842 | 879 |
| 843 // Normally request_gcm_statistics_callback_ would not be null. | 880 // Normally request_gcm_statistics_callback_ would not be null. |
| 844 if (!request_gcm_statistics_callback_.is_null()) | 881 if (!request_gcm_statistics_callback_.is_null()) |
| 845 request_gcm_statistics_callback_.Run(stats); | 882 request_gcm_statistics_callback_.Run(stats); |
| 846 else | 883 else |
| 847 LOG(WARNING) << "request_gcm_statistics_callback_ is NULL."; | 884 LOG(WARNING) << "request_gcm_statistics_callback_ is NULL."; |
| 848 } | 885 } |
| 849 | 886 |
| 850 } // namespace gcm | 887 } // namespace gcm |
| OLD | NEW |