summaryrefslogtreecommitdiffstats
path: root/chrome/service
diff options
context:
space:
mode:
authorscottbyer@chromium.org <scottbyer@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-01-14 00:12:37 +0000
committerscottbyer@chromium.org <scottbyer@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-01-14 00:12:37 +0000
commit942efaa6d01c225e3771cd49d9baabaf24de67f6 (patch)
tree5510242b007bb2c4ab51346688c07ef0a3bd5e50 /chrome/service
parent61fc8ab9479523bc7962003abea37abfdbac685e (diff)
downloadchromium_src-942efaa6d01c225e3771cd49d9baabaf24de67f6.zip
chromium_src-942efaa6d01c225e3771cd49d9baabaf24de67f6.tar.gz
chromium_src-942efaa6d01c225e3771cd49d9baabaf24de67f6.tar.bz2
Cloud Print Connector Policy, Service-side enforcement.
Have the service process periodically launch the browser (if not connected to the browser already) with a command line switch that instructs the browser to check the policy, shut the service down if it's set, then quit. If the service is already connected to the browser, the launch is not done since the browser is already watching for policy changes and would immediately inform the service. BUG=98049 TEST=Launch the browser, sign into the cloud print connector, quit the browser, set the policy, wait a long time (8 hours) or relaunch the service process - the service process should end up disabled and shut itself down. Review URL: http://codereview.chromium.org/8905023 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@117732 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/service')
-rw-r--r--chrome/service/cloud_print/cloud_print_proxy.cc30
-rw-r--r--chrome/service/cloud_print/cloud_print_proxy.h5
-rw-r--r--chrome/service/service_ipc_server.h4
-rw-r--r--chrome/service/service_process.cc25
-rw-r--r--chrome/service/service_process.h8
5 files changed, 62 insertions, 10 deletions
diff --git a/chrome/service/cloud_print/cloud_print_proxy.cc b/chrome/service/cloud_print/cloud_print_proxy.cc
index df84dde..81f9114 100644
--- a/chrome/service/cloud_print/cloud_print_proxy.cc
+++ b/chrome/service/cloud_print/cloud_print_proxy.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -19,10 +19,9 @@
#include "chrome/service/service_process_prefs.h"
#include "googleurl/src/gurl.h"
-// This method is invoked on the IO thread to launch the browser process to
-// display a desktop notification that the Cloud Print token is invalid and
-// needs re-authentication.
-static void ShowTokenExpiredNotificationInBrowser() {
+namespace {
+
+void LaunchBrowserProcessWithSwitch(const std::string& switch_string) {
DCHECK(g_service_process->io_thread()->message_loop_proxy()->
BelongsToCurrentThread());
FilePath exe_path;
@@ -37,11 +36,24 @@ static void ShowTokenExpiredNotificationInBrowser() {
process_command_line.GetSwitchValuePath(switches::kUserDataDir);
if (!user_data_dir.empty())
cmd_line.AppendSwitchPath(switches::kUserDataDir, user_data_dir);
- cmd_line.AppendSwitch(switches::kNotifyCloudPrintTokenExpired);
+ cmd_line.AppendSwitch(switch_string);
base::LaunchProcess(cmd_line, base::LaunchOptions(), NULL);
}
+// This method is invoked on the IO thread to launch the browser process to
+// display a desktop notification that the Cloud Print token is invalid and
+// needs re-authentication.
+void ShowTokenExpiredNotificationInBrowser() {
+ LaunchBrowserProcessWithSwitch(switches::kNotifyCloudPrintTokenExpired);
+}
+
+void CheckCloudPrintProxyPolicyInBrowser() {
+ LaunchBrowserProcessWithSwitch(switches::kCheckCloudPrintConnectorPolicy);
+}
+
+} // namespace
+
CloudPrintProxy::CloudPrintProxy()
: service_prefs_(NULL),
client_(NULL),
@@ -189,6 +201,11 @@ void CloudPrintProxy::GetProxyInfo(cloud_print::CloudPrintProxyInfo* info) {
service_prefs_->GetString(prefs::kCloudPrintProxyId, &info->proxy_id);
}
+void CloudPrintProxy::CheckCloudPrintProxyPolicy() {
+ g_service_process->io_thread()->message_loop_proxy()->PostTask(
+ FROM_HERE, base::Bind(&CheckCloudPrintProxyPolicyInBrowser));
+}
+
void CloudPrintProxy::OnAuthenticated(
const std::string& robot_oauth_refresh_token,
const std::string& robot_email,
@@ -240,4 +257,3 @@ void CloudPrintProxy::Shutdown() {
backend_->Shutdown();
backend_.reset();
}
-
diff --git a/chrome/service/cloud_print/cloud_print_proxy.h b/chrome/service/cloud_print/cloud_print_proxy.h
index 2cd834bb..0fe6d9c 100644
--- a/chrome/service/cloud_print/cloud_print_proxy.h
+++ b/chrome/service/cloud_print/cloud_print_proxy.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -47,6 +47,9 @@ class CloudPrintProxy : public CloudPrintProxyFrontend,
// Returns the proxy info.
void GetProxyInfo(cloud_print::CloudPrintProxyInfo* info);
+ // Launches a browser to see if the proxy policy has been set.
+ void CheckCloudPrintProxyPolicy();
+
const std::string& user_email() const {
return user_email_;
}
diff --git a/chrome/service/service_ipc_server.h b/chrome/service/service_ipc_server.h
index e309f94..980112d 100644
--- a/chrome/service/service_ipc_server.h
+++ b/chrome/service/service_ipc_server.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -35,6 +35,8 @@ class ServiceIPCServer : public IPC::Channel::Listener,
private:
+ friend class MockServiceIPCServer;
+
// IPC::Channel::Listener implementation.
virtual bool OnMessageReceived(const IPC::Message& msg) OVERRIDE;
virtual void OnChannelConnected(int32 peer_pid) OVERRIDE;
diff --git a/chrome/service/service_process.cc b/chrome/service/service_process.cc
index d2fa127..d66e0f0 100644
--- a/chrome/service/service_process.cc
+++ b/chrome/service/service_process.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -47,6 +47,10 @@ namespace {
// a shutdown.
const int64 kShutdownDelay = 60000;
+// Delay in milliseconds between launching a browser process to check the
+// policy for us. 8 hours * 60 * 60 * 1000
+const int64 kPolicyCheckDelay = 28800000;
+
const char kDefaultServiceProcessLocale[] = "en-US";
class ServiceIOThread : public base::Thread {
@@ -218,6 +222,10 @@ bool ServiceProcess::Initialize(MessageLoopForUI* message_loop,
// See if we need to stay running.
ScheduleShutdownCheck();
+
+ // Occasionally check to see if we need to launch the browser to get the
+ // policy state information.
+ CloudPrintPolicyCheckIfNeeded();
return true;
}
@@ -365,6 +373,21 @@ void ServiceProcess::ShutdownIfNeeded() {
}
}
+void ServiceProcess::ScheduleCloudPrintPolicyCheck() {
+ MessageLoop::current()->PostDelayedTask(
+ FROM_HERE,
+ base::Bind(&ServiceProcess::CloudPrintPolicyCheckIfNeeded,
+ base::Unretained(this)),
+ kPolicyCheckDelay);
+}
+
+void ServiceProcess::CloudPrintPolicyCheckIfNeeded() {
+ if (enabled_services_ && !ipc_server_->is_client_connected()) {
+ GetCloudPrintProxy()->CheckCloudPrintProxyPolicy();
+ }
+ ScheduleCloudPrintPolicyCheck();
+}
+
ServiceProcess::~ServiceProcess() {
Teardown();
g_service_process = NULL;
diff --git a/chrome/service/service_process.h b/chrome/service/service_process.h
index 8859304..19cfc3b 100644
--- a/chrome/service/service_process.h
+++ b/chrome/service/service_process.h
@@ -99,6 +99,8 @@ class ServiceProcess : public CloudPrintProxy::Client {
ServiceURLRequestContextGetter* GetServiceURLRequestContextGetter();
private:
+ friend class TestServiceProcess;
+
// Schedule a call to ShutdownIfNeeded.
void ScheduleShutdownCheck();
@@ -106,6 +108,12 @@ class ServiceProcess : public CloudPrintProxy::Client {
// connected.
void ShutdownIfNeeded();
+ // Schedule a call to CloudPrintPolicyCheckIfNeeded.
+ void ScheduleCloudPrintPolicyCheck();
+
+ // Launch the browser for a policy check if we're not connected.
+ void CloudPrintPolicyCheckIfNeeded();
+
// Called exactly ONCE per process instance for each service that gets
// enabled in this process.
void OnServiceEnabled();