Chromium Code Reviews| 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/scoped_ptr.h" | |
| 13 #include "base/task.h" | |
| 14 | |
| 15 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.
| |
| 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 { | |
|
Mark Mentovai
2011/01/06 17:59:09
Good solution.
dmac
2011/01/06 18:22:37
Thanks
| |
| 27 ProfileDomain, | |
| 28 UserDomain, | |
| 29 SystemDomain | |
| 30 }; | |
| 31 | |
| 32 // Posts a notification intended to |domain|. | |
| 33 // Returns true if the notification was posted. | |
| 34 bool Post(const std::string& name, Domain domain); | |
| 35 | |
| 36 // A notification listener. Will listen for a given notification and | |
| 37 // call the delegate. Note that the delegate is not owned by the listener. | |
| 38 class Listener { | |
| 39 public: | |
| 40 class Delegate { | |
| 41 public: | |
| 42 virtual ~Delegate() { } | |
| 43 virtual void OnNotificationReceived(const std::string& name) = 0; | |
| 44 }; | |
| 45 | |
| 46 Listener(const std::string& name, Domain domain, Delegate* delegate); | |
| 47 | |
| 48 // 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
| |
| 49 ~Listener(); | |
| 50 | |
| 51 bool Start(); | |
| 52 | |
| 53 private: | |
| 54 scoped_ptr<ListenerImpl> impl_; | |
| 55 | |
| 56 DISALLOW_COPY_AND_ASSIGN(Listener); | |
| 57 }; | |
| 58 | |
| 59 // A delegate implementation that performs a task when a notification is | |
| 60 // received. Note that it does not check the notification, and will fire | |
| 61 // for any notification it receives. | |
| 62 class PerformTaskOnNotification : public Listener::Delegate { | |
| 63 public: | |
| 64 explicit PerformTaskOnNotification(Task* task); | |
| 65 virtual ~PerformTaskOnNotification(); | |
| 66 | |
| 67 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.
| |
| 68 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.
| |
| 69 | |
| 70 private: | |
| 71 scoped_ptr<Task> task_; | |
| 72 | |
| 73 DISALLOW_COPY_AND_ASSIGN(PerformTaskOnNotification); | |
| 74 }; | |
| 75 | |
| 76 } // namespace multi_process_notification | |
| 77 | |
| 78 #endif // CHROME_COMMON_MULTI_PROCESS_NOTIFICATION_H_ | |
| OLD | NEW |