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..b277f84b10327f747a4b7ff32ab24546ba6021eb |
--- /dev/null |
+++ b/chrome/common/multi_process_notification.h |
@@ -0,0 +1,78 @@ |
+// 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/basictypes.h" |
+#include "base/scoped_ptr.h" |
+#include "base/task.h" |
+ |
+class Task; |
Mark Mentovai
2011/01/06 17:59:09
This forward declaration isn’t necessary, as you’v
dmac
2011/01/06 18:22:37
Done.
|
+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 Mac OS X a "Happy" notification will become |
+// "org.chromium.Happy"). |
+namespace multi_process_notification { |
+ |
+class ListenerImpl; |
+ |
+enum Domain { |
Mark Mentovai
2011/01/06 17:59:09
Good solution.
dmac
2011/01/06 18:22:37
Thanks
|
+ ProfileDomain, |
+ UserDomain, |
+ SystemDomain |
+}; |
+ |
+// Posts a notification intended to |domain|. |
+// Returns true if the notification was posted. |
+bool Post(const std::string& name, Domain domain); |
+ |
+// 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 ~Delegate() { } |
+ virtual void OnNotificationReceived(const std::string& name) = 0; |
+ }; |
+ |
+ Listener(const std::string& name, Domain domain, Delegate* delegate); |
+ |
+ // Dtor required for scoped_ptr to compile. |
Mark Mentovai
2011/01/06 17:59:09
A few more characters would yield a complete sente
dmac
2011/01/06 18:22:37
Done. It is as far as I can tell. Without this d't
|
+ ~Listener(); |
+ |
+ bool Start(); |
+ |
+ private: |
+ scoped_ptr<ListenerImpl> impl_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(Listener); |
+}; |
+ |
+// 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: |
+ explicit PerformTaskOnNotification(Task* task); |
+ virtual ~PerformTaskOnNotification(); |
+ |
+ virtual void OnNotificationReceived(const std::string& name); |
Mark Mentovai
2011/01/06 17:59:09
Do you want to use that goofy OVERRIDE macro from
dmac
2011/01/06 18:22:37
Done.
|
+ bool WasNotificationCalled(); |
Mark Mentovai
2011/01/06 17:59:09
I think that WasNotificationReceived() is a more a
dmac
2011/01/06 18:22:37
Good call. Done.
|
+ |
+ private: |
+ scoped_ptr<Task> task_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(PerformTaskOnNotification); |
+}; |
+ |
+} // namespace multi_process_notification |
+ |
+#endif // CHROME_COMMON_MULTI_PROCESS_NOTIFICATION_H_ |