summaryrefslogtreecommitdiffstats
path: root/chrome/browser/service
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/service
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/service')
-rw-r--r--chrome/browser/service/service_process_control.cc22
-rw-r--r--chrome/browser/service/service_process_control.h12
-rw-r--r--chrome/browser/service/service_process_control_browsertest.cc40
3 files changed, 70 insertions, 4 deletions
diff --git a/chrome/browser/service/service_process_control.cc b/chrome/browser/service/service_process_control.cc
index 6790b00..22ad863 100644
--- a/chrome/browser/service/service_process_control.cc
+++ b/chrome/browser/service/service_process_control.cc
@@ -11,8 +11,10 @@
#include "chrome/browser/browser_process.h"
#include "chrome/browser/chrome_thread.h"
#include "chrome/browser/io_thread.h"
+#include "chrome/browser/upgrade_detector.h"
#include "chrome/common/child_process_host.h"
#include "chrome/common/chrome_switches.h"
+#include "chrome/common/notification_service.h"
#include "chrome/common/service_messages.h"
#include "chrome/common/service_process_util.h"
@@ -108,6 +110,16 @@ void ServiceProcessControl::ConnectInternal(Task* task) {
io_thread->message_loop(), true,
g_browser_process->shutdown_event()));
channel_->set_sync_messages_with_no_timeout_allowed(false);
+
+ // We just established a channel with the service process. Notify it if an
+ // upgrade is available.
+ if (Singleton<UpgradeDetector>::get()->notify_upgrade()) {
+ Send(new ServiceMsg_UpdateAvailable);
+ } else {
+ if (registrar_.IsEmpty())
+ registrar_.Add(this, NotificationType::UPGRADE_RECOMMENDED,
+ NotificationService::AllSources());
+ }
}
void ServiceProcessControl::Launch(Task* task) {
@@ -200,6 +212,16 @@ bool ServiceProcessControl::Send(IPC::Message* message) {
return channel_->Send(message);
}
+// NotificationObserver implementation.
+void ServiceProcessControl::Observe(NotificationType type,
+ const NotificationSource& source,
+ const NotificationDetails& details) {
+ if (type == NotificationType::UPGRADE_RECOMMENDED) {
+ Send(new ServiceMsg_UpdateAvailable);
+ }
+}
+
+
void ServiceProcessControl::OnGoodDay() {
if (!message_handler_)
return;
diff --git a/chrome/browser/service/service_process_control.h b/chrome/browser/service/service_process_control.h
index 021b669..e6df376 100644
--- a/chrome/browser/service/service_process_control.h
+++ b/chrome/browser/service/service_process_control.h
@@ -13,6 +13,8 @@
#include "base/process.h"
#include "base/scoped_ptr.h"
#include "base/task.h"
+#include "chrome/common/notification_observer.h"
+#include "chrome/common/notification_registrar.h"
#include "ipc/ipc_sync_channel.h"
class Profile;
@@ -28,7 +30,8 @@ class Profile;
// This class is accessed on the UI thread through some UI actions. It then
// talks to the IPC channel on the IO thread.
class ServiceProcessControl : public IPC::Channel::Sender,
- public IPC::Channel::Listener {
+ public IPC::Channel::Listener,
+ public NotificationObserver {
public:
typedef IDMap<ServiceProcessControl>::iterator iterator;
typedef std::queue<IPC::Message> MessageQueue;
@@ -67,6 +70,11 @@ class ServiceProcessControl : public IPC::Channel::Sender,
// IPC::Channel::Sender implementation
virtual bool Send(IPC::Message* message);
+ // NotificationObserver implementation.
+ virtual void Observe(NotificationType type,
+ const NotificationSource& source,
+ const NotificationDetails& details);
+
// Message handlers
void OnGoodDay();
void OnCloudPrintProxyIsEnabled(bool enabled, std::string email);
@@ -127,6 +135,8 @@ class ServiceProcessControl : public IPC::Channel::Sender,
// Handler for messages from service process.
MessageHandler* message_handler_;
+
+ NotificationRegistrar registrar_;
};
#endif // CHROME_BROWSER_SERVICE_SERVICE_PROCESS_CONTROL_H_
diff --git a/chrome/browser/service/service_process_control_browsertest.cc b/chrome/browser/service/service_process_control_browsertest.cc
index 391f99f..e48a60c 100644
--- a/chrome/browser/service/service_process_control_browsertest.cc
+++ b/chrome/browser/service/service_process_control_browsertest.cc
@@ -2,11 +2,13 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "chrome/test/in_process_browser_test.h"
-#include "chrome/test/ui_test_utils.h"
+#include "base/test/test_timeouts.h"
#include "chrome/browser/browser.h"
#include "chrome/browser/service/service_process_control.h"
#include "chrome/browser/service/service_process_control_manager.h"
+#include "chrome/common/service_process_util.h"
+#include "chrome/test/in_process_browser_test.h"
+#include "chrome/test/ui_test_utils.h"
class ServiceProcessControlBrowserTest
: public InProcessBrowserTest,
@@ -29,11 +31,32 @@ class ServiceProcessControlBrowserTest
}
void SayHelloAndWait() {
- // Send a hello message to the service process and wait for a reply.
+ // Send a hello message to the service process and wait for a reply.
process()->SendHello();
ui_test_utils::RunMessageLoop();
}
+ void DisconnectAndWaitForShutdown() {
+ // This will delete all instances of ServiceProcessControl and close the IPC
+ // connections.
+ ServiceProcessControlManager::instance()->Shutdown();
+ process_ = NULL;
+ MessageLoop::current()->PostDelayedTask(
+ FROM_HERE,
+ NewRunnableMethod(this,
+ &ServiceProcessControlBrowserTest::DoDetectShutdown),
+ TestTimeouts::wait_for_terminate_timeout_ms());
+ ui_test_utils::RunMessageLoop();
+ }
+
+
+ void DoDetectShutdown() {
+ EXPECT_FALSE(CheckServiceProcessRunning());
+ // Quit the current message loop.
+ MessageLoop::current()->PostTask(FROM_HERE,
+ new MessageLoop::QuitTask());
+ }
+
void ProcessControlLaunched() {
process()->SetMessageHandler(this);
// Quit the current message.
@@ -85,6 +108,17 @@ IN_PROC_BROWSER_TEST_F(ServiceProcessControlBrowserTest, LaunchTwice) {
// And then shutdown the service process.
EXPECT_TRUE(process()->Shutdown());
}
+
+// Tests whether disconnecting from the service IPC causes the service process
+// to die.
+IN_PROC_BROWSER_TEST_F(ServiceProcessControlBrowserTest, DieOnDisconnect) {
+ // Launch the service process the first time.
+ LaunchServiceProcessControl();
+ // Make sure we are connected to the service process.
+ EXPECT_TRUE(process()->is_connected());
+ DisconnectAndWaitForShutdown();
+}
+
#endif
DISABLE_RUNNABLE_METHOD_REFCOUNT(ServiceProcessControlBrowserTest);