| 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 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 | 63 |
| 64 // Called on IO thread. | 64 // Called on IO thread. |
| 65 void Initialize( | 65 void Initialize( |
| 66 scoped_ptr<GCMClientFactory> gcm_client_factory, | 66 scoped_ptr<GCMClientFactory> gcm_client_factory, |
| 67 const GCMClient::ChromeBuildInfo& chrome_build_info, | 67 const GCMClient::ChromeBuildInfo& chrome_build_info, |
| 68 const base::FilePath& store_path, | 68 const base::FilePath& store_path, |
| 69 const scoped_refptr<net::URLRequestContextGetter>& request_context, | 69 const scoped_refptr<net::URLRequestContextGetter>& request_context, |
| 70 const scoped_refptr<base::SequencedTaskRunner> blocking_task_runner); | 70 const scoped_refptr<base::SequencedTaskRunner> blocking_task_runner); |
| 71 void Start(const base::WeakPtr<GCMDriverDesktop>& service); | 71 void Start(const base::WeakPtr<GCMDriverDesktop>& service); |
| 72 void Stop(); | 72 void Stop(); |
| 73 void CheckOut(); | |
| 74 void Register(const std::string& app_id, | 73 void Register(const std::string& app_id, |
| 75 const std::vector<std::string>& sender_ids); | 74 const std::vector<std::string>& sender_ids); |
| 76 void Unregister(const std::string& app_id); | 75 void Unregister(const std::string& app_id); |
| 77 void Send(const std::string& app_id, | 76 void Send(const std::string& app_id, |
| 78 const std::string& receiver_id, | 77 const std::string& receiver_id, |
| 79 const GCMClient::OutgoingMessage& message); | 78 const GCMClient::OutgoingMessage& message); |
| 80 void GetGCMStatistics(bool clear_logs); | 79 void GetGCMStatistics(bool clear_logs); |
| 81 void SetGCMRecording(bool recording); | 80 void SetGCMRecording(bool recording); |
| 82 | 81 |
| 83 void SetAccountTokens( | 82 void SetAccountTokens( |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 246 service_ = service; | 245 service_ = service; |
| 247 gcm_client_->Start(); | 246 gcm_client_->Start(); |
| 248 } | 247 } |
| 249 | 248 |
| 250 void GCMDriverDesktop::IOWorker::Stop() { | 249 void GCMDriverDesktop::IOWorker::Stop() { |
| 251 DCHECK(io_thread_->RunsTasksOnCurrentThread()); | 250 DCHECK(io_thread_->RunsTasksOnCurrentThread()); |
| 252 | 251 |
| 253 gcm_client_->Stop(); | 252 gcm_client_->Stop(); |
| 254 } | 253 } |
| 255 | 254 |
| 256 void GCMDriverDesktop::IOWorker::CheckOut() { | |
| 257 DCHECK(io_thread_->RunsTasksOnCurrentThread()); | |
| 258 | |
| 259 gcm_client_->CheckOut(); | |
| 260 | |
| 261 // Note that we still need to keep GCMClient instance alive since the | |
| 262 // GCMDriverDesktop may check in again. | |
| 263 } | |
| 264 | |
| 265 void GCMDriverDesktop::IOWorker::Register( | 255 void GCMDriverDesktop::IOWorker::Register( |
| 266 const std::string& app_id, | 256 const std::string& app_id, |
| 267 const std::vector<std::string>& sender_ids) { | 257 const std::vector<std::string>& sender_ids) { |
| 268 DCHECK(io_thread_->RunsTasksOnCurrentThread()); | 258 DCHECK(io_thread_->RunsTasksOnCurrentThread()); |
| 269 | 259 |
| 270 gcm_client_->Register(app_id, sender_ids); | 260 gcm_client_->Register(app_id, sender_ids); |
| 271 } | 261 } |
| 272 | 262 |
| 273 void GCMDriverDesktop::IOWorker::Unregister(const std::string& app_id) { | 263 void GCMDriverDesktop::IOWorker::Unregister(const std::string& app_id) { |
| 274 DCHECK(io_thread_->RunsTasksOnCurrentThread()); | 264 DCHECK(io_thread_->RunsTasksOnCurrentThread()); |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 424 } | 414 } |
| 425 | 415 |
| 426 void GCMDriverDesktop::OnSignedIn() { | 416 void GCMDriverDesktop::OnSignedIn() { |
| 427 signed_in_ = true; | 417 signed_in_ = true; |
| 428 } | 418 } |
| 429 | 419 |
| 430 void GCMDriverDesktop::OnSignedOut() { | 420 void GCMDriverDesktop::OnSignedOut() { |
| 431 signed_in_ = false; | 421 signed_in_ = false; |
| 432 } | 422 } |
| 433 | 423 |
| 434 void GCMDriverDesktop::Purge() { | |
| 435 DCHECK(ui_thread_->RunsTasksOnCurrentThread()); | |
| 436 | |
| 437 RemoveCachedData(); | |
| 438 | |
| 439 io_thread_->PostTask(FROM_HERE, | |
| 440 base::Bind(&GCMDriverDesktop::IOWorker::CheckOut, | |
| 441 base::Unretained(io_worker_.get()))); | |
| 442 } | |
| 443 | |
| 444 void GCMDriverDesktop::AddAppHandler(const std::string& app_id, | 424 void GCMDriverDesktop::AddAppHandler(const std::string& app_id, |
| 445 GCMAppHandler* handler) { | 425 GCMAppHandler* handler) { |
| 446 DCHECK(ui_thread_->RunsTasksOnCurrentThread()); | 426 DCHECK(ui_thread_->RunsTasksOnCurrentThread()); |
| 447 GCMDriver::AddAppHandler(app_id, handler); | 427 GCMDriver::AddAppHandler(app_id, handler); |
| 448 | 428 |
| 449 // Ensures that the GCM service is started when there is an interest. | 429 // Ensures that the GCM service is started when there is an interest. |
| 450 EnsureStarted(); | 430 EnsureStarted(); |
| 451 } | 431 } |
| 452 | 432 |
| 453 void GCMDriverDesktop::RemoveAppHandler(const std::string& app_id) { | 433 void GCMDriverDesktop::RemoveAppHandler(const std::string& app_id) { |
| (...skipping 399 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 853 DCHECK(ui_thread_->RunsTasksOnCurrentThread()); | 833 DCHECK(ui_thread_->RunsTasksOnCurrentThread()); |
| 854 | 834 |
| 855 // Normally request_gcm_statistics_callback_ would not be null. | 835 // Normally request_gcm_statistics_callback_ would not be null. |
| 856 if (!request_gcm_statistics_callback_.is_null()) | 836 if (!request_gcm_statistics_callback_.is_null()) |
| 857 request_gcm_statistics_callback_.Run(stats); | 837 request_gcm_statistics_callback_.Run(stats); |
| 858 else | 838 else |
| 859 LOG(WARNING) << "request_gcm_statistics_callback_ is NULL."; | 839 LOG(WARNING) << "request_gcm_statistics_callback_ is NULL."; |
| 860 } | 840 } |
| 861 | 841 |
| 862 } // namespace gcm | 842 } // namespace gcm |
| OLD | NEW |