OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_EVENT_ROUTER_FORWARDER_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_EVENT_ROUTER_FORWARDER_H_ |
6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_EVENT_ROUTER_FORWARDER_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_EVENT_ROUTER_FORWARDER_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
12 #include "chrome/browser/profiles/profile.h" | 12 #include "chrome/browser/profiles/profile.h" |
13 #include "content/public/browser/browser_thread.h" | 13 #include "content/public/browser/browser_thread.h" |
14 | 14 |
15 class GURL; | 15 class GURL; |
16 | 16 |
17 // This class forwards events to ExtensionEventRouters. | 17 namespace extensions { |
18 // The advantages of this class over direct usage of ExtensionEventRouters are: | 18 |
| 19 // This class forwards events to EventRouters. |
| 20 // The advantages of this class over direct usage of EventRouters are: |
19 // - this class is thread-safe, you can call the functions from UI and IO | 21 // - this class is thread-safe, you can call the functions from UI and IO |
20 // thread. | 22 // thread. |
21 // - the class can handle if a profile is deleted between the time of sending | 23 // - the class can handle if a profile is deleted between the time of sending |
22 // the event from the IO thread to the UI thread. | 24 // the event from the IO thread to the UI thread. |
23 // - this class can be used in contexts that are not governed by a profile, e.g. | 25 // - this class can be used in contexts that are not governed by a profile, e.g. |
24 // by system URLRequestContexts. In these cases the |restrict_to_profile| | 26 // by system URLRequestContexts. In these cases the |restrict_to_profile| |
25 // parameter remains NULL and events are broadcasted to all profiles. | 27 // parameter remains NULL and events are broadcasted to all profiles. |
26 class ExtensionEventRouterForwarder | 28 class EventRouterForwarder |
27 : public base::RefCountedThreadSafe<ExtensionEventRouterForwarder> { | 29 : public base::RefCountedThreadSafe<EventRouterForwarder> { |
28 public: | 30 public: |
29 ExtensionEventRouterForwarder(); | 31 EventRouterForwarder(); |
30 | 32 |
31 // Calls | 33 // Calls |
32 // DispatchEventToRenderers(event_name, event_args, profile, event_url) | 34 // DispatchEventToRenderers(event_name, event_args, profile, event_url) |
33 // on all (original) profiles' ExtensionEventRouters. | 35 // on all (original) profiles' EventRouters. |
34 // May be called on any thread. | 36 // May be called on any thread. |
35 void BroadcastEventToRenderers(const std::string& event_name, | 37 void BroadcastEventToRenderers(const std::string& event_name, |
36 const std::string& event_args, | 38 const std::string& event_args, |
37 const GURL& event_url); | 39 const GURL& event_url); |
38 | 40 |
39 // Calls | 41 // Calls |
40 // DispatchEventToExtension(extension_id, event_name, event_args, | 42 // DispatchEventToExtension(extension_id, event_name, event_args, |
41 // profile, event_url) | 43 // profile, event_url) |
42 // on all (original) profiles' ExtensionEventRouters. | 44 // on all (original) profiles' EventRouters. |
43 // May be called on any thread. | 45 // May be called on any thread. |
44 void BroadcastEventToExtension(const std::string& extension_id, | 46 void BroadcastEventToExtension(const std::string& extension_id, |
45 const std::string& event_name, | 47 const std::string& event_name, |
46 const std::string& event_args, | 48 const std::string& event_args, |
47 const GURL& event_url); | 49 const GURL& event_url); |
48 | 50 |
49 // Calls | 51 // Calls |
50 // DispatchEventToRenderers(event_name, event_args, | 52 // DispatchEventToRenderers(event_name, event_args, |
51 // use_profile_to_restrict_events ? profile : NULL, event_url) | 53 // use_profile_to_restrict_events ? profile : NULL, event_url) |
52 // on |profile|'s ExtensionEventRouter. May be called on any thread. | 54 // on |profile|'s EventRouter. May be called on any thread. |
53 void DispatchEventToRenderers(const std::string& event_name, | 55 void DispatchEventToRenderers(const std::string& event_name, |
54 const std::string& event_args, | 56 const std::string& event_args, |
55 void* profile, | 57 void* profile, |
56 bool use_profile_to_restrict_events, | 58 bool use_profile_to_restrict_events, |
57 const GURL& event_url); | 59 const GURL& event_url); |
58 | 60 |
59 // Calls | 61 // Calls |
60 // DispatchEventToExtension(extension_id, event_name, event_args, | 62 // DispatchEventToExtension(extension_id, event_name, event_args, |
61 // use_profile_to_restrict_events ? profile : NULL, event_url) | 63 // use_profile_to_restrict_events ? profile : NULL, event_url) |
62 // on |profile|'s ExtensionEventRouter. May be called on any thread. | 64 // on |profile|'s EventRouter. May be called on any thread. |
63 void DispatchEventToExtension(const std::string& extension_id, | 65 void DispatchEventToExtension(const std::string& extension_id, |
64 const std::string& event_name, | 66 const std::string& event_name, |
65 const std::string& event_args, | 67 const std::string& event_args, |
66 void* profile, | 68 void* profile, |
67 bool use_profile_to_restrict_events, | 69 bool use_profile_to_restrict_events, |
68 const GURL& event_url); | 70 const GURL& event_url); |
69 | 71 |
70 protected: | 72 protected: |
71 // Protected for testing. | 73 // Protected for testing. |
72 virtual ~ExtensionEventRouterForwarder(); | 74 virtual ~EventRouterForwarder(); |
73 | 75 |
74 // Helper function for {Broadcast,Dispatch}EventTo{Extension,Renderers}. | 76 // Helper function for {Broadcast,Dispatch}EventTo{Extension,Renderers}. |
75 // Virtual for testing. | 77 // Virtual for testing. |
76 virtual void HandleEvent(const std::string& extension_id, | 78 virtual void HandleEvent(const std::string& extension_id, |
77 const std::string& event_name, | 79 const std::string& event_name, |
78 const std::string& event_args, | 80 const std::string& event_args, |
79 void* profile, | 81 void* profile, |
80 bool use_profile_to_restrict_events, | 82 bool use_profile_to_restrict_events, |
81 const GURL& event_url); | 83 const GURL& event_url); |
82 | 84 |
83 // Calls DispatchEventToRenderers or DispatchEventToExtension (depending on | 85 // Calls DispatchEventToRenderers or DispatchEventToExtension (depending on |
84 // whether extension_id == "" or not) of |profile|'s ExtensionEventRouter. | 86 // whether extension_id == "" or not) of |profile|'s EventRouter. |
85 // |profile| may never be NULL. | 87 // |profile| may never be NULL. |
86 // Virtual for testing. | 88 // Virtual for testing. |
87 virtual void CallExtensionEventRouter(Profile* profile, | 89 virtual void CallEventRouter(Profile* profile, |
88 const std::string& extension_id, | 90 const std::string& extension_id, |
89 const std::string& event_name, | 91 const std::string& event_name, |
90 const std::string& event_args, | 92 const std::string& event_args, |
91 Profile* restrict_to_profile, | 93 Profile* restrict_to_profile, |
92 const GURL& event_url); | 94 const GURL& event_url); |
93 | 95 |
94 private: | 96 private: |
95 friend class base::RefCountedThreadSafe<ExtensionEventRouterForwarder>; | 97 friend class base::RefCountedThreadSafe<EventRouterForwarder>; |
96 | 98 |
97 DISALLOW_COPY_AND_ASSIGN(ExtensionEventRouterForwarder); | 99 DISALLOW_COPY_AND_ASSIGN(EventRouterForwarder); |
98 }; | 100 }; |
99 | 101 |
100 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_EVENT_ROUTER_FORWARDER_H_ | 102 } // namespace extensions |
| 103 |
| 104 #endif // CHROME_BROWSER_EXTENSIONS_EVENT_ROUTER_FORWARDER_H_ |
OLD | NEW |