Chromium Code Reviews| 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 // Calls a named extension API function in the extension host and routes the | |
| 25 // response back to the caller. | |
|
not at google - send to devlin
2012/03/30 03:14:31
This reads more like the documentation that would
koz (OOO until 15th September)
2012/04/03 00:15:17
Done.
| |
| 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, | |
|
not at google - send to devlin
2012/03/30 03:14:31
Looking at the implementation of this method it se
koz (OOO until 15th September)
2012/04/03 00:15:17
Perhaps the caller doesn't care? Maybe the silent
| |
| 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, | |
|
not at google - send to devlin
2012/03/30 03:14:31
"OnResponse" feels like a better name, it implies
koz (OOO until 15th September)
2012/04/03 00:15:17
Yeah, it doesn't seem worth the change. HandleResp
| |
| 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 PendingRequest* GetPendingRequest(int request_id); | |
| 54 void RemoveRequest(int request_id); | |
| 55 | |
| 56 ExtensionDispatcher* extension_dispatcher_; | |
| 57 PendingRequestMap pending_requests_; | |
| 58 ChromeV8ContextSet* context_set_; | |
| 59 | |
| 60 DISALLOW_COPY_AND_ASSIGN(ExtensionRequestSender); | |
| 61 }; | |
| 62 | |
| 63 #endif // CHROME_RENDERER_EXTENSIONS_EXTENSION_REQUEST_SENDER_H_ | |
| OLD | NEW |