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" |
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/sequenced_task_runner.h" | 14 #include "base/sequenced_task_runner.h" |
15 #include "base/threading/sequenced_worker_pool.h" | 15 #include "base/threading/sequenced_worker_pool.h" |
16 #include "components/gcm_driver/gcm_app_handler.h" | 16 #include "components/gcm_driver/gcm_app_handler.h" |
| 17 #include "components/gcm_driver/gcm_channel_status_syncer.h" |
17 #include "components/gcm_driver/gcm_client_factory.h" | 18 #include "components/gcm_driver/gcm_client_factory.h" |
18 #include "components/gcm_driver/gcm_delayed_task_controller.h" | 19 #include "components/gcm_driver/gcm_delayed_task_controller.h" |
19 #include "components/gcm_driver/system_encryptor.h" | 20 #include "components/gcm_driver/system_encryptor.h" |
20 #include "google_apis/gcm/engine/account_mapping.h" | 21 #include "google_apis/gcm/engine/account_mapping.h" |
21 #include "net/base/ip_endpoint.h" | 22 #include "net/base/ip_endpoint.h" |
22 #include "net/url_request/url_request_context_getter.h" | 23 #include "net/url_request/url_request_context_getter.h" |
23 | 24 |
24 namespace gcm { | 25 namespace gcm { |
25 | 26 |
26 class GCMDriverDesktop::IOWorker : public GCMClient::Delegate { | 27 class GCMDriverDesktop::IOWorker : public GCMClient::Delegate { |
(...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
322 const std::string& account_id) { | 323 const std::string& account_id) { |
323 DCHECK(io_thread_->RunsTasksOnCurrentThread()); | 324 DCHECK(io_thread_->RunsTasksOnCurrentThread()); |
324 | 325 |
325 if (gcm_client_.get()) | 326 if (gcm_client_.get()) |
326 gcm_client_->RemoveAccountMapping(account_id); | 327 gcm_client_->RemoveAccountMapping(account_id); |
327 } | 328 } |
328 | 329 |
329 GCMDriverDesktop::GCMDriverDesktop( | 330 GCMDriverDesktop::GCMDriverDesktop( |
330 scoped_ptr<GCMClientFactory> gcm_client_factory, | 331 scoped_ptr<GCMClientFactory> gcm_client_factory, |
331 const GCMClient::ChromeBuildInfo& chrome_build_info, | 332 const GCMClient::ChromeBuildInfo& chrome_build_info, |
| 333 PrefService* prefs, |
332 const base::FilePath& store_path, | 334 const base::FilePath& store_path, |
333 const scoped_refptr<net::URLRequestContextGetter>& request_context, | 335 const scoped_refptr<net::URLRequestContextGetter>& request_context, |
334 const scoped_refptr<base::SequencedTaskRunner>& ui_thread, | 336 const scoped_refptr<base::SequencedTaskRunner>& ui_thread, |
335 const scoped_refptr<base::SequencedTaskRunner>& io_thread, | 337 const scoped_refptr<base::SequencedTaskRunner>& io_thread, |
336 const scoped_refptr<base::SequencedTaskRunner>& blocking_task_runner) | 338 const scoped_refptr<base::SequencedTaskRunner>& blocking_task_runner) |
337 : signed_in_(false), | 339 : gcm_channel_status_syncer_(this, prefs, request_context), |
| 340 signed_in_(false), |
338 gcm_started_(false), | 341 gcm_started_(false), |
339 gcm_enabled_(true), | 342 gcm_enabled_(true), |
340 connected_(false), | 343 connected_(false), |
341 ui_thread_(ui_thread), | 344 ui_thread_(ui_thread), |
342 io_thread_(io_thread), | 345 io_thread_(io_thread), |
343 weak_ptr_factory_(this) { | 346 weak_ptr_factory_(this) { |
| 347 gcm_enabled_ = gcm_channel_status_syncer_.gcm_enabled(); |
| 348 |
344 // Create and initialize the GCMClient. Note that this does not initiate the | 349 // Create and initialize the GCMClient. Note that this does not initiate the |
345 // GCM check-in. | 350 // GCM check-in. |
346 io_worker_.reset(new IOWorker(ui_thread, io_thread)); | 351 io_worker_.reset(new IOWorker(ui_thread, io_thread)); |
347 io_thread_->PostTask( | 352 io_thread_->PostTask( |
348 FROM_HERE, | 353 FROM_HERE, |
349 base::Bind(&GCMDriverDesktop::IOWorker::Initialize, | 354 base::Bind(&GCMDriverDesktop::IOWorker::Initialize, |
350 base::Unretained(io_worker_.get()), | 355 base::Unretained(io_worker_.get()), |
351 base::Passed(&gcm_client_factory), | 356 base::Passed(&gcm_client_factory), |
352 chrome_build_info, | 357 chrome_build_info, |
353 store_path, | 358 store_path, |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
430 Stop(); | 435 Stop(); |
431 } | 436 } |
432 | 437 |
433 void GCMDriverDesktop::Stop() { | 438 void GCMDriverDesktop::Stop() { |
434 DCHECK(ui_thread_->RunsTasksOnCurrentThread()); | 439 DCHECK(ui_thread_->RunsTasksOnCurrentThread()); |
435 | 440 |
436 // No need to stop GCM service if not started yet. | 441 // No need to stop GCM service if not started yet. |
437 if (!gcm_started_) | 442 if (!gcm_started_) |
438 return; | 443 return; |
439 | 444 |
| 445 gcm_channel_status_syncer_.Stop(); |
| 446 |
440 RemoveCachedData(); | 447 RemoveCachedData(); |
441 | 448 |
442 io_thread_->PostTask( | 449 io_thread_->PostTask( |
443 FROM_HERE, | 450 FROM_HERE, |
444 base::Bind(&GCMDriverDesktop::IOWorker::Stop, | 451 base::Bind(&GCMDriverDesktop::IOWorker::Stop, |
445 base::Unretained(io_worker_.get()))); | 452 base::Unretained(io_worker_.get()))); |
446 } | 453 } |
447 | 454 |
448 void GCMDriverDesktop::RegisterImpl( | 455 void GCMDriverDesktop::RegisterImpl( |
449 const std::string& app_id, | 456 const std::string& app_id, |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
616 if (app_handlers().empty()) | 623 if (app_handlers().empty()) |
617 return GCMClient::UNKNOWN_ERROR; | 624 return GCMClient::UNKNOWN_ERROR; |
618 | 625 |
619 // TODO(jianli): To be removed when sign-in enforcement is dropped. | 626 // TODO(jianli): To be removed when sign-in enforcement is dropped. |
620 if (!signed_in_ && !GCMDriver::IsAllowedForAllUsers()) | 627 if (!signed_in_ && !GCMDriver::IsAllowedForAllUsers()) |
621 return GCMClient::NOT_SIGNED_IN; | 628 return GCMClient::NOT_SIGNED_IN; |
622 | 629 |
623 DCHECK(!delayed_task_controller_); | 630 DCHECK(!delayed_task_controller_); |
624 delayed_task_controller_.reset(new GCMDelayedTaskController); | 631 delayed_task_controller_.reset(new GCMDelayedTaskController); |
625 | 632 |
| 633 // Polling for channel status is only needed when GCM is supported for all |
| 634 // users. |
| 635 if (GCMDriver::IsAllowedForAllUsers()) |
| 636 gcm_channel_status_syncer_.EnsureStarted(); |
| 637 |
626 // Note that we need to pass weak pointer again since the existing weak | 638 // Note that we need to pass weak pointer again since the existing weak |
627 // pointer in IOWorker might have been invalidated when check-out occurs. | 639 // pointer in IOWorker might have been invalidated when check-out occurs. |
628 io_thread_->PostTask( | 640 io_thread_->PostTask( |
629 FROM_HERE, | 641 FROM_HERE, |
630 base::Bind(&GCMDriverDesktop::IOWorker::Start, | 642 base::Bind(&GCMDriverDesktop::IOWorker::Start, |
631 base::Unretained(io_worker_.get()), | 643 base::Unretained(io_worker_.get()), |
632 weak_ptr_factory_.GetWeakPtr())); | 644 weak_ptr_factory_.GetWeakPtr())); |
633 | 645 |
634 gcm_started_ = true; | 646 gcm_started_ = true; |
635 return GCMClient::SUCCESS; | 647 return GCMClient::SUCCESS; |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
730 | 742 |
731 // Normally request_gcm_statistics_callback_ would not be null. | 743 // Normally request_gcm_statistics_callback_ would not be null. |
732 if (!request_gcm_statistics_callback_.is_null()) | 744 if (!request_gcm_statistics_callback_.is_null()) |
733 request_gcm_statistics_callback_.Run(stats); | 745 request_gcm_statistics_callback_.Run(stats); |
734 else | 746 else |
735 LOG(WARNING) << "request_gcm_statistics_callback_ is NULL."; | 747 LOG(WARNING) << "request_gcm_statistics_callback_ is NULL."; |
736 } | 748 } |
737 | 749 |
738 } // namespace gcm | 750 } // namespace gcm |
739 | 751 |
OLD | NEW |