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

Unified Diff: chrome/common/multi_process_notification.h

Issue 5970015: Add multi-process notification class. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 12 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
Index: chrome/common/multi_process_notification.h
diff --git a/chrome/common/multi_process_notification.h b/chrome/common/multi_process_notification.h
new file mode 100644
index 0000000000000000000000000000000000000000..b2b91a644865b7a7c2c25bb1d4fe24e7c3d6906c
--- /dev/null
+++ b/chrome/common/multi_process_notification.h
@@ -0,0 +1,69 @@
+// Copyright (c) 2011 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.
+
+#ifndef CHROME_COMMON_MULTI_PROCESS_NOTIFICATION_H_
+#define CHROME_COMMON_MULTI_PROCESS_NOTIFICATION_H_
+#pragma once
+
+#include <string>
+
+#include "base/scoped_ptr.h"
+#include "base/task.h"
+
+class Task;
+class MessageLoop;
+
+// Platform abstraction for a notification that can be sent between processes.
+// Notifications are strings. The string will be prefixed accordingly per
+// platform (so on MacOSX a "Happy" notification will become
Mark Mentovai 2011/01/04 18:19:33 Mac OS X is generally spelled with three spaces.
dmac 2011/01/06 06:06:03 Done.
+// "org.chromium.Happy").
+namespace multi_process_notification {
+
+class ListenerImpl;
+
+// Posts a notification. Returns true if the notification was posted.
+bool Post(const std::string& name);
+
+// A notification listener. Will listen for a given notification and
+// call the delegate. Note that the delegate is not owned by the listener.
+class Listener {
+ public:
+ class Delegate {
+ public:
+ virtual void OnNotificationReceived(const std::string& name) = 0;
Mark Mentovai 2011/01/04 18:19:33 Wanna declare a virtual destructor?
dmac 2011/01/06 06:06:03 Done.
+ };
+
+ Listener(const std::string& name, Delegate* delegate);
+ virtual ~Listener();
+
+ virtual bool Start();
+
+ private:
+ scoped_ptr<ListenerImpl> impl_;
+};
+
+// A delegate implementation that performs a task when a notification is
+// received. Note that it does not check the notification, and will fire
+// for any notification it receives.
+class PerformTaskOnNotification : public Listener::Delegate {
+ public:
Mark Mentovai 2011/01/04 18:19:33 Bogus indentation throughout this class.
dmac 2011/01/06 06:06:03 Done.
+ explicit PerformTaskOnNotification(Task* task) : task_(task) {
Mark Mentovai 2011/01/04 18:19:33 Should this class really define its implementation
dmac 2011/01/06 06:06:03 Done.
+ }
+
+ virtual void OnNotificationReceived(const std::string& name) {
+ task_->Run();
+ task_.reset();
+ }
+
+ bool notification_called() {
+ return task_.get() == NULL;
+ }
+
+ private:
+ scoped_ptr<Task> task_;
+ };
+
+} // namespace multi_process_notification
+
+#endif // CHROME_COMMON_MULTI_PROCESS_NOTIFICATION_H_

Powered by Google App Engine
This is Rietveld 408576698