| Index: components/gcm/gcm_driver_desktop.cc
|
| diff --git a/components/gcm/gcm_driver.cc b/components/gcm/gcm_driver_desktop.cc
|
| similarity index 71%
|
| copy from components/gcm/gcm_driver.cc
|
| copy to components/gcm/gcm_driver_desktop.cc
|
| index 2fa86d037fac2c10c535386acb5af9cb72f9b976..7a5b9f38a704888db36b73eb9363bd8f7a002ce0 100644
|
| --- a/components/gcm/gcm_driver.cc
|
| +++ b/components/gcm/gcm_driver_desktop.cc
|
| @@ -2,7 +2,7 @@
|
| // Use of this source code is governed by a BSD-style license that can be
|
| // found in the LICENSE file.
|
|
|
| -#include "components/gcm/gcm_driver.h"
|
| +#include "components/gcm/gcm_driver_desktop.h"
|
|
|
| #include <algorithm>
|
| #include <utility>
|
| @@ -24,7 +24,7 @@
|
| namespace gcm {
|
|
|
| // Helper class to save tasks to run until we're ready to execute them.
|
| -class GCMDriver::DelayedTaskController {
|
| +class GCMDriverDesktop::DelayedTaskController {
|
| public:
|
| DelayedTaskController();
|
| ~DelayedTaskController();
|
| @@ -50,26 +50,28 @@ class GCMDriver::DelayedTaskController {
|
| DISALLOW_COPY_AND_ASSIGN(DelayedTaskController);
|
| };
|
|
|
| -GCMDriver::DelayedTaskController::DelayedTaskController() : ready_(false) {
|
| +GCMDriverDesktop::DelayedTaskController::DelayedTaskController()
|
| + : ready_(false) {
|
| }
|
|
|
| -GCMDriver::DelayedTaskController::~DelayedTaskController() {
|
| +GCMDriverDesktop::DelayedTaskController::~DelayedTaskController() {
|
| }
|
|
|
| -void GCMDriver::DelayedTaskController::AddTask(const base::Closure& task) {
|
| +void GCMDriverDesktop::DelayedTaskController::AddTask(
|
| + const base::Closure& task) {
|
| delayed_tasks_.push_back(task);
|
| }
|
|
|
| -void GCMDriver::DelayedTaskController::SetReady() {
|
| +void GCMDriverDesktop::DelayedTaskController::SetReady() {
|
| ready_ = true;
|
| RunTasks();
|
| }
|
|
|
| -bool GCMDriver::DelayedTaskController::CanRunTaskWithoutDelay() const {
|
| +bool GCMDriverDesktop::DelayedTaskController::CanRunTaskWithoutDelay() const {
|
| return ready_;
|
| }
|
|
|
| -void GCMDriver::DelayedTaskController::RunTasks() {
|
| +void GCMDriverDesktop::DelayedTaskController::RunTasks() {
|
| DCHECK(ready_);
|
|
|
| for (size_t i = 0; i < delayed_tasks_.size(); ++i)
|
| @@ -77,7 +79,7 @@ void GCMDriver::DelayedTaskController::RunTasks() {
|
| delayed_tasks_.clear();
|
| }
|
|
|
| -class GCMDriver::IOWorker : public GCMClient::Delegate {
|
| +class GCMDriverDesktop::IOWorker : public GCMClient::Delegate {
|
| public:
|
| // Called on UI thread.
|
| IOWorker(const scoped_refptr<base::MessageLoopProxy>& ui_thread,
|
| @@ -111,7 +113,7 @@ class GCMDriver::IOWorker : public GCMClient::Delegate {
|
| const std::vector<std::string>& account_ids,
|
| const scoped_refptr<net::URLRequestContextGetter>& request_context,
|
| const scoped_refptr<base::SequencedTaskRunner> blocking_task_runner);
|
| - void Start(const base::WeakPtr<GCMDriver>& service);
|
| + void Start(const base::WeakPtr<GCMDriverDesktop>& service);
|
| void Stop();
|
| void CheckOut();
|
| void Register(const std::string& app_id,
|
| @@ -130,14 +132,14 @@ class GCMDriver::IOWorker : public GCMClient::Delegate {
|
| scoped_refptr<base::MessageLoopProxy> ui_thread_;
|
| scoped_refptr<base::MessageLoopProxy> io_thread_;
|
|
|
| - base::WeakPtr<GCMDriver> service_;
|
| + base::WeakPtr<GCMDriverDesktop> service_;
|
|
|
| scoped_ptr<GCMClient> gcm_client_;
|
|
|
| DISALLOW_COPY_AND_ASSIGN(IOWorker);
|
| };
|
|
|
| -GCMDriver::IOWorker::IOWorker(
|
| +GCMDriverDesktop::IOWorker::IOWorker(
|
| const scoped_refptr<base::MessageLoopProxy>& ui_thread,
|
| const scoped_refptr<base::MessageLoopProxy>& io_thread)
|
| : ui_thread_(ui_thread),
|
| @@ -145,11 +147,11 @@ GCMDriver::IOWorker::IOWorker(
|
| DCHECK(ui_thread_->BelongsToCurrentThread());
|
| }
|
|
|
| -GCMDriver::IOWorker::~IOWorker() {
|
| +GCMDriverDesktop::IOWorker::~IOWorker() {
|
| DCHECK(io_thread_->BelongsToCurrentThread());
|
| }
|
|
|
| -void GCMDriver::IOWorker::Initialize(
|
| +void GCMDriverDesktop::IOWorker::Initialize(
|
| const checkin_proto::ChromeBuildProto& chrome_build_proto,
|
| scoped_ptr<GCMClientFactory> gcm_client_factory,
|
| const base::FilePath& store_path,
|
| @@ -168,7 +170,7 @@ void GCMDriver::IOWorker::Initialize(
|
| this);
|
| }
|
|
|
| -void GCMDriver::IOWorker::OnRegisterFinished(
|
| +void GCMDriverDesktop::IOWorker::OnRegisterFinished(
|
| const std::string& app_id,
|
| const std::string& registration_id,
|
| GCMClient::Result result) {
|
| @@ -176,88 +178,96 @@ void GCMDriver::IOWorker::OnRegisterFinished(
|
|
|
| ui_thread_->PostTask(
|
| FROM_HERE,
|
| - base::Bind(&GCMDriver::RegisterFinished, service_, app_id,
|
| + base::Bind(&GCMDriverDesktop::RegisterFinished, service_, app_id,
|
| registration_id, result));
|
| }
|
|
|
| -void GCMDriver::IOWorker::OnUnregisterFinished(const std::string& app_id,
|
| - GCMClient::Result result) {
|
| +void GCMDriverDesktop::IOWorker::OnUnregisterFinished(
|
| + const std::string& app_id,
|
| + GCMClient::Result result) {
|
| DCHECK(io_thread_->BelongsToCurrentThread());
|
|
|
| ui_thread_->PostTask(
|
| FROM_HERE,
|
| - base::Bind(&GCMDriver::UnregisterFinished, service_, app_id, result));
|
| + base::Bind(&GCMDriverDesktop::UnregisterFinished,
|
| + service_,
|
| + app_id,
|
| + result));
|
| }
|
|
|
| -void GCMDriver::IOWorker::OnSendFinished(const std::string& app_id,
|
| - const std::string& message_id,
|
| - GCMClient::Result result) {
|
| +void GCMDriverDesktop::IOWorker::OnSendFinished(const std::string& app_id,
|
| + const std::string& message_id,
|
| + GCMClient::Result result) {
|
| DCHECK(io_thread_->BelongsToCurrentThread());
|
|
|
| ui_thread_->PostTask(
|
| FROM_HERE,
|
| - base::Bind(&GCMDriver::SendFinished, service_, app_id, message_id,
|
| + base::Bind(&GCMDriverDesktop::SendFinished, service_, app_id, message_id,
|
| result));
|
| }
|
|
|
| -void GCMDriver::IOWorker::OnMessageReceived(
|
| +void GCMDriverDesktop::IOWorker::OnMessageReceived(
|
| const std::string& app_id,
|
| const GCMClient::IncomingMessage& message) {
|
| DCHECK(io_thread_->BelongsToCurrentThread());
|
|
|
| ui_thread_->PostTask(
|
| FROM_HERE,
|
| - base::Bind(&GCMDriver::MessageReceived, service_, app_id, message));
|
| + base::Bind(&GCMDriverDesktop::MessageReceived,
|
| + service_,
|
| + app_id,
|
| + message));
|
| }
|
|
|
| -void GCMDriver::IOWorker::OnMessagesDeleted(const std::string& app_id) {
|
| +void GCMDriverDesktop::IOWorker::OnMessagesDeleted(const std::string& app_id) {
|
| DCHECK(io_thread_->BelongsToCurrentThread());
|
|
|
| ui_thread_->PostTask(
|
| FROM_HERE,
|
| - base::Bind(&GCMDriver::MessagesDeleted, service_, app_id));
|
| + base::Bind(&GCMDriverDesktop::MessagesDeleted, service_, app_id));
|
| }
|
|
|
| -void GCMDriver::IOWorker::OnMessageSendError(
|
| +void GCMDriverDesktop::IOWorker::OnMessageSendError(
|
| const std::string& app_id,
|
| const GCMClient::SendErrorDetails& send_error_details) {
|
| DCHECK(io_thread_->BelongsToCurrentThread());
|
|
|
| ui_thread_->PostTask(
|
| FROM_HERE,
|
| - base::Bind(&GCMDriver::MessageSendError, service_, app_id,
|
| + base::Bind(&GCMDriverDesktop::MessageSendError, service_, app_id,
|
| send_error_details));
|
| }
|
|
|
| -void GCMDriver::IOWorker::OnGCMReady() {
|
| +void GCMDriverDesktop::IOWorker::OnGCMReady() {
|
| ui_thread_->PostTask(
|
| FROM_HERE,
|
| - base::Bind(&GCMDriver::GCMClientReady, service_));
|
| + base::Bind(&GCMDriverDesktop::GCMClientReady, service_));
|
| }
|
|
|
| -void GCMDriver::IOWorker::Start(const base::WeakPtr<GCMDriver>& service) {
|
| +void GCMDriverDesktop::IOWorker::Start(
|
| + const base::WeakPtr<GCMDriverDesktop>& service) {
|
| DCHECK(io_thread_->BelongsToCurrentThread());
|
|
|
| service_ = service;
|
| gcm_client_->Start();
|
| }
|
|
|
| -void GCMDriver::IOWorker::Stop() {
|
| +void GCMDriverDesktop::IOWorker::Stop() {
|
| DCHECK(io_thread_->BelongsToCurrentThread());
|
|
|
| gcm_client_->Stop();
|
| }
|
|
|
| -void GCMDriver::IOWorker::CheckOut() {
|
| +void GCMDriverDesktop::IOWorker::CheckOut() {
|
| DCHECK(io_thread_->BelongsToCurrentThread());
|
|
|
| gcm_client_->CheckOut();
|
|
|
| // Note that we still need to keep GCMClient instance alive since the
|
| - // GCMDriver may check in again.
|
| + // GCMDriverDesktop may check in again.
|
| }
|
|
|
| -void GCMDriver::IOWorker::Register(
|
| +void GCMDriverDesktop::IOWorker::Register(
|
| const std::string& app_id,
|
| const std::vector<std::string>& sender_ids) {
|
| DCHECK(io_thread_->BelongsToCurrentThread());
|
| @@ -265,21 +275,22 @@ void GCMDriver::IOWorker::Register(
|
| gcm_client_->Register(app_id, sender_ids);
|
| }
|
|
|
| -void GCMDriver::IOWorker::Unregister(const std::string& app_id) {
|
| +void GCMDriverDesktop::IOWorker::Unregister(const std::string& app_id) {
|
| DCHECK(io_thread_->BelongsToCurrentThread());
|
|
|
| gcm_client_->Unregister(app_id);
|
| }
|
|
|
| -void GCMDriver::IOWorker::Send(const std::string& app_id,
|
| - const std::string& receiver_id,
|
| - const GCMClient::OutgoingMessage& message) {
|
| +void GCMDriverDesktop::IOWorker::Send(
|
| + const std::string& app_id,
|
| + const std::string& receiver_id,
|
| + const GCMClient::OutgoingMessage& message) {
|
| DCHECK(io_thread_->BelongsToCurrentThread());
|
|
|
| gcm_client_->Send(app_id, receiver_id, message);
|
| }
|
|
|
| -void GCMDriver::IOWorker::GetGCMStatistics(bool clear_logs) {
|
| +void GCMDriverDesktop::IOWorker::GetGCMStatistics(bool clear_logs) {
|
| DCHECK(io_thread_->BelongsToCurrentThread());
|
| gcm::GCMClient::GCMStatistics stats;
|
|
|
| @@ -291,10 +302,10 @@ void GCMDriver::IOWorker::GetGCMStatistics(bool clear_logs) {
|
|
|
| ui_thread_->PostTask(
|
| FROM_HERE,
|
| - base::Bind(&GCMDriver::GetGCMStatisticsFinished, service_, stats));
|
| + base::Bind(&GCMDriverDesktop::GetGCMStatisticsFinished, service_, stats));
|
| }
|
|
|
| -void GCMDriver::IOWorker::SetGCMRecording(bool recording) {
|
| +void GCMDriverDesktop::IOWorker::SetGCMRecording(bool recording) {
|
| DCHECK(io_thread_->BelongsToCurrentThread());
|
| gcm::GCMClient::GCMStatistics stats;
|
|
|
| @@ -306,10 +317,10 @@ void GCMDriver::IOWorker::SetGCMRecording(bool recording) {
|
|
|
| ui_thread_->PostTask(
|
| FROM_HERE,
|
| - base::Bind(&GCMDriver::GetGCMStatisticsFinished, service_, stats));
|
| + base::Bind(&GCMDriverDesktop::GetGCMStatisticsFinished, service_, stats));
|
| }
|
|
|
| -GCMDriver::GCMDriver(
|
| +GCMDriverDesktop::GCMDriverDesktop(
|
| const checkin_proto::ChromeBuildProto& chrome_build_proto,
|
| scoped_ptr<GCMClientFactory> gcm_client_factory,
|
| scoped_ptr<IdentityProvider> identity_provider,
|
| @@ -318,8 +329,8 @@ GCMDriver::GCMDriver(
|
| const scoped_refptr<base::SequencedTaskRunner> blocking_task_runner,
|
| const scoped_refptr<base::MessageLoopProxy>& ui_thread,
|
| const scoped_refptr<base::MessageLoopProxy>& io_thread)
|
| - : identity_provider_(identity_provider.Pass()),
|
| - ui_thread_(ui_thread),
|
| + : GCMDriver(ui_thread),
|
| + identity_provider_(identity_provider.Pass()),
|
| io_thread_(io_thread),
|
| gcm_enabled_(true),
|
| gcm_client_ready_(false),
|
| @@ -336,7 +347,7 @@ GCMDriver::GCMDriver(
|
| io_worker_.reset(new IOWorker(ui_thread, io_thread));
|
| io_thread_->PostTask(
|
| FROM_HERE,
|
| - base::Bind(&GCMDriver::IOWorker::Initialize,
|
| + base::Bind(&GCMDriverDesktop::IOWorker::Initialize,
|
| base::Unretained(io_worker_.get()),
|
| chrome_build_proto,
|
| base::Passed(&gcm_client_factory),
|
| @@ -348,16 +359,16 @@ GCMDriver::GCMDriver(
|
| identity_provider_->AddObserver(this);
|
| }
|
|
|
| -GCMDriver::GCMDriver()
|
| +GCMDriverDesktop::GCMDriverDesktop()
|
| : gcm_enabled_(true),
|
| gcm_client_ready_(false),
|
| weak_ptr_factory_(this) {
|
| }
|
|
|
| -GCMDriver::~GCMDriver() {
|
| +GCMDriverDesktop::~GCMDriverDesktop() {
|
| }
|
|
|
| -void GCMDriver::Enable() {
|
| +void GCMDriverDesktop::Enable() {
|
| DCHECK(ui_thread_->BelongsToCurrentThread());
|
|
|
| if (gcm_enabled_)
|
| @@ -367,7 +378,7 @@ void GCMDriver::Enable() {
|
| EnsureStarted();
|
| }
|
|
|
| -void GCMDriver::Disable() {
|
| +void GCMDriverDesktop::Disable() {
|
| DCHECK(ui_thread_->BelongsToCurrentThread());
|
|
|
| if (!gcm_enabled_)
|
| @@ -377,43 +388,32 @@ void GCMDriver::Disable() {
|
| Stop();
|
| }
|
|
|
| -void GCMDriver::Shutdown() {
|
| +void GCMDriverDesktop::Shutdown() {
|
| DCHECK(ui_thread_->BelongsToCurrentThread());
|
| identity_provider_->RemoveObserver(this);
|
| - for (GCMAppHandlerMap::const_iterator iter = app_handlers_.begin();
|
| - iter != app_handlers_.end(); ++iter) {
|
| - iter->second->ShutdownHandler();
|
| - }
|
| - app_handlers_.clear();
|
| + GCMDriver::Shutdown();
|
| io_thread_->DeleteSoon(FROM_HERE, io_worker_.release());
|
| }
|
|
|
| -void GCMDriver::AddAppHandler(const std::string& app_id,
|
| +void GCMDriverDesktop::AddAppHandler(const std::string& app_id,
|
| GCMAppHandler* handler) {
|
| - DCHECK(ui_thread_->BelongsToCurrentThread());
|
| - DCHECK(!app_id.empty());
|
| - DCHECK(handler);
|
| -
|
| - app_handlers_[app_id] = handler;
|
| + GCMDriver::AddAppHandler(app_id, handler);
|
|
|
| // Ensures that the GCM service is started when there is an interest.
|
| EnsureStarted();
|
| }
|
|
|
| -void GCMDriver::RemoveAppHandler(const std::string& app_id) {
|
| - DCHECK(ui_thread_->BelongsToCurrentThread());
|
| - DCHECK(!app_id.empty());
|
| -
|
| - app_handlers_.erase(app_id);
|
| +void GCMDriverDesktop::RemoveAppHandler(const std::string& app_id) {
|
| + GCMDriver::RemoveAppHandler(app_id);
|
|
|
| // Stops the GCM service when no app intends to consume it.
|
| - if (app_handlers_.empty())
|
| + if (app_handlers().empty())
|
| Stop();
|
| }
|
|
|
| -void GCMDriver::Register(const std::string& app_id,
|
| - const std::vector<std::string>& sender_ids,
|
| - const RegisterCallback& callback) {
|
| +void GCMDriverDesktop::Register(const std::string& app_id,
|
| + const std::vector<std::string>& sender_ids,
|
| + const RegisterCallback& callback) {
|
| DCHECK(ui_thread_->BelongsToCurrentThread());
|
| DCHECK(!app_id.empty());
|
| DCHECK(!sender_ids.empty());
|
| @@ -435,7 +435,7 @@ void GCMDriver::Register(const std::string& app_id,
|
|
|
| // Delay the register operation until GCMClient is ready.
|
| if (!delayed_task_controller_->CanRunTaskWithoutDelay()) {
|
| - delayed_task_controller_->AddTask(base::Bind(&GCMDriver::DoRegister,
|
| + delayed_task_controller_->AddTask(base::Bind(&GCMDriverDesktop::DoRegister,
|
| weak_ptr_factory_.GetWeakPtr(),
|
| app_id,
|
| sender_ids));
|
| @@ -445,8 +445,8 @@ void GCMDriver::Register(const std::string& app_id,
|
| DoRegister(app_id, sender_ids);
|
| }
|
|
|
| -void GCMDriver::DoRegister(const std::string& app_id,
|
| - const std::vector<std::string>& sender_ids) {
|
| +void GCMDriverDesktop::DoRegister(const std::string& app_id,
|
| + const std::vector<std::string>& sender_ids) {
|
| DCHECK(ui_thread_->BelongsToCurrentThread());
|
| std::map<std::string, RegisterCallback>::iterator callback_iter =
|
| register_callbacks_.find(app_id);
|
| @@ -461,14 +461,14 @@ void GCMDriver::DoRegister(const std::string& app_id,
|
|
|
| io_thread_->PostTask(
|
| FROM_HERE,
|
| - base::Bind(&GCMDriver::IOWorker::Register,
|
| + base::Bind(&GCMDriverDesktop::IOWorker::Register,
|
| base::Unretained(io_worker_.get()),
|
| app_id,
|
| normalized_sender_ids));
|
| }
|
|
|
| -void GCMDriver::Unregister(const std::string& app_id,
|
| - const UnregisterCallback& callback) {
|
| +void GCMDriverDesktop::Unregister(const std::string& app_id,
|
| + const UnregisterCallback& callback) {
|
| DCHECK(ui_thread_->BelongsToCurrentThread());
|
| DCHECK(!app_id.empty());
|
| DCHECK(!callback.is_null());
|
| @@ -489,16 +489,17 @@ void GCMDriver::Unregister(const std::string& app_id,
|
|
|
| // Delay the unregister operation until GCMClient is ready.
|
| if (!delayed_task_controller_->CanRunTaskWithoutDelay()) {
|
| - delayed_task_controller_->AddTask(base::Bind(&GCMDriver::DoUnregister,
|
| - weak_ptr_factory_.GetWeakPtr(),
|
| - app_id));
|
| + delayed_task_controller_->AddTask(
|
| + base::Bind(&GCMDriverDesktop::DoUnregister,
|
| + weak_ptr_factory_.GetWeakPtr(),
|
| + app_id));
|
| return;
|
| }
|
|
|
| DoUnregister(app_id);
|
| }
|
|
|
| -void GCMDriver::DoUnregister(const std::string& app_id) {
|
| +void GCMDriverDesktop::DoUnregister(const std::string& app_id) {
|
| DCHECK(ui_thread_->BelongsToCurrentThread());
|
|
|
| // Ask the server to unregister it. There could be a small chance that the
|
| @@ -506,15 +507,15 @@ void GCMDriver::DoUnregister(const std::string& app_id) {
|
| // we simply reject the messages/events received from the server.
|
| io_thread_->PostTask(
|
| FROM_HERE,
|
| - base::Bind(&GCMDriver::IOWorker::Unregister,
|
| + base::Bind(&GCMDriverDesktop::IOWorker::Unregister,
|
| base::Unretained(io_worker_.get()),
|
| app_id));
|
| }
|
|
|
| -void GCMDriver::Send(const std::string& app_id,
|
| - const std::string& receiver_id,
|
| - const GCMClient::OutgoingMessage& message,
|
| - const SendCallback& callback) {
|
| +void GCMDriverDesktop::Send(const std::string& app_id,
|
| + const std::string& receiver_id,
|
| + const GCMClient::OutgoingMessage& message,
|
| + const SendCallback& callback) {
|
| DCHECK(ui_thread_->BelongsToCurrentThread());
|
| DCHECK(!app_id.empty());
|
| DCHECK(!receiver_id.empty());
|
| @@ -537,7 +538,7 @@ void GCMDriver::Send(const std::string& app_id,
|
|
|
| // Delay the send operation until all GCMClient is ready.
|
| if (!delayed_task_controller_->CanRunTaskWithoutDelay()) {
|
| - delayed_task_controller_->AddTask(base::Bind(&GCMDriver::DoSend,
|
| + delayed_task_controller_->AddTask(base::Bind(&GCMDriverDesktop::DoSend,
|
| weak_ptr_factory_.GetWeakPtr(),
|
| app_id,
|
| receiver_id,
|
| @@ -548,68 +549,68 @@ void GCMDriver::Send(const std::string& app_id,
|
| DoSend(app_id, receiver_id, message);
|
| }
|
|
|
| -void GCMDriver::DoSend(const std::string& app_id,
|
| - const std::string& receiver_id,
|
| - const GCMClient::OutgoingMessage& message) {
|
| +void GCMDriverDesktop::DoSend(const std::string& app_id,
|
| + const std::string& receiver_id,
|
| + const GCMClient::OutgoingMessage& message) {
|
| DCHECK(ui_thread_->BelongsToCurrentThread());
|
| io_thread_->PostTask(
|
| FROM_HERE,
|
| - base::Bind(&GCMDriver::IOWorker::Send,
|
| + base::Bind(&GCMDriverDesktop::IOWorker::Send,
|
| base::Unretained(io_worker_.get()),
|
| app_id,
|
| receiver_id,
|
| message));
|
| }
|
|
|
| -GCMClient* GCMDriver::GetGCMClientForTesting() const {
|
| +GCMClient* GCMDriverDesktop::GetGCMClientForTesting() const {
|
| DCHECK(ui_thread_->BelongsToCurrentThread());
|
| return io_worker_ ? io_worker_->gcm_client_for_testing() : NULL;
|
| }
|
|
|
| -bool GCMDriver::IsStarted() const {
|
| +bool GCMDriverDesktop::IsStarted() const {
|
| DCHECK(ui_thread_->BelongsToCurrentThread());
|
| return !account_id_.empty();
|
| }
|
|
|
| -bool GCMDriver::IsGCMClientReady() const {
|
| +bool GCMDriverDesktop::IsGCMClientReady() const {
|
| DCHECK(ui_thread_->BelongsToCurrentThread());
|
| return gcm_client_ready_;
|
| }
|
|
|
| -void GCMDriver::GetGCMStatistics(GetGCMStatisticsCallback callback,
|
| - bool clear_logs) {
|
| +void GCMDriverDesktop::GetGCMStatistics(GetGCMStatisticsCallback callback,
|
| + bool clear_logs) {
|
| DCHECK(ui_thread_->BelongsToCurrentThread());
|
| DCHECK(!callback.is_null());
|
|
|
| request_gcm_statistics_callback_ = callback;
|
| io_thread_->PostTask(
|
| FROM_HERE,
|
| - base::Bind(&GCMDriver::IOWorker::GetGCMStatistics,
|
| + base::Bind(&GCMDriverDesktop::IOWorker::GetGCMStatistics,
|
| base::Unretained(io_worker_.get()),
|
| clear_logs));
|
| }
|
|
|
| -void GCMDriver::SetGCMRecording(GetGCMStatisticsCallback callback,
|
| - bool recording) {
|
| +void GCMDriverDesktop::SetGCMRecording(GetGCMStatisticsCallback callback,
|
| + bool recording) {
|
| DCHECK(ui_thread_->BelongsToCurrentThread());
|
|
|
| request_gcm_statistics_callback_ = callback;
|
| io_thread_->PostTask(
|
| FROM_HERE,
|
| - base::Bind(&GCMDriver::IOWorker::SetGCMRecording,
|
| + base::Bind(&GCMDriverDesktop::IOWorker::SetGCMRecording,
|
| base::Unretained(io_worker_.get()),
|
| recording));
|
| }
|
|
|
| -void GCMDriver::OnActiveAccountLogin() {
|
| +void GCMDriverDesktop::OnActiveAccountLogin() {
|
| EnsureStarted();
|
| }
|
|
|
| -void GCMDriver::OnActiveAccountLogout() {
|
| +void GCMDriverDesktop::OnActiveAccountLogout() {
|
| CheckOut();
|
| }
|
|
|
| -GCMClient::Result GCMDriver::EnsureStarted() {
|
| +GCMClient::Result GCMDriverDesktop::EnsureStarted() {
|
| DCHECK(ui_thread_->BelongsToCurrentThread());
|
|
|
| // Is GCM enabled?
|
| @@ -617,7 +618,7 @@ GCMClient::Result GCMDriver::EnsureStarted() {
|
| return GCMClient::GCM_DISABLED;
|
|
|
| // Has any app requested the service?
|
| - if (app_handlers_.empty())
|
| + if (app_handlers().empty())
|
| return GCMClient::UNKNOWN_ERROR;
|
|
|
| // Can we get an account ID from the identity provider?
|
| @@ -641,14 +642,14 @@ GCMClient::Result GCMDriver::EnsureStarted() {
|
| // pointer in IOWorker might have been invalidated when check-out occurs.
|
| io_thread_->PostTask(
|
| FROM_HERE,
|
| - base::Bind(&GCMDriver::IOWorker::Start,
|
| + base::Bind(&GCMDriverDesktop::IOWorker::Start,
|
| base::Unretained(io_worker_.get()),
|
| weak_ptr_factory_.GetWeakPtr()));
|
|
|
| return GCMClient::SUCCESS;
|
| }
|
|
|
| -void GCMDriver::Stop() {
|
| +void GCMDriverDesktop::Stop() {
|
| // No need to stop GCM service if not started yet.
|
| if (account_id_.empty())
|
| return;
|
| @@ -657,11 +658,11 @@ void GCMDriver::Stop() {
|
|
|
| io_thread_->PostTask(
|
| FROM_HERE,
|
| - base::Bind(&GCMDriver::IOWorker::Stop,
|
| + base::Bind(&GCMDriverDesktop::IOWorker::Stop,
|
| base::Unretained(io_worker_.get())));
|
| }
|
|
|
| -void GCMDriver::RemoveCachedData() {
|
| +void GCMDriverDesktop::RemoveCachedData() {
|
| DCHECK(ui_thread_->BelongsToCurrentThread());
|
| // Remove all the queued tasks since they no longer make sense after
|
| // GCM service is stopped.
|
| @@ -674,7 +675,7 @@ void GCMDriver::RemoveCachedData() {
|
| send_callbacks_.clear();
|
| }
|
|
|
| -void GCMDriver::CheckOut() {
|
| +void GCMDriverDesktop::CheckOut() {
|
| DCHECK(ui_thread_->BelongsToCurrentThread());
|
|
|
| // We still proceed with the check-out logic even if the check-in is not
|
| @@ -685,19 +686,20 @@ void GCMDriver::CheckOut() {
|
|
|
| io_thread_->PostTask(
|
| FROM_HERE,
|
| - base::Bind(&GCMDriver::IOWorker::CheckOut,
|
| + base::Bind(&GCMDriverDesktop::IOWorker::CheckOut,
|
| base::Unretained(io_worker_.get())));
|
| }
|
|
|
| -bool GCMDriver::IsAsyncOperationPending(const std::string& app_id) const {
|
| +bool GCMDriverDesktop::IsAsyncOperationPending(
|
| + const std::string& app_id) const {
|
| DCHECK(ui_thread_->BelongsToCurrentThread());
|
| return register_callbacks_.find(app_id) != register_callbacks_.end() ||
|
| unregister_callbacks_.find(app_id) != unregister_callbacks_.end();
|
| }
|
|
|
| -void GCMDriver::RegisterFinished(const std::string& app_id,
|
| - const std::string& registration_id,
|
| - GCMClient::Result result) {
|
| +void GCMDriverDesktop::RegisterFinished(const std::string& app_id,
|
| + const std::string& registration_id,
|
| + GCMClient::Result result) {
|
| DCHECK(ui_thread_->BelongsToCurrentThread());
|
|
|
| std::map<std::string, RegisterCallback>::iterator callback_iter =
|
| @@ -712,8 +714,8 @@ void GCMDriver::RegisterFinished(const std::string& app_id,
|
| callback.Run(registration_id, result);
|
| }
|
|
|
| -void GCMDriver::UnregisterFinished(const std::string& app_id,
|
| - GCMClient::Result result) {
|
| +void GCMDriverDesktop::UnregisterFinished(const std::string& app_id,
|
| + GCMClient::Result result) {
|
| DCHECK(ui_thread_->BelongsToCurrentThread());
|
|
|
| std::map<std::string, UnregisterCallback>::iterator callback_iter =
|
| @@ -726,9 +728,9 @@ void GCMDriver::UnregisterFinished(const std::string& app_id,
|
| callback.Run(result);
|
| }
|
|
|
| -void GCMDriver::SendFinished(const std::string& app_id,
|
| - const std::string& message_id,
|
| - GCMClient::Result result) {
|
| +void GCMDriverDesktop::SendFinished(const std::string& app_id,
|
| + const std::string& message_id,
|
| + GCMClient::Result result) {
|
| DCHECK(ui_thread_->BelongsToCurrentThread());
|
|
|
| std::map<std::pair<std::string, std::string>, SendCallback>::iterator
|
| @@ -744,8 +746,8 @@ void GCMDriver::SendFinished(const std::string& app_id,
|
| callback.Run(message_id, result);
|
| }
|
|
|
| -void GCMDriver::MessageReceived(const std::string& app_id,
|
| - GCMClient::IncomingMessage message) {
|
| +void GCMDriverDesktop::MessageReceived(const std::string& app_id,
|
| + GCMClient::IncomingMessage message) {
|
| DCHECK(ui_thread_->BelongsToCurrentThread());
|
|
|
| // Drop the event if signed out.
|
| @@ -755,7 +757,7 @@ void GCMDriver::MessageReceived(const std::string& app_id,
|
| GetAppHandler(app_id)->OnMessage(app_id, message);
|
| }
|
|
|
| -void GCMDriver::MessagesDeleted(const std::string& app_id) {
|
| +void GCMDriverDesktop::MessagesDeleted(const std::string& app_id) {
|
| DCHECK(ui_thread_->BelongsToCurrentThread());
|
|
|
| // Drop the event if signed out.
|
| @@ -765,7 +767,7 @@ void GCMDriver::MessagesDeleted(const std::string& app_id) {
|
| GetAppHandler(app_id)->OnMessagesDeleted(app_id);
|
| }
|
|
|
| -void GCMDriver::MessageSendError(
|
| +void GCMDriverDesktop::MessageSendError(
|
| const std::string& app_id,
|
| const GCMClient::SendErrorDetails& send_error_details) {
|
| DCHECK(ui_thread_->BelongsToCurrentThread());
|
| @@ -777,7 +779,7 @@ void GCMDriver::MessageSendError(
|
| GetAppHandler(app_id)->OnSendError(app_id, send_error_details);
|
| }
|
|
|
| -void GCMDriver::GCMClientReady() {
|
| +void GCMDriverDesktop::GCMClientReady() {
|
| DCHECK(ui_thread_->BelongsToCurrentThread());
|
|
|
| if (gcm_client_ready_)
|
| @@ -787,20 +789,20 @@ void GCMDriver::GCMClientReady() {
|
| delayed_task_controller_->SetReady();
|
| }
|
|
|
| -GCMAppHandler* GCMDriver::GetAppHandler(const std::string& app_id) {
|
| +GCMAppHandler* GCMDriverDesktop::GetAppHandler(const std::string& app_id) {
|
| DCHECK(ui_thread_->BelongsToCurrentThread());
|
|
|
| - std::map<std::string, GCMAppHandler*>::const_iterator iter =
|
| - app_handlers_.find(app_id);
|
| - return iter == app_handlers_.end() ? &default_app_handler_ : iter->second;
|
| + GCMAppHandlerMap::const_iterator iter = app_handlers().find(app_id);
|
| + return iter == app_handlers().end() ? &default_app_handler_ : iter->second;
|
| }
|
|
|
| -void GCMDriver::GetGCMStatisticsFinished(GCMClient::GCMStatistics stats) {
|
| +void GCMDriverDesktop::GetGCMStatisticsFinished(
|
| + GCMClient::GCMStatistics stats) {
|
| DCHECK(ui_thread_->BelongsToCurrentThread());
|
| request_gcm_statistics_callback_.Run(stats);
|
| }
|
|
|
| -std::string GCMDriver::SignedInUserName() const {
|
| +std::string GCMDriverDesktop::SignedInUserName() const {
|
| if (IsStarted())
|
| return identity_provider_->GetActiveUsername();
|
| return std::string();
|
|
|