| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 EXTENSIONS_RENDERER_REQUEST_SENDER_H_ | 5 #ifndef EXTENSIONS_RENDERER_REQUEST_SENDER_H_ |
| 6 #define EXTENSIONS_RENDERER_REQUEST_SENDER_H_ | 6 #define EXTENSIONS_RENDERER_REQUEST_SENDER_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| (...skipping 29 matching lines...) Expand all Loading... |
| 40 virtual ~Source() {} | 40 virtual ~Source() {} |
| 41 | 41 |
| 42 virtual ScriptContext* GetContext() = 0; | 42 virtual ScriptContext* GetContext() = 0; |
| 43 virtual void OnResponseReceived(const std::string& name, | 43 virtual void OnResponseReceived(const std::string& name, |
| 44 int request_id, | 44 int request_id, |
| 45 bool success, | 45 bool success, |
| 46 const base::ListValue& response, | 46 const base::ListValue& response, |
| 47 const std::string& error) = 0; | 47 const std::string& error) = 0; |
| 48 }; | 48 }; |
| 49 | 49 |
| 50 // Helper class to (re)set the |source_tab_id_| below. | |
| 51 class ScopedTabID { | |
| 52 public: | |
| 53 ScopedTabID(RequestSender* request_sender, int tab_id); | |
| 54 ~ScopedTabID(); | |
| 55 | |
| 56 private: | |
| 57 RequestSender* const request_sender_; | |
| 58 const int tab_id_; | |
| 59 const int previous_tab_id_; | |
| 60 | |
| 61 DISALLOW_COPY_AND_ASSIGN(ScopedTabID); | |
| 62 }; | |
| 63 | |
| 64 RequestSender(); | 50 RequestSender(); |
| 65 virtual ~RequestSender(); | 51 virtual ~RequestSender(); |
| 66 | 52 |
| 67 // In order to avoid collision, all |request_id|s passed into StartRequest() | 53 // In order to avoid collision, all |request_id|s passed into StartRequest() |
| 68 // should be generated by this method. | 54 // should be generated by this method. |
| 69 int GetNextRequestId() const; | 55 int GetNextRequestId() const; |
| 70 | 56 |
| 71 // Makes a call to the API function |name| that is to be handled by the | 57 // Makes a call to the API function |name| that is to be handled by the |
| 72 // extension host. The response to this request will be received in | 58 // extension host. The response to this request will be received in |
| 73 // HandleResponse(). | 59 // HandleResponse(). |
| (...skipping 27 matching lines...) Expand all Loading... |
| 101 private: | 87 private: |
| 102 friend class ScopedTabID; | 88 friend class ScopedTabID; |
| 103 using PendingRequestMap = std::map<int, std::unique_ptr<PendingRequest>>; | 89 using PendingRequestMap = std::map<int, std::unique_ptr<PendingRequest>>; |
| 104 | 90 |
| 105 void InsertRequest(int request_id, | 91 void InsertRequest(int request_id, |
| 106 std::unique_ptr<PendingRequest> pending_request); | 92 std::unique_ptr<PendingRequest> pending_request); |
| 107 std::unique_ptr<PendingRequest> RemoveRequest(int request_id); | 93 std::unique_ptr<PendingRequest> RemoveRequest(int request_id); |
| 108 | 94 |
| 109 PendingRequestMap pending_requests_; | 95 PendingRequestMap pending_requests_; |
| 110 | 96 |
| 111 int source_tab_id_; // Id of the tab sending the request, or -1 if no tab. | |
| 112 | |
| 113 DISALLOW_COPY_AND_ASSIGN(RequestSender); | 97 DISALLOW_COPY_AND_ASSIGN(RequestSender); |
| 114 }; | 98 }; |
| 115 | 99 |
| 116 } // namespace extensions | 100 } // namespace extensions |
| 117 | 101 |
| 118 #endif // EXTENSIONS_RENDERER_REQUEST_SENDER_H_ | 102 #endif // EXTENSIONS_RENDERER_REQUEST_SENDER_H_ |
| OLD | NEW |