Chromium Code Reviews| Index: components/gcm_driver/gcm_driver_desktop.cc |
| diff --git a/components/gcm_driver/gcm_driver.cc b/components/gcm_driver/gcm_driver_desktop.cc |
| similarity index 72% |
| copy from components/gcm_driver/gcm_driver.cc |
| copy to components/gcm_driver/gcm_driver_desktop.cc |
| index e41972e944770856d073a93788f2713687cfca58..d57aa63faeec17e91dbb64944a1635c9568476a6 100644 |
| --- a/components/gcm_driver/gcm_driver.cc |
| +++ b/components/gcm_driver/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_driver/gcm_driver.h" |
| +#include "components/gcm_driver/gcm_driver_desktop.h" |
| #include <algorithm> |
| #include <utility> |
| @@ -23,7 +23,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(); |
| @@ -49,26 +49,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) |
| @@ -76,7 +78,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::SequencedTaskRunner>& 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::SequencedTaskRunner> ui_thread_; |
| scoped_refptr<base::SequencedTaskRunner> 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::SequencedTaskRunner>& ui_thread, |
| const scoped_refptr<base::SequencedTaskRunner>& io_thread) |
| : ui_thread_(ui_thread), |
| @@ -145,11 +147,11 @@ GCMDriver::IOWorker::IOWorker( |
| DCHECK(ui_thread_->RunsTasksOnCurrentThread()); |
| } |
| -GCMDriver::IOWorker::~IOWorker() { |
| +GCMDriverDesktop::IOWorker::~IOWorker() { |
| DCHECK(io_thread_->RunsTasksOnCurrentThread()); |
| } |
| -void GCMDriver::IOWorker::Initialize( |
| +void GCMDriverDesktop::IOWorker::Initialize( |
| scoped_ptr<GCMClientFactory> gcm_client_factory, |
| const GCMClient::ChromeBuildInfo& chrome_build_info, |
| const base::FilePath& store_path, |
| @@ -169,7 +171,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) { |
| @@ -177,95 +179,102 @@ 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_->RunsTasksOnCurrentThread()); |
| - ui_thread_->PostTask( |
| - FROM_HERE, |
| - base::Bind(&GCMDriver::UnregisterFinished, service_, app_id, result)); |
| + ui_thread_->PostTask(FROM_HERE, |
| + 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_->RunsTasksOnCurrentThread()); |
| 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_->RunsTasksOnCurrentThread()); |
| 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_->RunsTasksOnCurrentThread()); |
| 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_->RunsTasksOnCurrentThread()); |
| 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::OnActivityRecorded() { |
| +void GCMDriverDesktop::IOWorker::OnActivityRecorded() { |
| DCHECK(io_thread_->RunsTasksOnCurrentThread()); |
| // When an activity is recorded, get all the stats and refresh the UI of |
| // gcm-internals page. |
| GetGCMStatistics(false); |
| } |
| -void GCMDriver::IOWorker::Start(const base::WeakPtr<GCMDriver>& service) { |
| +void GCMDriverDesktop::IOWorker::Start( |
| + const base::WeakPtr<GCMDriverDesktop>& service) { |
| DCHECK(io_thread_->RunsTasksOnCurrentThread()); |
| service_ = service; |
| gcm_client_->Start(); |
| } |
| -void GCMDriver::IOWorker::Stop() { |
| +void GCMDriverDesktop::IOWorker::Stop() { |
| DCHECK(io_thread_->RunsTasksOnCurrentThread()); |
| gcm_client_->Stop(); |
| } |
| -void GCMDriver::IOWorker::CheckOut() { |
| +void GCMDriverDesktop::IOWorker::CheckOut() { |
| DCHECK(io_thread_->RunsTasksOnCurrentThread()); |
| 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_->RunsTasksOnCurrentThread()); |
| @@ -273,21 +282,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_->RunsTasksOnCurrentThread()); |
| 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_->RunsTasksOnCurrentThread()); |
| 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_->RunsTasksOnCurrentThread()); |
| gcm::GCMClient::GCMStatistics stats; |
| @@ -299,10 +309,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_->RunsTasksOnCurrentThread()); |
| gcm::GCMClient::GCMStatistics stats; |
| @@ -314,10 +324,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( |
| scoped_ptr<GCMClientFactory> gcm_client_factory, |
| scoped_ptr<IdentityProvider> identity_provider, |
| const GCMClient::ChromeBuildInfo& chrome_build_info, |
| @@ -334,16 +344,14 @@ GCMDriver::GCMDriver( |
| weak_ptr_factory_(this) { |
| // Get the list of available accounts. |
| std::vector<std::string> account_ids; |
| -#if !defined(OS_ANDROID) |
| account_ids = identity_provider_->GetTokenService()->GetAccounts(); |
| -#endif |
| // Create and initialize the GCMClient. Note that this does not initiate the |
| // GCM check-in. |
| 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()), |
| base::Passed(&gcm_client_factory), |
| chrome_build_info, |
| @@ -355,16 +363,35 @@ GCMDriver::GCMDriver( |
| identity_provider_->AddObserver(this); |
| } |
| -GCMDriver::GCMDriver() |
| - : gcm_enabled_(true), |
| - gcm_client_ready_(false), |
| - weak_ptr_factory_(this) { |
| +GCMDriverDesktop::~GCMDriverDesktop() { |
| +} |
| + |
| +void GCMDriverDesktop::Shutdown() { |
| + DCHECK(ui_thread_->RunsTasksOnCurrentThread()); |
| + identity_provider_->RemoveObserver(this); |
| + GCMDriver::Shutdown(); |
| + io_thread_->DeleteSoon(FROM_HERE, io_worker_.release()); |
| } |
| -GCMDriver::~GCMDriver() { |
| +void GCMDriverDesktop::AddAppHandler(const std::string& app_id, |
| + GCMAppHandler* handler) { |
| + DCHECK(ui_thread_->RunsTasksOnCurrentThread()); |
| + GCMDriver::AddAppHandler(app_id, handler); |
| + |
| + // Ensures that the GCM service is started when there is an interest. |
| + EnsureStarted(); |
| } |
| -void GCMDriver::Enable() { |
| +void GCMDriverDesktop::RemoveAppHandler(const std::string& app_id) { |
| + DCHECK(ui_thread_->RunsTasksOnCurrentThread()); |
| + GCMDriver::RemoveAppHandler(app_id); |
| + |
| + // Stops the GCM service when no app intends to consume it. |
| + if (app_handlers().empty()) |
| + Stop(); |
| +} |
| + |
| +void GCMDriverDesktop::Enable() { |
| DCHECK(ui_thread_->RunsTasksOnCurrentThread()); |
| if (gcm_enabled_) |
| @@ -374,7 +401,7 @@ void GCMDriver::Enable() { |
| EnsureStarted(); |
| } |
| -void GCMDriver::Disable() { |
| +void GCMDriverDesktop::Disable() { |
| DCHECK(ui_thread_->RunsTasksOnCurrentThread()); |
| if (!gcm_enabled_) |
| @@ -384,7 +411,7 @@ void GCMDriver::Disable() { |
| Stop(); |
| } |
| -void GCMDriver::Stop() { |
| +void GCMDriverDesktop::Stop() { |
| DCHECK(ui_thread_->RunsTasksOnCurrentThread()); |
| // No need to stop GCM service if not started yet. |
| @@ -395,48 +422,13 @@ 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::Shutdown() { |
| - DCHECK(ui_thread_->RunsTasksOnCurrentThread()); |
| - identity_provider_->RemoveObserver(this); |
| - for (GCMAppHandlerMap::const_iterator iter = app_handlers_.begin(); |
| - iter != app_handlers_.end(); ++iter) { |
| - iter->second->ShutdownHandler(); |
| - } |
| - app_handlers_.clear(); |
| - io_thread_->DeleteSoon(FROM_HERE, io_worker_.release()); |
| -} |
| - |
| -void GCMDriver::AddAppHandler(const std::string& app_id, |
| - GCMAppHandler* handler) { |
| - DCHECK(ui_thread_->RunsTasksOnCurrentThread()); |
| - DCHECK(!app_id.empty()); |
| - DCHECK(handler); |
| - DCHECK(app_handlers_.find(app_id) == app_handlers_.end()); |
| - |
| - app_handlers_[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_->RunsTasksOnCurrentThread()); |
| - DCHECK(!app_id.empty()); |
| - |
| - app_handlers_.erase(app_id); |
| - |
| - // Stops the GCM service when no app intends to consume it. |
| - 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_->RunsTasksOnCurrentThread()); |
| DCHECK(!app_id.empty()); |
| DCHECK(!sender_ids.empty()); |
| @@ -458,7 +450,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)); |
| @@ -468,8 +460,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_->RunsTasksOnCurrentThread()); |
| std::map<std::string, RegisterCallback>::iterator callback_iter = |
| register_callbacks_.find(app_id); |
| @@ -484,14 +476,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_->RunsTasksOnCurrentThread()); |
| DCHECK(!app_id.empty()); |
| DCHECK(!callback.is_null()); |
| @@ -512,16 +504,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_->RunsTasksOnCurrentThread()); |
| // Ask the server to unregister it. There could be a small chance that the |
| @@ -529,15 +522,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_->RunsTasksOnCurrentThread()); |
| DCHECK(!app_id.empty()); |
| DCHECK(!receiver_id.empty()); |
| @@ -560,7 +553,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, |
| @@ -571,75 +564,76 @@ 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_->RunsTasksOnCurrentThread()); |
| 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_->RunsTasksOnCurrentThread()); |
| return io_worker_ ? io_worker_->gcm_client_for_testing() : NULL; |
| } |
| -bool GCMDriver::IsStarted() const { |
| +bool GCMDriverDesktop::IsStarted() const { |
| DCHECK(ui_thread_->RunsTasksOnCurrentThread()); |
| return !account_id_.empty(); |
| } |
| -bool GCMDriver::IsGCMClientReady() const { |
| +bool GCMDriverDesktop::IsGCMClientReady() const { |
| DCHECK(ui_thread_->RunsTasksOnCurrentThread()); |
| return gcm_client_ready_; |
| } |
| -void GCMDriver::GetGCMStatistics(const GetGCMStatisticsCallback& callback, |
| - bool clear_logs) { |
| +void GCMDriverDesktop::GetGCMStatistics( |
| + const GetGCMStatisticsCallback& callback, |
| + bool clear_logs) { |
| DCHECK(ui_thread_->RunsTasksOnCurrentThread()); |
| 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(const GetGCMStatisticsCallback& callback, |
| - bool recording) { |
| +void GCMDriverDesktop::SetGCMRecording(const GetGCMStatisticsCallback& callback, |
| + bool recording) { |
| DCHECK(ui_thread_->RunsTasksOnCurrentThread()); |
| 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_->RunsTasksOnCurrentThread()); |
| if (!gcm_enabled_) |
| return GCMClient::GCM_DISABLED; |
| // Have any app requested the service? |
| - if (app_handlers_.empty()) |
| + if (app_handlers().empty()) |
| return GCMClient::UNKNOWN_ERROR; |
| // Is the user signed in? |
| @@ -661,14 +655,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::RemoveCachedData() { |
| +void GCMDriverDesktop::RemoveCachedData() { |
| DCHECK(ui_thread_->RunsTasksOnCurrentThread()); |
| // Remove all the queued tasks since they no longer make sense after |
| // GCM service is stopped. |
| @@ -681,7 +675,7 @@ void GCMDriver::RemoveCachedData() { |
| send_callbacks_.clear(); |
| } |
| -void GCMDriver::CheckOut() { |
| +void GCMDriverDesktop::CheckOut() { |
| DCHECK(ui_thread_->RunsTasksOnCurrentThread()); |
| // We still proceed with the check-out logic even if the check-in is not |
| @@ -692,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_->RunsTasksOnCurrentThread()); |
| 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_->RunsTasksOnCurrentThread()); |
| std::map<std::string, RegisterCallback>::iterator callback_iter = |
| @@ -719,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_->RunsTasksOnCurrentThread()); |
| std::map<std::string, UnregisterCallback>::iterator callback_iter = |
| @@ -733,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_->RunsTasksOnCurrentThread()); |
| std::map<std::pair<std::string, std::string>, SendCallback>::iterator |
| @@ -751,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) { |
|
Finnur
2014/06/02 21:41:46
Probably not your fault, but could this be passed
|
| DCHECK(ui_thread_->RunsTasksOnCurrentThread()); |
| // Drop the event if signed out. |
| @@ -762,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_->RunsTasksOnCurrentThread()); |
| // Drop the event if signed out. |
| @@ -772,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_->RunsTasksOnCurrentThread()); |
| @@ -784,7 +779,7 @@ void GCMDriver::MessageSendError( |
| GetAppHandler(app_id)->OnSendError(app_id, send_error_details); |
| } |
| -void GCMDriver::GCMClientReady() { |
| +void GCMDriverDesktop::GCMClientReady() { |
| DCHECK(ui_thread_->RunsTasksOnCurrentThread()); |
| if (gcm_client_ready_) |
| @@ -794,15 +789,8 @@ void GCMDriver::GCMClientReady() { |
| delayed_task_controller_->SetReady(); |
| } |
| -GCMAppHandler* GCMDriver::GetAppHandler(const std::string& app_id) { |
| - DCHECK(ui_thread_->RunsTasksOnCurrentThread()); |
| - |
| - std::map<std::string, GCMAppHandler*>::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) { |
|
Finnur
2014/06/02 21:41:46
Same here
|
| DCHECK(ui_thread_->RunsTasksOnCurrentThread()); |
| // Normally request_gcm_statistics_callback_ would not be null. |
| @@ -812,7 +800,7 @@ void GCMDriver::GetGCMStatisticsFinished(GCMClient::GCMStatistics stats) { |
| LOG(WARNING) << "request_gcm_statistics_callback_ is NULL."; |
| } |
| -std::string GCMDriver::SignedInUserName() const { |
| +std::string GCMDriverDesktop::SignedInUserName() const { |
| if (IsStarted()) |
| return identity_provider_->GetActiveUsername(); |
| return std::string(); |