summaryrefslogtreecommitdiffstats
path: root/chrome/browser/printing
diff options
context:
space:
mode:
authorsanjeevr@chromium.org <sanjeevr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-10-07 22:37:38 +0000
committersanjeevr@chromium.org <sanjeevr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-10-07 22:37:38 +0000
commit17543d6da3e6078109e25358481fd3bbd98ab587 (patch)
tree9d92d94d76db72a6feb4becc2e7f77ec89ebcf10 /chrome/browser/printing
parent4c974a138a20ec387ad0f347ca6d0804f26de74e (diff)
downloadchromium_src-17543d6da3e6078109e25358481fd3bbd98ab587.zip
chromium_src-17543d6da3e6078109e25358481fd3bbd98ab587.tar.gz
chromium_src-17543d6da3e6078109e25358481fd3bbd98ab587.tar.bz2
All communication with the cloud print proxy service from the browser now happens in the CloudPrintProxyService class. Added code to start the service process if the cloud print proxy was enabled. Also, when detect an auto-update, we send an IPC to the service process. The service process then shuts down when the browser disconnects.
BUG=None TEST=Unit-tests, test Cloud Print proxy UI, test that when an update is available, the service process shuts down when the browser does. TBR=phajdan.jr Review URL: http://codereview.chromium.org/3617008 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@61871 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/printing')
-rw-r--r--chrome/browser/printing/cloud_print/cloud_print_proxy_service.cc82
-rw-r--r--chrome/browser/printing/cloud_print/cloud_print_proxy_service.h23
-rw-r--r--chrome/browser/printing/cloud_print/cloud_print_setup_flow.cc199
-rw-r--r--chrome/browser/printing/cloud_print/cloud_print_setup_flow.h14
4 files changed, 96 insertions, 222 deletions
diff --git a/chrome/browser/printing/cloud_print/cloud_print_proxy_service.cc b/chrome/browser/printing/cloud_print/cloud_print_proxy_service.cc
index 1067923..20d0a73 100644
--- a/chrome/browser/printing/cloud_print/cloud_print_proxy_service.cc
+++ b/chrome/browser/printing/cloud_print/cloud_print_proxy_service.cc
@@ -16,7 +16,10 @@
#include "chrome/browser/notifications/notification_ui_manager.h"
#include "chrome/browser/prefs/pref_service.h"
#include "chrome/browser/profile.h"
+#include "chrome/browser/service/service_process_control.h"
+#include "chrome/browser/service/service_process_control_manager.h"
#include "chrome/common/pref_names.h"
+#include "chrome/common/service_messages.h"
#include "grit/generated_resources.h"
// TODO(sanjeevr): Localize the product name?
@@ -51,25 +54,34 @@ CloudPrintProxyService::CloudPrintProxyService(Profile* profile)
}
CloudPrintProxyService::~CloudPrintProxyService() {
- Shutdown();
}
void CloudPrintProxyService::Initialize() {
+ if (profile_->GetPrefs()->HasPrefPath(prefs::kCloudPrintEmail) &&
+ !profile_->GetPrefs()->GetString(prefs::kCloudPrintEmail).empty()) {
+ // If the cloud print proxy is enabled, establish a channel with the
+ // service process and update the status.
+ RefreshStatusFromService();
+ }
}
-
-void CloudPrintProxyService::EnableForUser(const std::string& auth_token) {
- // TODO(sanjeevr): Add code to communicate with the cloud print proxy code
- // running in the service process here.
+void CloudPrintProxyService::RefreshStatusFromService() {
+ InvokeServiceTask(
+ NewRunnableMethod(
+ this, &CloudPrintProxyService::RefreshCloudPrintProxyStatus));
}
-void CloudPrintProxyService::DisableForUser() {
- Shutdown();
+void CloudPrintProxyService::EnableForUser(const std::string& lsid,
+ const std::string& email) {
+ InvokeServiceTask(
+ NewRunnableMethod(
+ this, &CloudPrintProxyService::EnableCloudPrintProxy, lsid, email));
}
-void CloudPrintProxyService::Shutdown() {
- // TODO(sanjeevr): Add code to communicate with the cloud print proxy code
- // running in the service process here.
+void CloudPrintProxyService::DisableForUser() {
+ InvokeServiceTask(
+ NewRunnableMethod(
+ this, &CloudPrintProxyService::DisableCloudPrintProxy));
}
bool CloudPrintProxyService::ShowTokenExpiredNotification() {
@@ -126,3 +138,53 @@ void CloudPrintProxyService::OnDialogClosed() {
FROM_HERE, NewRunnableFunction(&BrowserList::EndKeepAlive));
}
+void CloudPrintProxyService::RefreshCloudPrintProxyStatus() {
+ DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI));
+ ServiceProcessControl* process_control =
+ ServiceProcessControlManager::instance()->GetProcessControl(profile_);
+ DCHECK(process_control && process_control->is_connected());
+ if (process_control && process_control->is_connected()) {
+ Callback2<bool, std::string>::Type* callback =
+ NewCallback(this, &CloudPrintProxyService::StatusCallback);
+ // GetCloudPrintProxyStatus takes ownership of callback.
+ process_control->GetCloudPrintProxyStatus(callback);
+ }
+}
+
+void CloudPrintProxyService::EnableCloudPrintProxy(const std::string& lsid,
+ const std::string& email) {
+ ServiceProcessControl* process_control =
+ ServiceProcessControlManager::instance()->GetProcessControl(profile_);
+ DCHECK(process_control && process_control->is_connected());
+ if (process_control->is_connected()) {
+ process_control->Send(new ServiceMsg_EnableCloudPrintProxy(lsid));
+ // Assume the IPC worked.
+ profile_->GetPrefs()->SetString(prefs::kCloudPrintEmail, email);
+ }
+}
+
+void CloudPrintProxyService::DisableCloudPrintProxy() {
+ ServiceProcessControl* process_control =
+ ServiceProcessControlManager::instance()->GetProcessControl(profile_);
+ DCHECK(process_control && process_control->is_connected());
+ if (process_control->is_connected()) {
+ process_control->Send(new ServiceMsg_DisableCloudPrintProxy);
+ // Assume the IPC worked.
+ profile_->GetPrefs()->SetString(prefs::kCloudPrintEmail, std::string());
+ }
+}
+
+void CloudPrintProxyService::StatusCallback(bool enabled, std::string email) {
+ profile_->GetPrefs()->SetString(prefs::kCloudPrintEmail,
+ enabled ? email : std::string());
+}
+
+bool CloudPrintProxyService::InvokeServiceTask(Task* task) {
+ ServiceProcessControl* process_control =
+ ServiceProcessControlManager::instance()->GetProcessControl(profile_);
+ DCHECK(process_control);
+ if (process_control)
+ process_control->Launch(task);
+ return !!process_control;
+}
+
diff --git a/chrome/browser/printing/cloud_print/cloud_print_proxy_service.h b/chrome/browser/printing/cloud_print/cloud_print_proxy_service.h
index 538da2c..220cbd1 100644
--- a/chrome/browser/printing/cloud_print/cloud_print_proxy_service.h
+++ b/chrome/browser/printing/cloud_print/cloud_print_proxy_service.h
@@ -17,7 +17,9 @@ class Profile;
// Layer between the browser user interface and the cloud print proxy code
// running in the service process.
-class CloudPrintProxyService : public CloudPrintSetupFlow::Delegate {
+class CloudPrintProxyService
+ : public CloudPrintSetupFlow::Delegate,
+ public base::RefCountedThreadSafe<CloudPrintProxyService> {
public:
explicit CloudPrintProxyService(Profile* profile);
virtual ~CloudPrintProxyService();
@@ -27,9 +29,13 @@ class CloudPrintProxyService : public CloudPrintSetupFlow::Delegate {
void Initialize();
// Enables/disables cloud printing for the user
- virtual void EnableForUser(const std::string& auth_token);
+ virtual void EnableForUser(const std::string& lsid, const std::string& email);
virtual void DisableForUser();
+ // Query the service process for the status of the cloud print proxy and
+ // update the browser prefs.
+ void RefreshStatusFromService();
+
bool ShowTokenExpiredNotification();
// CloudPrintSetupFlow::Delegate implementation.
@@ -43,7 +49,18 @@ class CloudPrintProxyService : public CloudPrintSetupFlow::Delegate {
Profile* profile_;
scoped_refptr<TokenExpiredNotificationDelegate> token_expired_delegate_;
- void Shutdown();
+ // Methods that send an IPC to the service.
+ void RefreshCloudPrintProxyStatus();
+ void EnableCloudPrintProxy(const std::string& lsid, const std::string& email);
+ void DisableCloudPrintProxy();
+
+ // Callback that gets the cloud print proxy status.
+ void StatusCallback(bool enabled, std::string email);
+ // Invoke a task that gets run after the service process successfully
+ // launches. The task typically involves sending an IPC to the service
+ // process.
+ bool InvokeServiceTask(Task* task);
+
void OnTokenExpiredNotificationError();
void OnTokenExpiredNotificationClosed(bool by_user);
void OnTokenExpiredNotificationClick();
diff --git a/chrome/browser/printing/cloud_print/cloud_print_setup_flow.cc b/chrome/browser/printing/cloud_print/cloud_print_setup_flow.cc
index f74f980..e361062 100644
--- a/chrome/browser/printing/cloud_print/cloud_print_setup_flow.cc
+++ b/chrome/browser/printing/cloud_print/cloud_print_setup_flow.cc
@@ -19,6 +19,7 @@
#endif // defined(TOOLKIT_GTK)
#include "chrome/browser/platform_util.h"
#include "chrome/browser/prefs/pref_service.h"
+#include "chrome/browser/printing/cloud_print/cloud_print_proxy_service.h"
#include "chrome/browser/printing/cloud_print/cloud_print_setup_message_handler.h"
#include "chrome/browser/profile.h"
#include "chrome/browser/remoting/remoting_resources_source.h"
@@ -41,139 +42,6 @@ static const wchar_t kLoginIFrameXPath[] = L"//iframe[@id='login']";
static const wchar_t kDoneIframeXPath[] = L"//iframe[@id='done']";
////////////////////////////////////////////////////////////////////////////////
-// CloudPrintServiceProcessHelper
-//
-// This is a helper class to perform actions when the service process
-// is connected or launched. The events are sent back to CloudPrintSetupFlow
-// when the dialog is still active. CloudPrintSetupFlow can detach from this
-// helper class when the dialog is closed.
-
-class CloudPrintServiceProcessHelper
- : public base::RefCountedThreadSafe<CloudPrintServiceProcessHelper> {
- public:
- explicit CloudPrintServiceProcessHelper(CloudPrintSetupFlow* flow)
- : flow_(flow) {
- }
-
- void Detach() {
- flow_ = NULL;
- }
-
- void OnProcessLaunched() {
- DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI));
- // If the flow is detached then show the done page.
- if (!flow_)
- return;
-
- flow_->OnProcessLaunched();
- }
-
- private:
- CloudPrintSetupFlow* flow_;
-
- DISALLOW_COPY_AND_ASSIGN(CloudPrintServiceProcessHelper);
-};
-
-////////////////////////////////////////////////////////////////////////////////
-// CloudPrintServiceDisableTask
-//
-// This is a helper class to get the proxy service launched if it
-// isn't, in order to properly inform it that it should be disabled.
-
-class CloudPrintServiceDisableTask
- : public base::RefCountedThreadSafe<CloudPrintServiceDisableTask> {
- public:
- explicit CloudPrintServiceDisableTask(Profile* profile)
- : profile_(profile),
- process_control_(NULL) {
- }
-
- void StartDisable() {
- DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI));
-
- process_control_ =
- ServiceProcessControlManager::instance()->GetProcessControl(profile_);
-
- if (process_control_) {
- // If the process isn't connected, launch it now. This will run
- // the task whether the process is already launched or not, as
- // long as it's able to connect back up.
- process_control_->Launch(
- NewRunnableMethod(
- this, &CloudPrintServiceDisableTask::OnProcessLaunched));
- }
- }
-
- void OnProcessLaunched() {
- DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI));
- DCHECK(process_control_);
- if (process_control_->is_connected())
- process_control_->Send(new ServiceMsg_DisableCloudPrintProxy());
- profile_->GetPrefs()->SetString(prefs::kCloudPrintEmail, std::string());
- }
-
- private:
- Profile* profile_;
- ServiceProcessControl* process_control_;
-
- DISALLOW_COPY_AND_ASSIGN(CloudPrintServiceDisableTask);
-};
-
-////////////////////////////////////////////////////////////////////////////////
-// CloudPrintServiceRefreshTask
-//
-// This is a helper class to perform a preferences refresh of the
-// enablement state and registered e-mail from the cloud print proxy
-// service.
-
-class CloudPrintServiceRefreshTask
- : public base::RefCountedThreadSafe<CloudPrintServiceRefreshTask> {
- public:
- explicit CloudPrintServiceRefreshTask(
- Profile* profile,
- Callback2<bool, std::string>::Type* callback)
- : profile_(profile),
- process_control_(NULL),
- callback_(callback) {
- DCHECK(callback);
- }
-
- void StartRefresh() {
- DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI));
-
- process_control_ =
- ServiceProcessControlManager::instance()->GetProcessControl(profile_);
-
- if (process_control_) {
- // If the process isn't connected, launch it now. This will run
- // the task whether the process is already launched or not, as
- // long as it's able to connect back up.
- process_control_->Launch(
- NewRunnableMethod(
- this, &CloudPrintServiceRefreshTask::OnProcessLaunched));
- }
- }
-
- void OnProcessLaunched() {
- DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI));
- DCHECK(process_control_);
-
- if (callback_ != NULL)
- process_control_->GetCloudPrintProxyStatus(callback_.release());
- }
-
- private:
- Profile* profile_;
- ServiceProcessControl* process_control_;
-
- // Callback that gets invoked when a status message is received from
- // the cloud print proxy.
- scoped_ptr<Callback2<bool, std::string>::Type> callback_;
-
- DISALLOW_COPY_AND_ASSIGN(CloudPrintServiceRefreshTask);
-};
-
-////////////////////////////////////////////////////////////////////////////////
// CloudPrintSetupFlow implementation.
// static
@@ -216,28 +84,6 @@ CloudPrintSetupFlow* CloudPrintSetupFlow::OpenDialog(
return flow;
}
-// static
-void CloudPrintSetupFlow::DisableCloudPrintProxy(Profile* profile) {
- scoped_refptr<CloudPrintServiceDisableTask> refresh_task =
- new CloudPrintServiceDisableTask(profile);
- ChromeThread::PostTask(
- ChromeThread::UI, FROM_HERE,
- NewRunnableMethod(refresh_task.get(),
- &CloudPrintServiceDisableTask::StartDisable));
-}
-
-// static
-void CloudPrintSetupFlow::RefreshPreferencesFromService(
- Profile* profile,
- Callback2<bool, std::string>::Type* callback) {
- scoped_refptr<CloudPrintServiceRefreshTask> refresh_task =
- new CloudPrintServiceRefreshTask(profile, callback);
- ChromeThread::PostTask(
- ChromeThread::UI, FROM_HERE,
- NewRunnableMethod(refresh_task.get(),
- &CloudPrintServiceRefreshTask::StartRefresh));
-}
-
CloudPrintSetupFlow::CloudPrintSetupFlow(const std::string& args,
Profile* profile,
Delegate* delegate)
@@ -296,12 +142,6 @@ void CloudPrintSetupFlow::OnDialogClosed(const std::string& json_retval) {
if (authenticator_.get())
authenticator_->CancelRequest();
- // If the service process helper is still active then detach outself from it.
- // This is because the dialog is closing and this object is going to be
- // deleted but the service process launch is still in progress so we don't
- // the service process helper to call us when the process is launched.
- if (service_process_helper_.get())
- service_process_helper_->Detach();
if (delegate_) {
delegate_->OnDialogClosed();
}
@@ -342,26 +182,10 @@ void CloudPrintSetupFlow::OnClientLoginSuccess(
ShowGaiaSuccessAndSettingUp();
authenticator_.reset();
- // And then launch the service process if it has not started yet.
- // If we have already connected to the service process then submit the tokens
- // to it to register the host.
- process_control_ =
- ServiceProcessControlManager::instance()->GetProcessControl(profile_);
-
-#if defined(OS_WIN)
- // TODO(hclam): This call only works on Windows. I need to make it
- // work on other platforms.
- service_process_helper_ = new CloudPrintServiceProcessHelper(this);
-
- // If the process isn't connected, launch it now. This will run the
- // task whether the process is already launched or not, as long as
- // it's able to connect back up.
- process_control_->Launch(
- NewRunnableMethod(service_process_helper_.get(),
- &CloudPrintServiceProcessHelper::OnProcessLaunched));
-#else
+ profile_->GetCloudPrintProxyService()->EnableForUser(credentials.lsid,
+ login_);
+ // TODO(sanjeevr): Should we wait and verify that the enable succeeded?
ShowSetupDone();
-#endif
}
///////////////////////////////////////////////////////////////////////////////
@@ -387,21 +211,6 @@ void CloudPrintSetupFlow::OnUserSubmittedAuth(const std::string& user,
}
///////////////////////////////////////////////////////////////////////////////
-// Method called by CloudPrintServiceProcessHelper
-void CloudPrintSetupFlow::OnProcessLaunched() {
- DCHECK(process_control_->is_connected());
- // TODO(scottbyer): Need to wait for an ACK to be sure that it is
- // actually active.
- if (!lsid_.empty())
- process_control_->Send(new ServiceMsg_EnableCloudPrintProxy(lsid_));
-
- // Save the preference that we have completed the setup of cloud
- // print.
- profile_->GetPrefs()->SetString(prefs::kCloudPrintEmail, login_);
- ShowSetupDone();
-}
-
-///////////////////////////////////////////////////////////////////////////////
// Helper methods for showing contents of the DOM UI
void CloudPrintSetupFlow::ShowGaiaLogin(const DictionaryValue& args) {
if (dom_ui_)
diff --git a/chrome/browser/printing/cloud_print/cloud_print_setup_flow.h b/chrome/browser/printing/cloud_print/cloud_print_setup_flow.h
index 453c1e3..d79e578 100644
--- a/chrome/browser/printing/cloud_print/cloud_print_setup_flow.h
+++ b/chrome/browser/printing/cloud_print/cloud_print_setup_flow.h
@@ -56,15 +56,6 @@ class CloudPrintSetupFlow : public HtmlDialogUIDelegate,
static CloudPrintSetupFlow* OpenDialog(Profile* service, Delegate* delegate,
gfx::NativeWindow parent_window);
- // Disables the cloud print proxy if it's enabled and running.
- static void DisableCloudPrintProxy(Profile* profile);
-
- // Ping the cloud print proxy service in order to get the true
- // enablement state and user e-mail that the service is using, and
- // reflect those back into the browser preferences.
- static void RefreshPreferencesFromService(
- Profile* profile, Callback2<bool, std::string>::Type* callback);
-
// Focuses the dialog. This is useful in cases where the dialog has been
// obscured by a browser window.
void Focus();
@@ -105,9 +96,6 @@ class CloudPrintSetupFlow : public HtmlDialogUIDelegate,
const std::string& password,
const std::string& captcha);
- // Event triggered when the service process was launched.
- void OnProcessLaunched();
-
// The following methods control which iframe is visible.
void ShowGaiaLogin(const DictionaryValue& args);
void ShowGaiaSuccessAndSettingUp();
@@ -131,8 +119,6 @@ class CloudPrintSetupFlow : public HtmlDialogUIDelegate,
// Handle to the ServiceProcessControl which talks to the service process.
ServiceProcessControl* process_control_;
- scoped_refptr<CloudPrintServiceProcessHelper> service_process_helper_;
-
Delegate* delegate_;
DISALLOW_COPY_AND_ASSIGN(CloudPrintSetupFlow);