[email protected] | f7885d4 | 2012-04-03 08:30:04 | [diff] [blame] | 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. |
| 4 | |
| 5 | #ifndef CHROME_RENDERER_EXTENSIONS_EXTENSION_REQUEST_SENDER_H_ |
| 6 | #define CHROME_RENDERER_EXTENSIONS_EXTENSION_REQUEST_SENDER_H_ |
| 7 | #pragma once |
| 8 | |
| 9 | #include <string> |
| 10 | #include <map> |
| 11 | |
| 12 | #include "base/memory/linked_ptr.h" |
| 13 | #include "v8/include/v8.h" |
| 14 | |
| 15 | class ChromeV8ContextSet; |
| 16 | class ExtensionDispatcher; |
| 17 | |
| 18 | namespace base { |
| 19 | class ListValue; |
| 20 | } |
| 21 | |
| 22 | struct PendingRequest; |
| 23 | |
| 24 | // Responsible for sending requests for named extension API functions to the |
| 25 | // extension host and routing the responses back to the caller. |
[email protected] | 74e21e7 | 2012-07-09 21:20:53 | [diff] [blame^] | 26 | class ExtensionRequestSender { |
[email protected] | f7885d4 | 2012-04-03 08:30:04 | [diff] [blame] | 27 | public: |
| 28 | explicit ExtensionRequestSender(ExtensionDispatcher* extension_dispatcher, |
| 29 | ChromeV8ContextSet* context_set); |
[email protected] | 74e21e7 | 2012-07-09 21:20:53 | [diff] [blame^] | 30 | ~ExtensionRequestSender(); |
[email protected] | f7885d4 | 2012-04-03 08:30:04 | [diff] [blame] | 31 | |
| 32 | // Makes a call to the API function |name| that is to be handled by the |
[email protected] | 74e21e7 | 2012-07-09 21:20:53 | [diff] [blame^] | 33 | // extension host. The response to this request will be received in |
| 34 | // HandleResponse(). |
| 35 | // TODO(koz): Remove |request_id| and generate that internally. |
| 36 | void StartRequest(const std::string& name, |
| 37 | int request_id, |
| 38 | bool has_callback, |
| 39 | bool for_io_thread, |
| 40 | base::ListValue* value_args); |
| 41 | |
| 42 | // Handles responses from the extension host to calls made by StartRequest(). |
| 43 | void HandleResponse(int request_id, |
| 44 | bool success, |
| 45 | const base::ListValue& response, |
| 46 | const std::string& error); |
| 47 | |
[email protected] | f7885d4 | 2012-04-03 08:30:04 | [diff] [blame] | 48 | |
| 49 | private: |
[email protected] | 74e21e7 | 2012-07-09 21:20:53 | [diff] [blame^] | 50 | typedef std::map<int, linked_ptr<PendingRequest> > PendingRequestMap; |
[email protected] | f7885d4 | 2012-04-03 08:30:04 | [diff] [blame] | 51 | |
| 52 | void InsertRequest(int request_id, PendingRequest* pending_request); |
| 53 | linked_ptr<PendingRequest> RemoveRequest(int request_id); |
| 54 | |
| 55 | ExtensionDispatcher* extension_dispatcher_; |
[email protected] | 21776be | 2012-07-09 03:53:32 | [diff] [blame] | 56 | PendingRequestMap pending_requests_; |
[email protected] | 74e21e7 | 2012-07-09 21:20:53 | [diff] [blame^] | 57 | ChromeV8ContextSet* context_set_; |
[email protected] | 21776be | 2012-07-09 03:53:32 | [diff] [blame] | 58 | |
[email protected] | f7885d4 | 2012-04-03 08:30:04 | [diff] [blame] | 59 | DISALLOW_COPY_AND_ASSIGN(ExtensionRequestSender); |
| 60 | }; |
| 61 | |
| 62 | #endif // CHROME_RENDERER_EXTENSIONS_EXTENSION_REQUEST_SENDER_H_ |