Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / chrome / browser / extensions / event_router_forwarder.h
blob92b4bc7d74e65f53ab658bce12035458e21c60a6
1 // Copyright (c) 2012 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.
5 #ifndef CHROME_BROWSER_EXTENSIONS_EVENT_ROUTER_FORWARDER_H_
6 #define CHROME_BROWSER_EXTENSIONS_EVENT_ROUTER_FORWARDER_H_
8 #include <string>
10 #include "base/basictypes.h"
11 #include "base/memory/ref_counted.h"
12 #include "base/values.h"
13 #include "chrome/browser/profiles/profile.h"
14 #include "extensions/browser/extension_event_histogram_value.h"
16 class GURL;
18 namespace extensions {
20 // This class forwards events to EventRouters.
21 // The advantages of this class over direct usage of EventRouters are:
22 // - this class is thread-safe, you can call the functions from UI and IO
23 // thread.
24 // - the class can handle if a profile is deleted between the time of sending
25 // the event from the IO thread to the UI thread.
26 // - this class can be used in contexts that are not governed by a profile, e.g.
27 // by system URLRequestContexts. In these cases the |restrict_to_profile|
28 // parameter remains NULL and events are broadcasted to all profiles.
29 class EventRouterForwarder
30 : public base::RefCountedThreadSafe<EventRouterForwarder> {
31 public:
32 EventRouterForwarder();
34 // Calls
35 // DispatchEventToRenderers(event_name, event_args, profile, event_url)
36 // on all (original) profiles' EventRouters.
37 // May be called on any thread.
38 void BroadcastEventToRenderers(events::HistogramValue histogram_value,
39 const std::string& event_name,
40 scoped_ptr<base::ListValue> event_args,
41 const GURL& event_url);
43 // Calls
44 // DispatchEventToExtension(extension_id, event_name, event_args,
45 // profile, event_url)
46 // on all (original) profiles' EventRouters.
47 // May be called on any thread.
48 void BroadcastEventToExtension(const std::string& extension_id,
49 events::HistogramValue histogram_value,
50 const std::string& event_name,
51 scoped_ptr<base::ListValue> event_args,
52 const GURL& event_url);
54 // Calls
55 // DispatchEventToRenderers(event_name, event_args,
56 // use_profile_to_restrict_events ? profile : NULL, event_url)
57 // on |profile|'s EventRouter. May be called on any thread.
58 void DispatchEventToRenderers(events::HistogramValue histogram_value,
59 const std::string& event_name,
60 scoped_ptr<base::ListValue> event_args,
61 void* profile,
62 bool use_profile_to_restrict_events,
63 const GURL& event_url);
65 // Calls
66 // DispatchEventToExtension(extension_id, event_name, event_args,
67 // use_profile_to_restrict_events ? profile : NULL, event_url)
68 // on |profile|'s EventRouter. May be called on any thread.
69 void DispatchEventToExtension(const std::string& extension_id,
70 events::HistogramValue histogram_value,
71 const std::string& event_name,
72 scoped_ptr<base::ListValue> event_args,
73 void* profile,
74 bool use_profile_to_restrict_events,
75 const GURL& event_url);
77 protected:
78 // Protected for testing.
79 virtual ~EventRouterForwarder();
81 // Helper function for {Broadcast,Dispatch}EventTo{Extension,Renderers}.
82 // Virtual for testing.
83 virtual void HandleEvent(const std::string& extension_id,
84 events::HistogramValue histogram_value,
85 const std::string& event_name,
86 scoped_ptr<base::ListValue> event_args,
87 void* profile,
88 bool use_profile_to_restrict_events,
89 const GURL& event_url);
91 // Calls DispatchEventToRenderers or DispatchEventToExtension (depending on
92 // whether extension_id == "" or not) of |profile|'s EventRouter.
93 // |profile| may never be NULL.
94 // Virtual for testing.
95 virtual void CallEventRouter(Profile* profile,
96 const std::string& extension_id,
97 events::HistogramValue histogram_value,
98 const std::string& event_name,
99 scoped_ptr<base::ListValue> event_args,
100 Profile* restrict_to_profile,
101 const GURL& event_url);
103 private:
104 friend class base::RefCountedThreadSafe<EventRouterForwarder>;
106 DISALLOW_COPY_AND_ASSIGN(EventRouterForwarder);
109 } // namespace extensions
111 #endif // CHROME_BROWSER_EXTENSIONS_EVENT_ROUTER_FORWARDER_H_