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

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

Issue 7024056: Handle extension webrequest API on the IO thread. This speeds up blocking event (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: review Created 9 years, 6 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) 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_FUNCTION_DISPATCHER_H_ 5 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_FUNCTION_DISPATCHER_H_
6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_FUNCTION_DISPATCHER_H_ 6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_FUNCTION_DISPATCHER_H_
7 #pragma once 7 #pragma once
8 8
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
11 11
12 #include "base/memory/weak_ptr.h" 12 #include "base/memory/weak_ptr.h"
13 #include "chrome/browser/profiles/profile.h"
14 #include "ipc/ipc_message.h"
13 #include "googleurl/src/gurl.h" 15 #include "googleurl/src/gurl.h"
14 #include "ui/gfx/native_widget_types.h" 16 #include "ui/gfx/native_widget_types.h"
15 17
16 class Browser; 18 class Browser;
19 class ChromeRenderMessageFilter;
17 class Extension; 20 class Extension;
18 class ExtensionFunction; 21 class ExtensionFunction;
19 class ListValue; 22 class ListValue;
20 class Profile; 23 class Profile;
21 class RenderViewHost; 24 class RenderViewHost;
22 class TabContents; 25 class TabContents;
23 struct ExtensionHostMsg_Request_Params; 26 struct ExtensionHostMsg_Request_Params;
24 27
25 // A factory function for creating new ExtensionFunction instances. 28 // A factory function for creating new ExtensionFunction instances.
26 typedef ExtensionFunction* (*ExtensionFunctionFactory)(); 29 typedef ExtensionFunction* (*ExtensionFunctionFactory)();
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 static void GetAllFunctionNames(std::vector<std::string>* names); 68 static void GetAllFunctionNames(std::vector<std::string>* names);
66 69
67 // Override a previously registered function. Returns true if successful, 70 // Override a previously registered function. Returns true if successful,
68 // false if no such function was registered. 71 // false if no such function was registered.
69 static bool OverrideFunction(const std::string& name, 72 static bool OverrideFunction(const std::string& name,
70 ExtensionFunctionFactory factory); 73 ExtensionFunctionFactory factory);
71 74
72 // Resets all functions to their initial implementation. 75 // Resets all functions to their initial implementation.
73 static void ResetFunctions(); 76 static void ResetFunctions();
74 77
78 // Dispatches an IO-thread extension function. Only used for specific
79 // functions that must be handled on the IO-thread.
80 static void DispatchOnIOThread(
81 const ExtensionInfoMap* extension_info_map,
82 ProfileId profile_id,
83 int render_process_id,
84 base::WeakPtr<ChromeRenderMessageFilter> ipc_sender,
85 int routing_id,
86 const ExtensionHostMsg_Request_Params& params);
87
75 // Public constructor. Callers must ensure that: 88 // Public constructor. Callers must ensure that:
76 // - |delegate| outlives this object. 89 // - |delegate| outlives this object.
77 // - This object outlives any RenderViewHost's passed to created 90 // - This object outlives any RenderViewHost's passed to created
78 // ExtensionFunctions. 91 // ExtensionFunctions.
79 ExtensionFunctionDispatcher(Profile* profile, Delegate* delegate); 92 ExtensionFunctionDispatcher(Profile* profile, Delegate* delegate);
80 93
81 ~ExtensionFunctionDispatcher(); 94 ~ExtensionFunctionDispatcher();
82 95
83 Delegate* delegate() { return delegate_; } 96 Delegate* delegate() { return delegate_; }
84 97
85 // Message handlers. 98 // Message handlers.
86 void Dispatch(const ExtensionHostMsg_Request_Params& params, 99 void Dispatch(const ExtensionHostMsg_Request_Params& params,
87 RenderViewHost* sender); 100 RenderViewHost* sender);
88 101
89 // Returns the current browser. Callers should generally prefer 102 // Returns the current browser. Callers should generally prefer
90 // ExtensionFunction::GetCurrentBrowser() over this method, as that one 103 // ExtensionFunction::GetCurrentBrowser() over this method, as that one
91 // provides the correct value for |include_incognito|. 104 // provides the correct value for |include_incognito|.
92 // 105 //
93 // See the comments for ExtensionFunction::GetCurrentBrowser() for more 106 // See the comments for ExtensionFunction::GetCurrentBrowser() for more
94 // details. 107 // details.
95 Browser* GetCurrentBrowser(RenderViewHost* render_view_host, 108 Browser* GetCurrentBrowser(RenderViewHost* render_view_host,
96 bool include_incognito); 109 bool include_incognito);
97 110
98 // The profile that this dispatcher is associated with. 111 // The profile that this dispatcher is associated with.
99 Profile* profile() { return profile_; } 112 Profile* profile() { return profile_; }
100 113
101 private: 114 private:
102 // Helper to send an access denied error to the requesting render view. 115 // Helper to creates an ExtensionFunction to handle the function given by
battre 2011/06/08 22:26:05 nit: typo "Helper to creates"
103 void SendAccessDenied(RenderViewHost* render_view_host, int request_id); 116 // |params|. Can be called on any thread.
117 // Does not set subclass properties, or include_incognito.
118 static ExtensionFunction* CreateExtensionFunction(
119 const ExtensionHostMsg_Request_Params& params,
120 const Extension* extension,
121 ProfileId profile_id,
122 int render_process_id,
123 IPC::Message::Sender* ipc_sender,
124 int routing_id);
125
126 // Helper to send an access denied error to the requesting renderer. Can be
127 // called on any thread.
128 static void SendAccessDenied(IPC::Message::Sender* ipc_sender,
129 int routing_id,
130 int request_id);
104 131
105 Profile* profile_; 132 Profile* profile_;
106 133
107 Delegate* delegate_; 134 Delegate* delegate_;
108 }; 135 };
109 136
110 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_FUNCTION_DISPATCHER_H_ 137 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_FUNCTION_DISPATCHER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698