summaryrefslogtreecommitdiffstats
path: root/chrome/service
diff options
context:
space:
mode:
Diffstat (limited to 'chrome/service')
-rw-r--r--chrome/service/cloud_print/cloud_print_proxy.cc116
-rw-r--r--chrome/service/cloud_print/cloud_print_proxy.h8
-rw-r--r--chrome/service/cloud_print/cloud_print_proxy_backend.cc37
-rw-r--r--chrome/service/cloud_print/cloud_print_proxy_backend.h4
-rw-r--r--chrome/service/service_ipc_server.cc12
-rw-r--r--chrome/service/service_ipc_server.h4
6 files changed, 133 insertions, 48 deletions
diff --git a/chrome/service/cloud_print/cloud_print_proxy.cc b/chrome/service/cloud_print/cloud_print_proxy.cc
index 39ffffc..2ade634 100644
--- a/chrome/service/cloud_print/cloud_print_proxy.cc
+++ b/chrome/service/cloud_print/cloud_print_proxy.cc
@@ -61,14 +61,74 @@ void CloudPrintProxy::Initialize(ServiceProcessPrefs* service_prefs,
void CloudPrintProxy::EnableForUser(const std::string& lsid) {
DCHECK(CalledOnValidThread());
- if (backend_.get())
+ if (!CreateBackend())
+ return;
+ DCHECK(backend_.get());
+ // Read persisted robot credentials because we may decide to reuse it if the
+ // passed in LSID belongs the same user.
+ std::string robot_refresh_token;
+ service_prefs_->GetString(prefs::kCloudPrintRobotRefreshToken,
+ &robot_refresh_token);
+ std::string robot_email;
+ service_prefs_->GetString(prefs::kCloudPrintRobotEmail,
+ &robot_email);
+ service_prefs_->GetString(prefs::kCloudPrintEmail, &user_email_);
+
+ // If we have been passed in an LSID, we want to use this to authenticate.
+ // Else we will try and retrieve the last used auth tokens from prefs.
+ if (!lsid.empty()) {
+ backend_->InitializeWithLsid(lsid,
+ proxy_id_,
+ robot_refresh_token,
+ robot_email,
+ user_email_);
+ } else {
+ // See if we have persisted robot credentials.
+ if (!robot_refresh_token.empty()) {
+ DCHECK(!robot_email.empty());
+ backend_->InitializeWithRobotToken(robot_refresh_token,
+ robot_email,
+ proxy_id_);
+ } else {
+ // Finally see if we have persisted user credentials (legacy case).
+ std::string cloud_print_token;
+ service_prefs_->GetString(prefs::kCloudPrintAuthToken,
+ &cloud_print_token);
+ DCHECK(!cloud_print_token.empty());
+ backend_->InitializeWithToken(cloud_print_token, proxy_id_);
+ }
+ }
+ if (client_) {
+ client_->OnCloudPrintProxyEnabled(true);
+ }
+}
+
+void CloudPrintProxy::EnableForUserWithRobot(
+ const std::string& robot_auth_code,
+ const std::string& robot_email,
+ const std::string& user_email) {
+ DCHECK(CalledOnValidThread());
+ if (!CreateBackend())
return;
+ DCHECK(backend_.get());
+ user_email_ = user_email;
+ backend_->InitializeWithRobotAuthCode(robot_auth_code,
+ robot_email,
+ proxy_id_);
+ if (client_) {
+ client_->OnCloudPrintProxyEnabled(true);
+ }
+}
- std::string proxy_id;
- service_prefs_->GetString(prefs::kCloudPrintProxyId, &proxy_id);
- if (proxy_id.empty()) {
- proxy_id = cloud_print::PrintSystem::GenerateProxyId();
- service_prefs_->SetString(prefs::kCloudPrintProxyId, proxy_id);
+bool CloudPrintProxy::CreateBackend() {
+ DCHECK(CalledOnValidThread());
+ if (backend_.get())
+ return false;
+
+ service_prefs_->GetString(prefs::kCloudPrintProxyId, &proxy_id_);
+ if (proxy_id_.empty()) {
+ proxy_id_ = cloud_print::PrintSystem::GenerateProxyId();
+ service_prefs_->SetString(prefs::kCloudPrintProxyId, proxy_id_);
service_prefs_->WritePrefs();
}
@@ -84,7 +144,6 @@ void CloudPrintProxy::EnableForUser(const std::string& lsid) {
if (cloud_print_server_url_str.empty()) {
cloud_print_server_url_str = kDefaultCloudPrintServerUrl;
}
- service_prefs_->GetString(prefs::kCloudPrintEmail, &user_email_);
// By default we don't poll for jobs when we lose XMPP connection. But this
// behavior can be overridden by a preference.
@@ -103,42 +162,7 @@ void CloudPrintProxy::EnableForUser(const std::string& lsid) {
print_system_settings,
oauth_client_info,
enable_job_poll));
- // Read persisted robot credentials because we may decide to reuse it if the
- // passed in LSID belongs the same user.
- std::string robot_refresh_token;
- service_prefs_->GetString(prefs::kCloudPrintRobotRefreshToken,
- &robot_refresh_token);
- std::string robot_email;
- service_prefs_->GetString(prefs::kCloudPrintRobotEmail,
- &robot_email);
-
- // If we have been passed in an LSID, we want to use this to authenticate.
- // Else we will try and retrieve the last used auth tokens from prefs.
- if (!lsid.empty()) {
- backend_->InitializeWithLsid(lsid,
- proxy_id,
- robot_refresh_token,
- robot_email,
- user_email_);
- } else {
- // See if we have persisted robot credentials.
- if (!robot_refresh_token.empty()) {
- DCHECK(!robot_email.empty());
- backend_->InitializeWithRobotToken(robot_refresh_token,
- robot_email,
- proxy_id);
- } else {
- // Finally see if we have persisted user credentials (legacy case).
- std::string cloud_print_token;
- service_prefs_->GetString(prefs::kCloudPrintAuthToken,
- &cloud_print_token);
- DCHECK(!cloud_print_token.empty());
- backend_->InitializeWithToken(cloud_print_token, proxy_id);
- }
- }
- if (client_) {
- client_->OnCloudPrintProxyEnabled(true);
- }
+ return true;
}
void CloudPrintProxy::DisableForUser() {
@@ -154,11 +178,9 @@ void CloudPrintProxy::DisableForUser() {
void CloudPrintProxy::GetProxyInfo(cloud_print::CloudPrintProxyInfo* info) {
info->enabled = enabled_;
info->email.clear();
- info->proxy_id.clear();
if (enabled_)
info->email = user_email();
- if (service_prefs_)
- service_prefs_->GetString(prefs::kCloudPrintProxyId, &info->proxy_id);
+ info->proxy_id = proxy_id_;
}
// Notification methods from the backend. Called on UI thread.
@@ -182,8 +204,8 @@ void CloudPrintProxy::OnAuthenticated(
// If authenticating from a robot, the user email will be empty.
if (!user_email.empty()) {
user_email_ = user_email;
- service_prefs_->SetString(prefs::kCloudPrintEmail, user_email);
}
+ service_prefs_->SetString(prefs::kCloudPrintEmail, user_email_);
enabled_ = true;
DCHECK(!user_email_.empty());
service_prefs_->WritePrefs();
diff --git a/chrome/service/cloud_print/cloud_print_proxy.h b/chrome/service/cloud_print/cloud_print_proxy.h
index 8510a5b..f9e80ef 100644
--- a/chrome/service/cloud_print/cloud_print_proxy.h
+++ b/chrome/service/cloud_print/cloud_print_proxy.h
@@ -39,6 +39,10 @@ class CloudPrintProxy : public CloudPrintProxyFrontend,
// Enables/disables cloud printing for the user
void EnableForUser(const std::string& lsid);
+ void EnableForUserWithRobot(
+ const std::string& robot_auth_code,
+ const std::string& robot_email,
+ const std::string& user_email);
void DisableForUser();
// Returns the proxy info.
void GetProxyInfo(cloud_print::CloudPrintProxyInfo* info);
@@ -58,6 +62,7 @@ class CloudPrintProxy : public CloudPrintProxyFrontend,
protected:
void Shutdown();
+ bool CreateBackend();
// Our asynchronous backend to communicate with sync components living on
// other threads.
@@ -74,6 +79,9 @@ class CloudPrintProxy : public CloudPrintProxyFrontend,
// This is set to true when the Cloud Print proxy is enabled and after
// successful authentication with the Cloud Print service.
bool enabled_;
+ // This is initialized after a successful call to one of the Enable* methods.
+ // It is not cleared in DisableUser.
+ std::string proxy_id_;
DISALLOW_COPY_AND_ASSIGN(CloudPrintProxy);
};
diff --git a/chrome/service/cloud_print/cloud_print_proxy_backend.cc b/chrome/service/cloud_print/cloud_print_proxy_backend.cc
index ea9e09f..a1399eb 100644
--- a/chrome/service/cloud_print/cloud_print_proxy_backend.cc
+++ b/chrome/service/cloud_print/cloud_print_proxy_backend.cc
@@ -69,6 +69,9 @@ class CloudPrintProxyBackend::Core
void DoInitializeWithRobotToken(const std::string& robot_oauth_refresh_token,
const std::string& robot_email,
const std::string& proxy_id);
+ void DoInitializeWithRobotAuthCode(const std::string& robot_oauth_auth_code,
+ const std::string& robot_email,
+ const std::string& proxy_id);
// Called on the CloudPrintProxyBackend core_thread_ to perform
// shutdown.
@@ -340,6 +343,21 @@ bool CloudPrintProxyBackend::InitializeWithRobotToken(
return true;
}
+bool CloudPrintProxyBackend::InitializeWithRobotAuthCode(
+ const std::string& robot_oauth_auth_code,
+ const std::string& robot_email,
+ const std::string& proxy_id) {
+ if (!core_thread_.Start())
+ return false;
+ core_thread_.message_loop()->PostTask(FROM_HERE,
+ NewRunnableMethod(
+ core_.get(),
+ &CloudPrintProxyBackend::Core::DoInitializeWithRobotAuthCode,
+ robot_oauth_auth_code,
+ robot_email,
+ proxy_id));
+ return true;
+}
void CloudPrintProxyBackend::Shutdown() {
core_thread_.message_loop()->PostTask(FROM_HERE,
@@ -449,6 +467,22 @@ void CloudPrintProxyBackend::Core::DoInitializeWithRobotToken(
RefreshAccessToken();
}
+void CloudPrintProxyBackend::Core::DoInitializeWithRobotAuthCode(
+ const std::string& robot_oauth_auth_code,
+ const std::string& robot_email,
+ const std::string& proxy_id) {
+ robot_email_ = robot_email;
+ proxy_id_ = proxy_id;
+ // Now that we have an auth code we need to get the refresh and access tokens.
+ oauth_client_.reset(new gaia::GaiaOAuthClient(
+ gaia::kGaiaOAuth2Url,
+ g_service_process->GetServiceURLRequestContextGetter()));
+ oauth_client_->GetTokensFromAuthCode(oauth_client_info_,
+ robot_oauth_auth_code,
+ kCloudPrintAPIMaxRetryCount,
+ this);
+}
+
void CloudPrintProxyBackend::Core::PostAuthInitialization() {
DCHECK(MessageLoop::current() == backend_->core_thread_.message_loop());
// Now we can get down to registering printers.
@@ -539,7 +573,8 @@ void CloudPrintProxyBackend::Core::DoShutdown() {
index->second->Shutdown();
}
// Important to delete the TalkMediator on this thread.
- talk_mediator_->Logout();
+ if (talk_mediator_.get())
+ talk_mediator_->Logout();
talk_mediator_.reset();
notifications_enabled_ = false;
notifications_enabled_since_ = base::TimeTicks();
diff --git a/chrome/service/cloud_print/cloud_print_proxy_backend.h b/chrome/service/cloud_print/cloud_print_proxy_backend.h
index 71cf92f..603d4cd 100644
--- a/chrome/service/cloud_print/cloud_print_proxy_backend.h
+++ b/chrome/service/cloud_print/cloud_print_proxy_backend.h
@@ -78,6 +78,10 @@ class CloudPrintProxyBackend {
bool InitializeWithRobotToken(const std::string& robot_oauth_refresh_token,
const std::string& robot_email,
const std::string& proxy_id);
+ // Called when an external entity passed in the auth code for the robot.
+ bool InitializeWithRobotAuthCode(const std::string& robot_oauth_auth_code,
+ const std::string& robot_email,
+ const std::string& proxy_id);
void Shutdown();
void RegisterPrinters(const printing::PrinterList& printer_list);
diff --git a/chrome/service/service_ipc_server.cc b/chrome/service/service_ipc_server.cc
index 6f08401..b3582a2 100644
--- a/chrome/service/service_ipc_server.cc
+++ b/chrome/service/service_ipc_server.cc
@@ -101,6 +101,8 @@ bool ServiceIPCServer::OnMessageReceived(const IPC::Message& msg) {
IPC_BEGIN_MESSAGE_MAP(ServiceIPCServer, msg)
IPC_MESSAGE_HANDLER(ServiceMsg_EnableCloudPrintProxy,
OnEnableCloudPrintProxy)
+ IPC_MESSAGE_HANDLER(ServiceMsg_EnableCloudPrintProxyWithRobot,
+ OnEnableCloudPrintProxyWithRobot)
IPC_MESSAGE_HANDLER(ServiceMsg_DisableCloudPrintProxy,
OnDisableCloudPrintProxy)
IPC_MESSAGE_HANDLER(ServiceMsg_GetCloudPrintProxyInfo,
@@ -116,6 +118,16 @@ void ServiceIPCServer::OnEnableCloudPrintProxy(const std::string& lsid) {
g_service_process->GetCloudPrintProxy()->EnableForUser(lsid);
}
+void ServiceIPCServer::OnEnableCloudPrintProxyWithRobot(
+ const std::string& robot_auth_code,
+ const std::string& robot_email,
+ const std::string& user_email) {
+ g_service_process->GetCloudPrintProxy()->EnableForUserWithRobot(
+ robot_auth_code,
+ robot_email,
+ user_email);
+}
+
void ServiceIPCServer::OnGetCloudPrintProxyInfo() {
cloud_print::CloudPrintProxyInfo info;
g_service_process->GetCloudPrintProxy()->GetProxyInfo(&info);
diff --git a/chrome/service/service_ipc_server.h b/chrome/service/service_ipc_server.h
index 71c2a59..eeb1f74 100644
--- a/chrome/service/service_ipc_server.h
+++ b/chrome/service/service_ipc_server.h
@@ -42,6 +42,10 @@ class ServiceIPCServer : public IPC::Channel::Listener,
// IPC message handlers.
void OnEnableCloudPrintProxy(const std::string& lsid);
+ void OnEnableCloudPrintProxyWithRobot(
+ const std::string& robot_auth_code,
+ const std::string& robot_email,
+ const std::string& user_email);
void OnGetCloudPrintProxyInfo();
void OnDisableCloudPrintProxy();