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