Index: components/gcm_driver/gcm_driver_desktop.cc |
diff --git a/components/gcm_driver/gcm_driver_desktop.cc b/components/gcm_driver/gcm_driver_desktop.cc |
index 8d35c2c03acf9c2ed8b0fd8cfd00cb4ea2dd5656..82ca4b34320e1c14ef5e4e61e76307da0c1537ca 100644 |
--- a/components/gcm_driver/gcm_driver_desktop.cc |
+++ b/components/gcm_driver/gcm_driver_desktop.cc |
@@ -14,6 +14,7 @@ |
#include "base/sequenced_task_runner.h" |
#include "base/threading/sequenced_worker_pool.h" |
#include "components/gcm_driver/gcm_app_handler.h" |
+#include "components/gcm_driver/gcm_channel_status_syncer.h" |
#include "components/gcm_driver/gcm_client_factory.h" |
#include "components/gcm_driver/gcm_delayed_task_controller.h" |
#include "components/gcm_driver/system_encryptor.h" |
@@ -329,18 +330,23 @@ void GCMDriverDesktop::IOWorker::RemoveAccountMapping( |
GCMDriverDesktop::GCMDriverDesktop( |
scoped_ptr<GCMClientFactory> gcm_client_factory, |
const GCMClient::ChromeBuildInfo& chrome_build_info, |
+ PrefService* prefs, |
const base::FilePath& store_path, |
const scoped_refptr<net::URLRequestContextGetter>& request_context, |
const scoped_refptr<base::SequencedTaskRunner>& ui_thread, |
const scoped_refptr<base::SequencedTaskRunner>& io_thread, |
const scoped_refptr<base::SequencedTaskRunner>& blocking_task_runner) |
- : signed_in_(false), |
+ : gcm_channel_status_syncer_( |
+ new GCMChannelStatusSyncer(this, prefs, request_context)), |
+ signed_in_(false), |
gcm_started_(false), |
gcm_enabled_(true), |
connected_(false), |
ui_thread_(ui_thread), |
io_thread_(io_thread), |
weak_ptr_factory_(this) { |
+ gcm_enabled_ = gcm_channel_status_syncer_->gcm_enabled(); |
+ |
// Create and initialize the GCMClient. Note that this does not initiate the |
// GCM check-in. |
io_worker_.reset(new IOWorker(ui_thread, io_thread)); |
@@ -361,6 +367,12 @@ GCMDriverDesktop::~GCMDriverDesktop() { |
void GCMDriverDesktop::Shutdown() { |
DCHECK(ui_thread_->RunsTasksOnCurrentThread()); |
GCMDriver::Shutdown(); |
+ |
+ // Dispose the syncer in order to release the reference to |
+ // URLRequestContextGetter that needs to be done before IOThread gets |
+ // deleted. |
+ gcm_channel_status_syncer_.reset(); |
+ |
io_thread_->DeleteSoon(FROM_HERE, io_worker_.release()); |
} |
@@ -442,6 +454,8 @@ void GCMDriverDesktop::Stop() { |
if (!gcm_started_) |
return; |
+ gcm_channel_status_syncer_->Stop(); |
+ |
RemoveCachedData(); |
io_thread_->PostTask( |
@@ -627,6 +641,11 @@ GCMClient::Result GCMDriverDesktop::EnsureStarted() { |
DCHECK(!delayed_task_controller_); |
delayed_task_controller_.reset(new GCMDelayedTaskController); |
+ // Polling for channel status is only needed when GCM is supported for all |
+ // users. |
+ if (GCMDriver::IsAllowedForAllUsers()) |
+ gcm_channel_status_syncer_->EnsureStarted(); |
+ |
// Note that we need to pass weak pointer again since the existing weak |
// pointer in IOWorker might have been invalidated when check-out occurs. |
io_thread_->PostTask( |