| OLD | NEW |
| 1 // Copyright (c) 2012 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_RENDERER_EXTENSIONS_REQUEST_SENDER_H_ | 5 #ifndef CHROME_RENDERER_EXTENSIONS_REQUEST_SENDER_H_ |
| 6 #define CHROME_RENDERER_EXTENSIONS_REQUEST_SENDER_H_ | 6 #define CHROME_RENDERER_EXTENSIONS_REQUEST_SENDER_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 #include <map> | 9 #include <map> |
| 10 | 10 |
| 11 #include "base/memory/linked_ptr.h" | 11 #include "base/memory/linked_ptr.h" |
| 12 #include "v8/include/v8.h" | 12 #include "v8/include/v8.h" |
| 13 | 13 |
| 14 namespace base { | 14 namespace base { |
| 15 class ListValue; | 15 class ListValue; |
| 16 } | 16 } |
| 17 | 17 |
| 18 namespace extensions { | 18 namespace extensions { |
| 19 class ChromeV8ContextSet; | 19 class ChromeV8Context; |
| 20 class Dispatcher; | 20 class Dispatcher; |
| 21 | 21 |
| 22 struct PendingRequest; | 22 struct PendingRequest; |
| 23 | 23 |
| 24 // Responsible for sending requests for named extension API functions to the | 24 // Responsible for sending requests for named extension API functions to the |
| 25 // extension host and routing the responses back to the caller. | 25 // extension host and routing the responses back to the caller. |
| 26 class RequestSender { | 26 class RequestSender { |
| 27 public: | 27 public: |
| 28 explicit RequestSender(Dispatcher* dispatcher, | 28 explicit RequestSender(Dispatcher* dispatcher); |
| 29 ChromeV8ContextSet* context_set); | |
| 30 ~RequestSender(); | 29 ~RequestSender(); |
| 31 | 30 |
| 32 // Makes a call to the API function |name| that is to be handled by the | 31 // 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 | 32 // extension host. The response to this request will be received in |
| 34 // HandleResponse(). | 33 // HandleResponse(). |
| 35 // TODO(koz): Remove |request_id| and generate that internally. | 34 // TODO(koz): Remove |request_id| and generate that internally. |
| 36 void StartRequest(const std::string& name, | 35 // There are multiple of these per render view though, so we'll |
| 36 // need to vend the IDs centrally. |
| 37 void StartRequest(ChromeV8Context* target_context, |
| 38 const std::string& name, |
| 37 int request_id, | 39 int request_id, |
| 38 bool has_callback, | 40 bool has_callback, |
| 39 bool for_io_thread, | 41 bool for_io_thread, |
| 40 base::ListValue* value_args); | 42 base::ListValue* value_args); |
| 41 | 43 |
| 42 // Handles responses from the extension host to calls made by StartRequest(). | 44 // Handles responses from the extension host to calls made by StartRequest(). |
| 43 void HandleResponse(int request_id, | 45 void HandleResponse(int request_id, |
| 44 bool success, | 46 bool success, |
| 45 const base::ListValue& response, | 47 const base::ListValue& response, |
| 46 const std::string& error); | 48 const std::string& error); |
| 47 | 49 |
| 50 // Notifies this that a context is no longer valid. |
| 51 // TODO(kalman): Do this in a generic/safe way. |
| 52 void InvalidateContext(ChromeV8Context* context); |
| 48 | 53 |
| 49 private: | 54 private: |
| 50 typedef std::map<int, linked_ptr<PendingRequest> > PendingRequestMap; | 55 typedef std::map<int, linked_ptr<PendingRequest> > PendingRequestMap; |
| 51 | 56 |
| 52 void InsertRequest(int request_id, PendingRequest* pending_request); | 57 void InsertRequest(int request_id, PendingRequest* pending_request); |
| 53 linked_ptr<PendingRequest> RemoveRequest(int request_id); | 58 linked_ptr<PendingRequest> RemoveRequest(int request_id); |
| 54 | 59 |
| 55 Dispatcher* dispatcher_; | 60 Dispatcher* dispatcher_; |
| 56 PendingRequestMap pending_requests_; | 61 PendingRequestMap pending_requests_; |
| 57 ChromeV8ContextSet* context_set_; | |
| 58 | 62 |
| 59 DISALLOW_COPY_AND_ASSIGN(RequestSender); | 63 DISALLOW_COPY_AND_ASSIGN(RequestSender); |
| 60 }; | 64 }; |
| 61 | 65 |
| 62 } // namespace extensions | 66 } // namespace extensions |
| 63 | 67 |
| 64 #endif // CHROME_RENDERER_EXTENSIONS_REQUEST_SENDER_H_ | 68 #endif // CHROME_RENDERER_EXTENSIONS_REQUEST_SENDER_H_ |
| OLD | NEW |