| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef CHROME_COMMON_MULTI_PROCESS_NOTIFICATION_H_ | |
| 6 #define CHROME_COMMON_MULTI_PROCESS_NOTIFICATION_H_ | |
| 7 #pragma once | |
| 8 | |
| 9 #include <string> | |
| 10 | |
| 11 #include "base/basictypes.h" | |
| 12 #include "base/compiler_specific.h" | |
| 13 #include "base/scoped_ptr.h" | |
| 14 | |
| 15 class Task; | |
| 16 class MessageLoop; | |
| 17 | |
| 18 // Platform abstraction for a notification that can be sent between processes. | |
| 19 // Notifications are strings. The string will be prefixed accordingly per | |
| 20 // platform (so on Mac OS X a "Happy" notification will become | |
| 21 // "org.chromium.Happy"). | |
| 22 namespace multi_process_notification { | |
| 23 | |
| 24 class ListenerImpl; | |
| 25 | |
| 26 enum Domain { | |
| 27 // Notifications intended to be received by processes running with the | |
| 28 // same uid and same profile. | |
| 29 ProfileDomain, | |
| 30 // Notifications intended to be received by processes running with the | |
| 31 // same uid. | |
| 32 UserDomain, | |
| 33 // Notifications intended to be received by processes running on the | |
| 34 // same system. | |
| 35 SystemDomain | |
| 36 }; | |
| 37 | |
| 38 // Posts a notification |name| to |domain|. | |
| 39 // Returns true if the notification was posted. | |
| 40 bool Post(const std::string& name, Domain domain); | |
| 41 | |
| 42 // A notification listener. Will listen for a given notification and | |
| 43 // call the delegate. Note that the delegate is not owned by the listener. | |
| 44 class Listener { | |
| 45 public: | |
| 46 class Delegate { | |
| 47 public: | |
| 48 virtual ~Delegate() { } | |
| 49 virtual void OnNotificationReceived(const std::string& name, | |
| 50 Domain domain) = 0; | |
| 51 }; | |
| 52 | |
| 53 Listener(const std::string& name, Domain domain, Delegate* delegate); | |
| 54 | |
| 55 // A destructor is required for scoped_ptr to compile. | |
| 56 ~Listener(); | |
| 57 | |
| 58 bool Start(); | |
| 59 | |
| 60 private: | |
| 61 scoped_ptr<ListenerImpl> impl_; | |
| 62 | |
| 63 DISALLOW_COPY_AND_ASSIGN(Listener); | |
| 64 }; | |
| 65 | |
| 66 // A delegate implementation that performs a task when a notification is | |
| 67 // received. Note that it does not check the notification, and will fire | |
| 68 // for any notification it receives. It will only fire the task on the | |
| 69 // first notification received. | |
| 70 class PerformTaskOnNotification : public Listener::Delegate { | |
| 71 public: | |
| 72 explicit PerformTaskOnNotification(Task* task); | |
| 73 virtual ~PerformTaskOnNotification(); | |
| 74 | |
| 75 virtual void OnNotificationReceived(const std::string& name, | |
| 76 Domain domain) OVERRIDE; | |
| 77 bool WasNotificationReceived(); | |
| 78 | |
| 79 private: | |
| 80 scoped_ptr<Task> task_; | |
| 81 | |
| 82 DISALLOW_COPY_AND_ASSIGN(PerformTaskOnNotification); | |
| 83 }; | |
| 84 | |
| 85 } // namespace multi_process_notification | |
| 86 | |
| 87 #endif // CHROME_COMMON_MULTI_PROCESS_NOTIFICATION_H_ | |
| OLD | NEW |