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

Side by Side Diff: chrome/browser/extensions/extension_event_router_forwarder.h

Issue 10694085: Refactor extension event distribution to use Values instead of JSON strings. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase and review changes. Created 8 years, 5 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
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 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 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_EXTENSION_EVENT_ROUTER_FORWARDER_H_
6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_EVENT_ROUTER_FORWARDER_H_ 6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_EVENT_ROUTER_FORWARDER_H_
7 #pragma once 7 #pragma once
8 8
9 #include <string> 9 #include <string>
10 10
11 #include "base/basictypes.h" 11 #include "base/basictypes.h"
12 #include "base/memory/ref_counted.h" 12 #include "base/memory/ref_counted.h"
13 #include "base/values.h"
13 #include "chrome/browser/profiles/profile.h" 14 #include "chrome/browser/profiles/profile.h"
14 #include "content/public/browser/browser_thread.h" 15 #include "content/public/browser/browser_thread.h"
15 16
16 class GURL; 17 class GURL;
17 18
18 // This class forwards events to ExtensionEventRouters. 19 // This class forwards events to ExtensionEventRouters.
19 // The advantages of this class over direct usage of ExtensionEventRouters are: 20 // The advantages of this class over direct usage of ExtensionEventRouters are:
20 // - 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
21 // thread. 22 // thread.
22 // - 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
23 // the event from the IO thread to the UI thread. 24 // the event from the IO thread to the UI thread.
24 // - 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.
25 // by system URLRequestContexts. In these cases the |restrict_to_profile| 26 // by system URLRequestContexts. In these cases the |restrict_to_profile|
26 // parameter remains NULL and events are broadcasted to all profiles. 27 // parameter remains NULL and events are broadcasted to all profiles.
27 class ExtensionEventRouterForwarder 28 class ExtensionEventRouterForwarder
28 : public base::RefCountedThreadSafe<ExtensionEventRouterForwarder> { 29 : public base::RefCountedThreadSafe<ExtensionEventRouterForwarder> {
29 public: 30 public:
30 ExtensionEventRouterForwarder(); 31 ExtensionEventRouterForwarder();
31 32
32 // Calls 33 // Calls
33 // DispatchEventToRenderers(event_name, event_args, profile, event_url) 34 // DispatchEventToRenderers(event_name, event_args, profile, event_url)
34 // on all (original) profiles' ExtensionEventRouters. 35 // on all (original) profiles' ExtensionEventRouters.
35 // May be called on any thread. 36 // May be called on any thread.
36 void BroadcastEventToRenderers(const std::string& event_name, 37 void BroadcastEventToRenderers(const std::string& event_name,
37 const std::string& event_args, 38 base::ListValue* event_args,
38 const GURL& event_url); 39 const GURL& event_url);
39 40
40 // Calls 41 // Calls
41 // DispatchEventToExtension(extension_id, event_name, event_args, 42 // DispatchEventToExtension(extension_id, event_name, event_args,
42 // profile, event_url) 43 // profile, event_url)
43 // on all (original) profiles' ExtensionEventRouters. 44 // on all (original) profiles' ExtensionEventRouters.
44 // May be called on any thread. 45 // May be called on any thread.
45 void BroadcastEventToExtension(const std::string& extension_id, 46 void BroadcastEventToExtension(const std::string& extension_id,
46 const std::string& event_name, 47 const std::string& event_name,
47 const std::string& event_args, 48 base::ListValue* event_args,
48 const GURL& event_url); 49 const GURL& event_url);
49 50
50 // Calls 51 // Calls
51 // DispatchEventToRenderers(event_name, event_args, 52 // DispatchEventToRenderers(event_name, event_args,
52 // use_profile_to_restrict_events ? profile : NULL, event_url) 53 // use_profile_to_restrict_events ? profile : NULL, event_url)
53 // on |profile|'s ExtensionEventRouter. May be called on any thread. 54 // on |profile|'s ExtensionEventRouter. May be called on any thread.
54 void DispatchEventToRenderers(const std::string& event_name, 55 void DispatchEventToRenderers(const std::string& event_name,
55 const std::string& event_args, 56 base::ListValue* event_args,
56 void* profile, 57 void* profile,
57 bool use_profile_to_restrict_events, 58 bool use_profile_to_restrict_events,
58 const GURL& event_url); 59 const GURL& event_url);
59 60
60 // Calls 61 // Calls
61 // DispatchEventToExtension(extension_id, event_name, event_args, 62 // DispatchEventToExtension(extension_id, event_name, event_args,
62 // use_profile_to_restrict_events ? profile : NULL, event_url) 63 // use_profile_to_restrict_events ? profile : NULL, event_url)
63 // on |profile|'s ExtensionEventRouter. May be called on any thread. 64 // on |profile|'s ExtensionEventRouter. May be called on any thread.
64 void DispatchEventToExtension(const std::string& extension_id, 65 void DispatchEventToExtension(const std::string& extension_id,
65 const std::string& event_name, 66 const std::string& event_name,
66 const std::string& event_args, 67 base::ListValue* event_args,
67 void* profile, 68 void* profile,
68 bool use_profile_to_restrict_events, 69 bool use_profile_to_restrict_events,
69 const GURL& event_url); 70 const GURL& event_url);
70 71
71 protected: 72 protected:
72 // Protected for testing. 73 // Protected for testing.
73 virtual ~ExtensionEventRouterForwarder(); 74 virtual ~ExtensionEventRouterForwarder();
74 75
75 // Helper function for {Broadcast,Dispatch}EventTo{Extension,Renderers}. 76 // Helper function for {Broadcast,Dispatch}EventTo{Extension,Renderers}.
76 // Virtual for testing. 77 // Virtual for testing.
77 virtual void HandleEvent(const std::string& extension_id, 78 virtual void HandleEvent(const std::string& extension_id,
78 const std::string& event_name, 79 const std::string& event_name,
79 const std::string& event_args, 80 base::ListValue* event_args,
80 void* profile, 81 void* profile,
81 bool use_profile_to_restrict_events, 82 bool use_profile_to_restrict_events,
82 const GURL& event_url); 83 const GURL& event_url);
83 84
84 // Calls DispatchEventToRenderers or DispatchEventToExtension (depending on 85 // Calls DispatchEventToRenderers or DispatchEventToExtension (depending on
85 // whether extension_id == "" or not) of |profile|'s ExtensionEventRouter. 86 // whether extension_id == "" or not) of |profile|'s ExtensionEventRouter.
86 // |profile| may never be NULL. 87 // |profile| may never be NULL.
87 // Virtual for testing. 88 // Virtual for testing.
88 virtual void CallExtensionEventRouter(Profile* profile, 89 virtual void CallExtensionEventRouter(Profile* profile,
89 const std::string& extension_id, 90 const std::string& extension_id,
90 const std::string& event_name, 91 const std::string& event_name,
91 const std::string& event_args, 92 base::ListValue* event_args,
92 Profile* restrict_to_profile, 93 Profile* restrict_to_profile,
93 const GURL& event_url); 94 const GURL& event_url);
94 95
95 private: 96 private:
96 friend class base::RefCountedThreadSafe<ExtensionEventRouterForwarder>; 97 friend class base::RefCountedThreadSafe<ExtensionEventRouterForwarder>;
97 98
98 DISALLOW_COPY_AND_ASSIGN(ExtensionEventRouterForwarder); 99 DISALLOW_COPY_AND_ASSIGN(ExtensionEventRouterForwarder);
99 }; 100 };
100 101
101 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_EVENT_ROUTER_FORWARDER_H_ 102 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_EVENT_ROUTER_FORWARDER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698