Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2013 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_PEPPER_REQUEST_PROXY_H_ | |
| 6 #define CHROME_RENDERER_EXTENSIONS_PEPPER_REQUEST_PROXY_H_ | |
| 7 | |
| 8 #include <map> | |
| 9 #include <string> | |
| 10 | |
| 11 namespace base { | |
| 12 class ListValue; | |
| 13 } | |
| 14 | |
| 15 namespace extensions { | |
| 16 | |
| 17 class ChromeV8Context; | |
| 18 | |
| 19 // A proxy that forwards pepper apps API calls through the Javascript API | |
| 20 // bindings. | |
| 21 class PepperRequestProxy { | |
| 22 public: | |
| 23 class Source { | |
| 24 public: | |
| 25 virtual ~Source() {} | |
| 26 | |
| 27 // Called with the result of an API call. If |success| is true, |response| | |
| 28 // will contain the response value. Otherwise, |error| will contain the | |
| 29 // error message. | |
| 30 virtual void OnResponseReceived(int request_id, | |
| 31 bool success, | |
| 32 const base::ListValue& response, | |
| 33 const std::string& error) = 0; | |
| 34 }; | |
| 35 | |
| 36 explicit PepperRequestProxy(ChromeV8Context* context); | |
| 37 ~PepperRequestProxy(); | |
| 38 | |
| 39 // Starts an API request. Returns whether the call was successful. If the call | |
| 40 // was successful, |request_id| will contain the request ID that will be | |
| 41 // passed to the OnResponseReceived method of |source| when the response is | |
| 42 // received. Otherwise, |error| will contain the error message. | |
| 43 // OnResponseReceived will only be called if |has_callback| is true. | |
|
yzshen1
2013/11/26 19:33:11
Will it be called if |has_callback| is true but th
Sam McNally
2013/11/27 23:40:26
Done.
| |
| 44 bool StartRequest(Source* source, | |
|
yzshen1
2013/11/26 19:33:11
Is it better to use a base::Callback instead of |s
Sam McNally
2013/11/27 23:40:26
Done.
| |
| 45 const std::string& request_name, | |
| 46 bool has_callback, | |
| 47 base::ListValue& args, | |
| 48 int* request_id, | |
| 49 std::string* error); | |
| 50 | |
| 51 void OnResponse(int request_id, | |
|
yzshen1
2013/11/26 19:33:11
nit: OnResponseReceived might sound better.
Sam McNally
2013/11/27 23:40:26
Done.
| |
| 52 bool success, | |
| 53 const base::ListValue& args, | |
| 54 const std::string& error); | |
| 55 | |
| 56 // Invalidates all API calls in-flight for a source. This should be called | |
| 57 // when a Source is destroyed. | |
| 58 void InvalidateSource(Source* source); | |
| 59 | |
| 60 private: | |
| 61 typedef std::map<int, Source*> PendingRequestMap; | |
| 62 ChromeV8Context* context_; | |
|
yzshen1
2013/11/26 19:33:11
Please comment about the ownership/lifespan of con
Sam McNally
2013/11/27 23:40:26
Done.
| |
| 63 PendingRequestMap pending_request_map_; | |
| 64 int next_request_id_; | |
| 65 }; | |
| 66 | |
| 67 } // namespace extensions | |
| 68 | |
| 69 #endif // CHROME_RENDERER_EXTENSIONS_PEPPER_REQUEST_PROXY_H_ | |
| OLD | NEW |