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

Side by Side 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, 11 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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/scoped_ptr.h"
12 #include "base/task.h"
13
14 class Task;
15 class MessageLoop;
16
17 // Platform abstraction for a notification that can be sent between processes.
18 // Notifications are strings. The string will be prefixed accordingly per
19 // 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.
20 // "org.chromium.Happy").
21 namespace multi_process_notification {
22
23 class ListenerImpl;
24
25 // Posts a notification. Returns true if the notification was posted.
26 bool Post(const std::string& name);
27
28 // A notification listener. Will listen for a given notification and
29 // call the delegate. Note that the delegate is not owned by the listener.
30 class Listener {
31 public:
32 class Delegate {
33 public:
34 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.
35 };
36
37 Listener(const std::string& name, Delegate* delegate);
38 virtual ~Listener();
39
40 virtual bool Start();
41
42 private:
43 scoped_ptr<ListenerImpl> impl_;
44 };
45
46 // A delegate implementation that performs a task when a notification is
47 // received. Note that it does not check the notification, and will fire
48 // for any notification it receives.
49 class PerformTaskOnNotification : public Listener::Delegate {
50 public:
Mark Mentovai 2011/01/04 18:19:33 Bogus indentation throughout this class.
dmac 2011/01/06 06:06:03 Done.
51 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.
52 }
53
54 virtual void OnNotificationReceived(const std::string& name) {
55 task_->Run();
56 task_.reset();
57 }
58
59 bool notification_called() {
60 return task_.get() == NULL;
61 }
62
63 private:
64 scoped_ptr<Task> task_;
65 };
66
67 } // namespace multi_process_notification
68
69 #endif // CHROME_COMMON_MULTI_PROCESS_NOTIFICATION_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698