OLD | NEW |
(Empty) | |
| 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. |
| 26 class ExtensionRequestSender { |
| 27 public: |
| 28 explicit ExtensionRequestSender(ExtensionDispatcher* extension_dispatcher, |
| 29 ChromeV8ContextSet* context_set); |
| 30 ~ExtensionRequestSender(); |
| 31 |
| 32 // Makes a call to the API function |name| that is to be handled by the |
| 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 std::string& response, |
| 46 const std::string& error); |
| 47 |
| 48 |
| 49 private: |
| 50 typedef std::map<int, linked_ptr<PendingRequest> > PendingRequestMap; |
| 51 |
| 52 void InsertRequest(int request_id, PendingRequest* pending_request); |
| 53 linked_ptr<PendingRequest> RemoveRequest(int request_id); |
| 54 |
| 55 ExtensionDispatcher* extension_dispatcher_; |
| 56 PendingRequestMap pending_requests_; |
| 57 ChromeV8ContextSet* context_set_; |
| 58 |
| 59 DISALLOW_COPY_AND_ASSIGN(ExtensionRequestSender); |
| 60 }; |
| 61 |
| 62 #endif // CHROME_RENDERER_EXTENSIONS_EXTENSION_REQUEST_SENDER_H_ |
OLD | NEW |