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

Unified Diff: chrome/browser/extensions/extension_function.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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/extensions/extension_function.h
diff --git a/chrome/browser/extensions/extension_function.h b/chrome/browser/extensions/extension_function.h
index f000bf1b51d05eb1d30132f6014c0c278209b565..c57f0b12b1f40018f0dc0c5e951c07ddb8fec49b 100644
--- a/chrome/browser/extensions/extension_function.h
+++ b/chrome/browser/extensions/extension_function.h
@@ -11,16 +11,22 @@
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
+#include "base/memory/weak_ptr.h"
+#include "base/process.h"
+#include "chrome/browser/extensions/extension_info_map.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/common/extensions/extension.h"
#include "content/browser/browser_thread.h"
#include "content/common/notification_observer.h"
#include "content/common/notification_registrar.h"
+#include "ipc/ipc_message.h"
class Browser;
+class ChromeRenderMessageFilter;
class ExtensionFunction;
class ExtensionFunctionDispatcher;
class UIThreadExtensionFunction;
+class IOThreadExtensionFunction;
class ListValue;
class QuotaLimitHeuristic;
class RenderViewHost;
@@ -59,6 +65,7 @@ class ExtensionFunction
ExtensionFunction();
virtual UIThreadExtensionFunction* AsUIThreadExtensionFunction();
+ virtual IOThreadExtensionFunction* AsIOThreadExtensionFunction();
// Execute the API. Clients should initialize the ExtensionFunction using
// SetArgs(), set_request_id(), and the other setters before calling this
@@ -124,11 +131,17 @@ class ExtensionFunction
// Sends the result back to the extension.
virtual void SendResponse(bool success) = 0;
+ // Common implementation for SenderResponse.
+ void SendResponseImpl(base::ProcessHandle process,
+ IPC::Message::Sender* ipc_sender,
+ int routing_id,
+ bool success);
+
// Called when we receive an extension api request that is invalid in a way
// that JSON validation in the renderer should have caught. This should never
// happen and could be an attacker trying to exploit the browser, so we crash
// the renderer instead.
- virtual void HandleBadMessage() = 0;
+ void HandleBadMessage(base::ProcessHandle process);
// Return true if the argument to this function at |index| was provided and
// is non-null.
@@ -257,12 +270,52 @@ class UIThreadExtensionFunction : public ExtensionFunction {
NotificationRegistrar registrar_;
};
- virtual void HandleBadMessage();
-
virtual void Destruct() const;
scoped_ptr<RenderViewHostTracker> tracker_;
+};
+
+// Extension functions that run on the IO thread.
+class IOThreadExtensionFunction : public ExtensionFunction {
+ public:
+ IOThreadExtensionFunction();
+
+ virtual IOThreadExtensionFunction* AsIOThreadExtensionFunction() OVERRIDE;
+
+ void set_ipc_sender(base::WeakPtr<ChromeRenderMessageFilter> ipc_sender,
+ int routing_id) {
+ ipc_sender_ = ipc_sender;
+ routing_id_ = routing_id;
+ }
+ ChromeRenderMessageFilter* ipc_sender() const { return ipc_sender_.get(); }
+ int routing_id() const { return routing_id_; }
+
+ base::WeakPtr<ChromeRenderMessageFilter> ipc_sender_weak() const {
+ return ipc_sender_;
+ }
+
+ void set_extension_info_map(const ExtensionInfoMap* extension_info_map) {
+ extension_info_map_ = extension_info_map;
+ }
+ const ExtensionInfoMap* extension_info_map() const {
+ return extension_info_map_.get();
+ }
+
+ protected:
+ friend struct BrowserThread::DeleteOnThread<BrowserThread::IO>;
+ friend class DeleteTask<IOThreadExtensionFunction>;
+ virtual ~IOThreadExtensionFunction();
+
+ virtual void Destruct() const;
+
+ virtual void SendResponse(bool success);
+
+ private:
+ base::WeakPtr<ChromeRenderMessageFilter> ipc_sender_;
+ int routing_id_;
+
+ scoped_refptr<const ExtensionInfoMap> extension_info_map_;
};
// Base class for an extension function that runs asynchronously *relative to
@@ -290,9 +343,16 @@ class SyncExtensionFunction : public UIThreadExtensionFunction {
protected:
virtual ~SyncExtensionFunction();
+};
- private:
- DISALLOW_COPY_AND_ASSIGN(SyncExtensionFunction);
+class SyncIOThreadExtensionFunction : public IOThreadExtensionFunction {
+ public:
+ SyncIOThreadExtensionFunction();
+
+ virtual void Run() OVERRIDE;
+
+ protected:
+ virtual ~SyncIOThreadExtensionFunction();
};
#endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_FUNCTION_H_
« no previous file with comments | « chrome/browser/extensions/extension_event_router.cc ('k') | chrome/browser/extensions/extension_function.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698