Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 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 #include "ppapi/proxy/network_proxy_resource.h" | |
| 6 | |
| 7 #include "base/bind.h" | |
| 8 #include "ppapi/proxy/dispatch_reply_message.h" | |
| 9 #include "ppapi/proxy/ppapi_messages.h" | |
| 10 #include "ppapi/shared_impl/var.h" | |
| 11 | |
| 12 namespace ppapi { | |
| 13 namespace proxy { | |
| 14 | |
| 15 NetworkProxyResource::NetworkProxyResource(Connection connection, | |
| 16 PP_Instance instance) | |
| 17 : PluginResource(connection, instance) { | |
| 18 SendCreate(BROWSER, PpapiHostMsg_NetworkProxy_Create()); | |
| 19 } | |
| 20 | |
| 21 NetworkProxyResource::~NetworkProxyResource() { | |
| 22 } | |
| 23 | |
| 24 thunk::PPB_NetworkProxy_API* NetworkProxyResource::AsPPB_NetworkProxy_API() { | |
| 25 return this; | |
| 26 } | |
| 27 | |
| 28 int32_t NetworkProxyResource::GetProxyForURL( | |
| 29 PP_Instance /* instance */, | |
| 30 PP_Var url, | |
| 31 PP_Var* proxy_string, | |
| 32 scoped_refptr<TrackedCallback> callback) { | |
| 33 StringVar* string_url = StringVar::FromPPVar(url); | |
| 34 if (!string_url) | |
| 35 return PP_ERROR_BADARGUMENT; | |
| 36 Call<PpapiPluginMsg_NetworkProxy_GetProxyForURLReply>( | |
| 37 BROWSER, | |
| 38 PpapiHostMsg_NetworkProxy_GetProxyForURL(string_url->value()), | |
| 39 base::Bind(&NetworkProxyResource::OnPluginMsgGetProxyForURLReply, | |
| 40 this, | |
|
yzshen1
2013/06/16 23:49:53
nit, optional: It is safe and more clear to use ba
dmichael (off chromium)
2013/06/17 21:48:28
Done, thanks for pointing that out.
| |
| 41 base::Unretained(proxy_string), | |
| 42 callback)); | |
| 43 return PP_OK_COMPLETIONPENDING; | |
| 44 } | |
| 45 | |
| 46 void NetworkProxyResource::OnPluginMsgGetProxyForURLReply( | |
| 47 PP_Var* proxy_string_out_param, | |
| 48 scoped_refptr<TrackedCallback> callback, | |
| 49 const ResourceMessageReplyParams& params, | |
| 50 const std::string& proxy_string) { | |
| 51 // If the last plugin ref for this resource was released, the callback will | |
| 52 // have been cancelled. We can't invoke it, and we can't write to the var. | |
| 53 if (!TrackedCallback::IsPending(callback)) | |
| 54 return; | |
|
dmichael (off chromium)
2013/06/17 21:48:28
So I guess that means I don't need this check. Sin
| |
| 55 | |
| 56 if (params.result() == PP_OK) { | |
| 57 *proxy_string_out_param = (new StringVar(proxy_string))->GetPPVar(); | |
| 58 } | |
| 59 callback->Run(params.result()); | |
| 60 } | |
| 61 | |
| 62 } // namespace proxy | |
| 63 } // namespace ppapi | |
| OLD | NEW |