Chromium Code Reviews| 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 9f6a7c2c24b7996428458929cd64b6f2869ad4ba..f5dbdb87a96004fdbbdee2805323df91602bf5c0 100644 |
| --- a/components/gcm_driver/gcm_driver_desktop.cc |
| +++ b/components/gcm_driver/gcm_driver_desktop.cc |
| @@ -109,7 +109,6 @@ class GCMDriverDesktop::IOWorker : public GCMClient::Delegate { |
| scoped_ptr<GCMClientFactory> gcm_client_factory, |
| const GCMClient::ChromeBuildInfo& chrome_build_info, |
| const base::FilePath& store_path, |
| - 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<GCMDriverDesktop>& service); |
| @@ -154,7 +153,6 @@ void GCMDriverDesktop::IOWorker::Initialize( |
| scoped_ptr<GCMClientFactory> gcm_client_factory, |
| const GCMClient::ChromeBuildInfo& chrome_build_info, |
| const base::FilePath& store_path, |
| - const std::vector<std::string>& account_ids, |
| const scoped_refptr<net::URLRequestContextGetter>& request_context, |
| const scoped_refptr<base::SequencedTaskRunner> blocking_task_runner) { |
| DCHECK(io_thread_->RunsTasksOnCurrentThread()); |
| @@ -163,7 +161,6 @@ void GCMDriverDesktop::IOWorker::Initialize( |
| gcm_client_->Initialize(chrome_build_info, |
| store_path, |
| - account_ids, |
| blocking_task_runner, |
| request_context, |
| make_scoped_ptr<Encryptor>(new SystemEncryptor), |
| @@ -328,23 +325,19 @@ void GCMDriverDesktop::IOWorker::SetGCMRecording(bool recording) { |
| GCMDriverDesktop::GCMDriverDesktop( |
| scoped_ptr<GCMClientFactory> gcm_client_factory, |
| - scoped_ptr<IdentityProvider> identity_provider, |
| const GCMClient::ChromeBuildInfo& chrome_build_info, |
| 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) |
| - : gcm_enabled_(true), |
| + : signed_in_(false), |
| + gcm_started_(false), |
| + gcm_enabled_(true), |
| gcm_client_ready_(false), |
| - identity_provider_(identity_provider.Pass()), |
| ui_thread_(ui_thread), |
| io_thread_(io_thread), |
| weak_ptr_factory_(this) { |
| - // Get the list of available accounts. |
| - std::vector<std::string> account_ids; |
| - account_ids = identity_provider_->GetTokenService()->GetAccounts(); |
| - |
| // Create and initialize the GCMClient. Note that this does not initiate the |
| // GCM check-in. |
| io_worker_.reset(new IOWorker(ui_thread, io_thread)); |
| @@ -355,29 +348,38 @@ GCMDriverDesktop::GCMDriverDesktop( |
| base::Passed(&gcm_client_factory), |
| chrome_build_info, |
| store_path, |
| - account_ids, |
| request_context, |
| blocking_task_runner)); |
| - |
| - identity_provider_->AddObserver(this); |
| } |
| GCMDriverDesktop::~GCMDriverDesktop() { |
| } |
| -void GCMDriverDesktop::OnActiveAccountLogin() { |
| - EnsureStarted(); |
| +void GCMDriverDesktop::Shutdown() { |
| + DCHECK(ui_thread_->RunsTasksOnCurrentThread()); |
| + GCMDriver::Shutdown(); |
| + io_thread_->DeleteSoon(FROM_HERE, io_worker_.release()); |
| } |
| -void GCMDriverDesktop::OnActiveAccountLogout() { |
| - CheckOut(); |
| +void GCMDriverDesktop::SignIn() { |
| + signed_in_ = true; |
| + EnsureStarted(); |
| } |
| -void GCMDriverDesktop::Shutdown() { |
| +void GCMDriverDesktop::Purge() { |
| DCHECK(ui_thread_->RunsTasksOnCurrentThread()); |
| - identity_provider_->RemoveObserver(this); |
| - GCMDriver::Shutdown(); |
| - io_thread_->DeleteSoon(FROM_HERE, io_worker_.release()); |
| + |
| + // We still proceed with the check-out logic even if the check-in is not |
| + // initiated in the current session. This will make sure that all the |
| + // persisted data written previously will get purged. |
| + |
|
bartfab (slow)
2014/06/13 11:27:21
Nit: No need for a blank line here.
jianli
2014/06/13 18:04:49
Done.
|
| + signed_in_ = false; |
| + RemoveCachedData(); |
| + |
| + io_thread_->PostTask( |
| + FROM_HERE, |
|
bartfab (slow)
2014/06/13 11:27:21
Nit: Indent two more spaces or, even better, break
jianli
2014/06/13 18:04:49
Done. Caused by new version of VS that did the aut
|
| + base::Bind(&GCMDriverDesktop::IOWorker::CheckOut, |
| + base::Unretained(io_worker_.get()))); |
| } |
| void GCMDriverDesktop::AddAppHandler(const std::string& app_id, |
| @@ -422,7 +424,7 @@ void GCMDriverDesktop::Stop() { |
| DCHECK(ui_thread_->RunsTasksOnCurrentThread()); |
| // No need to stop GCM service if not started yet. |
| - if (account_id_.empty()) |
| + if (!gcm_started_) |
| return; |
| RemoveCachedData(); |
| @@ -526,7 +528,7 @@ GCMClient* GCMDriverDesktop::GetGCMClientForTesting() const { |
| bool GCMDriverDesktop::IsStarted() const { |
| DCHECK(ui_thread_->RunsTasksOnCurrentThread()); |
| - return !account_id_.empty(); |
| + return gcm_started_; |
| } |
| bool GCMDriverDesktop::IsGCMClientReady() const { |
| @@ -563,6 +565,9 @@ void GCMDriverDesktop::SetGCMRecording(const GetGCMStatisticsCallback& callback, |
| GCMClient::Result GCMDriverDesktop::EnsureStarted() { |
| DCHECK(ui_thread_->RunsTasksOnCurrentThread()); |
| + if (gcm_started_) |
| + return GCMClient::SUCCESS; |
| + |
| if (!gcm_enabled_) |
| return GCMClient::GCM_DISABLED; |
| @@ -570,19 +575,10 @@ GCMClient::Result GCMDriverDesktop::EnsureStarted() { |
| if (app_handlers().empty()) |
| return GCMClient::UNKNOWN_ERROR; |
| - // Is the user signed in? |
| - const std::string account_id = identity_provider_->GetActiveAccountId(); |
| - if (account_id.empty()) |
| + // TODO(jianli): to be removed when sign-in enforcement is dropped. |
| + if (!signed_in_) |
| return GCMClient::NOT_SIGNED_IN; |
| - // CheckIn could be called more than once when: |
| - // 1) The password changes. |
| - // 2) Register/send function calls it to ensure CheckIn is done. |
| - if (account_id_ == account_id) |
| - return GCMClient::SUCCESS; |
| - account_id_ = account_id; |
| - |
| - DCHECK(!delayed_task_controller_); |
|
bartfab (slow)
2014/06/13 11:27:21
Why did you remove this DCHECK?
jianli
2014/06/13 18:04:49
This is accidentally removed. Thanks for noticing
|
| delayed_task_controller_.reset(new DelayedTaskController); |
| // Note that we need to pass weak pointer again since the existing weak |
| @@ -593,6 +589,7 @@ GCMClient::Result GCMDriverDesktop::EnsureStarted() { |
| base::Unretained(io_worker_.get()), |
| weak_ptr_factory_.GetWeakPtr())); |
| + gcm_started_ = true; |
| return GCMClient::SUCCESS; |
| } |
| @@ -602,34 +599,19 @@ void GCMDriverDesktop::RemoveCachedData() { |
| // GCM service is stopped. |
| weak_ptr_factory_.InvalidateWeakPtrs(); |
| - account_id_.clear(); |
| + gcm_started_ = false; |
| gcm_client_ready_ = false; |
| delayed_task_controller_.reset(); |
| ClearCallbacks(); |
| } |
| -void GCMDriverDesktop::CheckOut() { |
| - DCHECK(ui_thread_->RunsTasksOnCurrentThread()); |
| - |
| - // We still proceed with the check-out logic even if the check-in is not |
| - // initiated in the current session. This will make sure that all the |
| - // persisted data written previously will get purged. |
| - |
| - RemoveCachedData(); |
| - |
| - io_thread_->PostTask( |
| - FROM_HERE, |
| - base::Bind(&GCMDriverDesktop::IOWorker::CheckOut, |
| - base::Unretained(io_worker_.get()))); |
| -} |
| - |
| void GCMDriverDesktop::MessageReceived( |
| const std::string& app_id, |
| const GCMClient::IncomingMessage& message) { |
| DCHECK(ui_thread_->RunsTasksOnCurrentThread()); |
| - // Drop the event if signed out. |
| - if (account_id_.empty()) |
| + // Drop the event if the service has been stopped. |
| + if (!gcm_started_) |
| return; |
| GetAppHandler(app_id)->OnMessage(app_id, message); |
| @@ -638,8 +620,8 @@ void GCMDriverDesktop::MessageReceived( |
| void GCMDriverDesktop::MessagesDeleted(const std::string& app_id) { |
| DCHECK(ui_thread_->RunsTasksOnCurrentThread()); |
| - // Drop the event if signed out. |
| - if (account_id_.empty()) |
| + // Drop the event if the service has been stopped. |
| + if (!gcm_started_) |
| return; |
| GetAppHandler(app_id)->OnMessagesDeleted(app_id); |
| @@ -650,8 +632,8 @@ void GCMDriverDesktop::MessageSendError( |
| const GCMClient::SendErrorDetails& send_error_details) { |
| DCHECK(ui_thread_->RunsTasksOnCurrentThread()); |
| - // Drop the event if signed out. |
| - if (account_id_.empty()) |
| + // Drop the event if the service has been stopped. |
| + if (!gcm_started_) |
| return; |
| GetAppHandler(app_id)->OnSendError(app_id, send_error_details); |
| @@ -678,10 +660,4 @@ void GCMDriverDesktop::GetGCMStatisticsFinished( |
| LOG(WARNING) << "request_gcm_statistics_callback_ is NULL."; |
| } |
| -std::string GCMDriverDesktop::SignedInUserName() const { |
| - if (IsStarted()) |
| - return identity_provider_->GetActiveUsername(); |
| - return std::string(); |
| -} |
| - |
| } // namespace gcm |