Chromium Code Reviews| 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 |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 35 virtual ~Source() {} | 35 virtual ~Source() {} |
| 36 | 36 |
| 37 virtual ChromeV8Context* GetContext() = 0; | 37 virtual ChromeV8Context* GetContext() = 0; |
| 38 virtual void OnResponseReceived(const std::string& name, | 38 virtual void OnResponseReceived(const std::string& name, |
| 39 int request_id, | 39 int request_id, |
| 40 bool success, | 40 bool success, |
| 41 const base::ListValue& response, | 41 const base::ListValue& response, |
| 42 const std::string& error) = 0; | 42 const std::string& error) = 0; |
| 43 }; | 43 }; |
| 44 | 44 |
| 45 // Helper class to (re)set the |source_tab_id_| below. | |
| 46 class ScopedTabID { | |
| 47 public: | |
| 48 ScopedTabID(RequestSender* request_sender, int tab_id); | |
| 49 ~ScopedTabID(); | |
| 50 | |
| 51 private: | |
| 52 RequestSender* const request_sender_; | |
| 53 const int tab_id_; | |
| 54 const int previous_tab_id_; | |
| 55 | |
| 56 DISALLOW_COPY_AND_ASSIGN(ScopedTabID); | |
| 57 }; | |
| 58 | |
| 45 explicit RequestSender(Dispatcher* dispatcher); | 59 explicit RequestSender(Dispatcher* dispatcher); |
| 46 ~RequestSender(); | 60 ~RequestSender(); |
| 47 | 61 |
| 48 // In order to avoid collision, all |request_id|s passed into StartRequest() | 62 // In order to avoid collision, all |request_id|s passed into StartRequest() |
| 49 // should be generated by this method. | 63 // should be generated by this method. |
| 50 int GetNextRequestId() const; | 64 int GetNextRequestId() const; |
| 51 | 65 |
| 52 // Makes a call to the API function |name| that is to be handled by the | 66 // Makes a call to the API function |name| that is to be handled by the |
| 53 // extension host. The response to this request will be received in | 67 // extension host. The response to this request will be received in |
| 54 // HandleResponse(). | 68 // HandleResponse(). |
| 55 // TODO(koz): Remove |request_id| and generate that internally. | 69 // TODO(koz): Remove |request_id| and generate that internally. |
| 56 // There are multiple of these per render view though, so we'll | 70 // There are multiple of these per render view though, so we'll |
| 57 // need to vend the IDs centrally. | 71 // need to vend the IDs centrally. |
| 58 void StartRequest(Source* source, | 72 void StartRequest(Source* source, |
| 59 const std::string& name, | 73 const std::string& name, |
| 60 int request_id, | 74 int request_id, |
| 61 bool has_callback, | 75 bool has_callback, |
| 62 bool for_io_thread, | 76 bool for_io_thread, |
| 77 int source_tab_id, | |
| 63 base::ListValue* value_args); | 78 base::ListValue* value_args); |
| 64 | 79 |
| 65 // Handles responses from the extension host to calls made by StartRequest(). | 80 // Handles responses from the extension host to calls made by StartRequest(). |
| 66 void HandleResponse(int request_id, | 81 void HandleResponse(int request_id, |
| 67 bool success, | 82 bool success, |
| 68 const base::ListValue& response, | 83 const base::ListValue& response, |
| 69 const std::string& error); | 84 const std::string& error); |
| 70 | 85 |
| 71 // Notifies this that a request source is no longer valid. | 86 // Notifies this that a request source is no longer valid. |
| 72 // TODO(kalman): Do this in a generic/safe way. | 87 // TODO(kalman): Do this in a generic/safe way. |
| 73 void InvalidateSource(Source* source); | 88 void InvalidateSource(Source* source); |
| 74 | 89 |
| 90 int sender_tab_id() const { | |
|
not at google - send to devlin
2014/01/28 18:45:45
(see comment in request_sender.cc; does this need
| |
| 91 return sender_tab_id_; | |
| 92 } | |
| 93 | |
| 75 private: | 94 private: |
| 95 friend class ScopedTabID; | |
| 76 typedef std::map<int, linked_ptr<PendingRequest> > PendingRequestMap; | 96 typedef std::map<int, linked_ptr<PendingRequest> > PendingRequestMap; |
| 77 | 97 |
| 78 void InsertRequest(int request_id, PendingRequest* pending_request); | 98 void InsertRequest(int request_id, PendingRequest* pending_request); |
| 79 linked_ptr<PendingRequest> RemoveRequest(int request_id); | 99 linked_ptr<PendingRequest> RemoveRequest(int request_id); |
| 80 | 100 |
| 81 Dispatcher* dispatcher_; | 101 Dispatcher* dispatcher_; |
| 82 PendingRequestMap pending_requests_; | 102 PendingRequestMap pending_requests_; |
| 83 | 103 |
| 104 int sender_tab_id_; // Id of the tab sending the request, or -1 if no tab. | |
| 105 | |
| 84 DISALLOW_COPY_AND_ASSIGN(RequestSender); | 106 DISALLOW_COPY_AND_ASSIGN(RequestSender); |
| 85 }; | 107 }; |
| 86 | 108 |
| 87 } // namespace extensions | 109 } // namespace extensions |
| 88 | 110 |
| 89 #endif // CHROME_RENDERER_EXTENSIONS_REQUEST_SENDER_H_ | 111 #endif // CHROME_RENDERER_EXTENSIONS_REQUEST_SENDER_H_ |
| OLD | NEW |