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 #ifndef CONTENT_BROWSER_RENDERER_HOST_PEPPER_PEPPER_NETWORK_HOST_HOST_H_ | |
|
yzshen1
2013/06/16 23:49:53
HOST_HOST -> PROXY_HOST, please.
dmichael (off chromium)
2013/06/17 21:48:28
Hah, nice catch, thanks.
| |
| 6 #define CONTENT_BROWSER_RENDERER_HOST_PEPPER_PEPPER_NETWORK_HOST_HOST_H_ | |
| 7 | |
| 8 #include <queue> | |
| 9 #include <string> | |
| 10 | |
| 11 #include "base/compiler_specific.h" | |
| 12 #include "base/memory/weak_ptr.h" | |
| 13 #include "content/common/content_export.h" | |
| 14 #include "net/proxy/proxy_service.h" | |
| 15 #include "ppapi/host/host_message_context.h" | |
| 16 #include "ppapi/host/resource_host.h" | |
| 17 | |
| 18 namespace net { | |
| 19 class ProxyInfo; | |
| 20 class URLRequestContextGetter; | |
| 21 } | |
| 22 | |
| 23 namespace ppapi { | |
| 24 namespace host { | |
| 25 struct ReplyMessageContext; | |
| 26 } | |
| 27 } | |
| 28 | |
| 29 namespace content { | |
| 30 | |
| 31 class BrowserPpapiHost; | |
| 32 | |
| 33 // The host for PPB_NetworkProxy. This class runs exclusively on the IO thread. | |
| 34 class CONTENT_EXPORT PepperNetworkProxyHost : public ppapi::host::ResourceHost { | |
| 35 public: | |
| 36 PepperNetworkProxyHost(BrowserPpapiHost* host, | |
| 37 PP_Instance instance, | |
| 38 PP_Resource resource); | |
| 39 | |
| 40 virtual ~PepperNetworkProxyHost(); | |
| 41 | |
| 42 private: | |
| 43 // We retrieve the appropriate URLRequestContextGetter on the UI thread | |
| 44 // and pass it to this function, which uses it to retrieve proxy_service_. | |
| 45 void DidGetURLRequestContextGetter( | |
| 46 scoped_refptr<net::URLRequestContextGetter> context_getter); | |
| 47 | |
| 48 // ResourceHost implementation. | |
| 49 virtual int32_t OnResourceMessageReceived( | |
| 50 const IPC::Message& msg, | |
| 51 ppapi::host::HostMessageContext* context) OVERRIDE; | |
| 52 | |
| 53 int32_t OnMsgGetProxyForURL(ppapi::host::HostMessageContext* context, | |
| 54 const std::string& url); | |
| 55 | |
| 56 // If we have a valid proxy_service_, send all messages in unsent_requests_. | |
| 57 void TryToSendUnsentRequests(); | |
| 58 | |
| 59 void OnResolveProxyCompleted(ppapi::host::ReplyMessageContext context, | |
| 60 net::ProxyInfo* proxy_info, | |
| 61 int result); | |
| 62 void SendFailureReply(int32_t error, | |
| 63 ppapi::host::ReplyMessageContext context); | |
| 64 | |
| 65 net::ProxyService* proxy_service_; | |
| 66 bool waiting_for_proxy_service_; | |
| 67 | |
| 68 // We have to get the URLRequestContextGetter from the UI thread before we | |
| 69 // can retrieve proxy_service_. If we receive any calls for GetProxyForURL | |
| 70 // before proxy_service_ is available, we save them in unsent_requests_. | |
| 71 struct UnsentRequest { | |
| 72 std::string url; | |
| 73 ppapi::host::ReplyMessageContext reply_context; | |
| 74 }; | |
| 75 std::queue<UnsentRequest> unsent_requests_; | |
| 76 | |
| 77 // Requests awaiting a response from ProxyService. We need to store these so | |
| 78 // that we can cancel them if we get destroyed. | |
| 79 std::queue<net::ProxyService::PacRequest*> pending_requests_; | |
| 80 | |
| 81 base::WeakPtrFactory<PepperNetworkProxyHost> weak_factory_; | |
| 82 | |
| 83 DISALLOW_COPY_AND_ASSIGN(PepperNetworkProxyHost); | |
| 84 }; | |
| 85 | |
| 86 } // namespace content | |
| 87 | |
| 88 #endif // CONTENT_BROWSER_RENDERER_HOST_PEPPER_PEPPER_NETWORK_HOST_HOST_H_ | |
| OLD | NEW |