Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(14)

Unified Diff: components/gcm_driver/gcm_driver_desktop.cc

Issue 330733002: Move IdentityProvider usage from GCMDriverDesktop to GCMProfileService (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix after sync Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « components/gcm_driver/gcm_driver_desktop.h ('k') | components/gcm_driver/gcm_driver_desktop_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 d69a98cffa4802c3fecaae185fa2e8f5055c2b86..f0f747403258be2553117094aba4cf2ff8df331d 100644
--- a/components/gcm_driver/gcm_driver_desktop.cc
+++ b/components/gcm_driver/gcm_driver_desktop.cc
@@ -16,7 +16,6 @@
#include "components/gcm_driver/gcm_app_handler.h"
#include "components/gcm_driver/gcm_client_factory.h"
#include "components/gcm_driver/system_encryptor.h"
-#include "google_apis/gaia/oauth2_token_service.h"
#include "net/base/ip_endpoint.h"
#include "net/url_request/url_request_context_getter.h"
@@ -119,7 +118,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);
@@ -164,7 +162,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());
@@ -173,7 +170,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),
@@ -351,24 +347,20 @@ 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),
connected_(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));
@@ -379,29 +371,36 @@ 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::OnSignedIn() {
+ 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.
+ signed_in_ = false;
+ RemoveCachedData();
+
+ io_thread_->PostTask(FROM_HERE,
+ base::Bind(&GCMDriverDesktop::IOWorker::CheckOut,
+ base::Unretained(io_worker_.get())));
}
void GCMDriverDesktop::AddAppHandler(const std::string& app_id,
@@ -446,7 +445,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();
@@ -550,7 +549,7 @@ GCMClient* GCMDriverDesktop::GetGCMClientForTesting() const {
bool GCMDriverDesktop::IsStarted() const {
DCHECK(ui_thread_->RunsTasksOnCurrentThread());
- return !account_id_.empty();
+ return gcm_started_;
}
bool GCMDriverDesktop::IsGCMClientReady() const {
@@ -591,6 +590,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;
@@ -598,18 +600,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_);
delayed_task_controller_.reset(new DelayedTaskController);
@@ -621,6 +615,7 @@ GCMClient::Result GCMDriverDesktop::EnsureStarted() {
base::Unretained(io_worker_.get()),
weak_ptr_factory_.GetWeakPtr()));
+ gcm_started_ = true;
return GCMClient::SUCCESS;
}
@@ -630,34 +625,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);
@@ -666,8 +646,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);
@@ -678,8 +658,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);
@@ -701,7 +681,7 @@ void GCMDriverDesktop::OnConnected(const net::IPEndPoint& ip_endpoint) {
connected_ = true;
// Drop the event if signed out.
- if (account_id_.empty())
+ if (!signed_in_)
return;
const GCMAppHandlerMap& app_handler_map = app_handlers();
@@ -719,7 +699,7 @@ void GCMDriverDesktop::OnDisconnected() {
connected_ = false;
// Drop the event if signed out.
- if (account_id_.empty())
+ if (!signed_in_)
return;
const GCMAppHandlerMap& app_handler_map = app_handlers();
@@ -742,11 +722,5 @@ 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
« no previous file with comments | « components/gcm_driver/gcm_driver_desktop.h ('k') | components/gcm_driver/gcm_driver_desktop_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698