Add ICU message format support
[chromium-blink-merge.git] / content / browser / renderer_host / pepper / pepper_network_proxy_host.h
blobeddbc89a1bd79c8c143c67237c3346524f512ddd
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.
5 #ifndef CONTENT_BROWSER_RENDERER_HOST_PEPPER_PEPPER_NETWORK_PROXY_HOST_H_
6 #define CONTENT_BROWSER_RENDERER_HOST_PEPPER_PEPPER_NETWORK_PROXY_HOST_H_
8 #include <queue>
9 #include <string>
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"
18 namespace net {
19 class ProxyInfo;
20 class URLRequestContextGetter;
23 namespace ppapi {
24 namespace host {
25 struct ReplyMessageContext;
29 namespace content {
31 class BrowserPpapiHostImpl;
33 // The host for PPB_NetworkProxy. This class lives on the IO thread.
34 class CONTENT_EXPORT PepperNetworkProxyHost : public ppapi::host::ResourceHost {
35 public:
36 PepperNetworkProxyHost(BrowserPpapiHostImpl* host,
37 PP_Instance instance,
38 PP_Resource resource);
40 ~PepperNetworkProxyHost() override;
42 private:
43 // We retrieve the appropriate URLRequestContextGetter and whether this API
44 // is allowed for the instance on the UI thread and pass those to
45 // DidGetUIThreadData, which sets allowed_ and proxy_service_.
46 struct UIThreadData {
47 UIThreadData();
48 ~UIThreadData();
49 bool is_allowed;
50 scoped_refptr<net::URLRequestContextGetter> context_getter;
52 static UIThreadData GetUIThreadDataOnUIThread(int render_process_id,
53 int render_frame_id,
54 bool is_external_plugin);
55 void DidGetUIThreadData(const UIThreadData&);
57 // ResourceHost implementation.
58 int32_t OnResourceMessageReceived(
59 const IPC::Message& msg,
60 ppapi::host::HostMessageContext* context) override;
62 int32_t OnMsgGetProxyForURL(ppapi::host::HostMessageContext* context,
63 const std::string& url);
65 // If we have a valid proxy_service_, send all messages in unsent_requests_.
66 void TryToSendUnsentRequests();
68 void OnResolveProxyCompleted(ppapi::host::ReplyMessageContext context,
69 net::ProxyInfo* proxy_info,
70 int result);
71 void SendFailureReply(int32_t error,
72 ppapi::host::ReplyMessageContext context);
74 // The following two members are invalid until we get some information from
75 // the UI thread. However, these are only ever set or accessed on the IO
76 // thread.
77 net::ProxyService* proxy_service_;
78 bool is_allowed_;
80 // True initially, but set to false once the values for proxy_service_ and
81 // is_allowed_ have been set.
82 bool waiting_for_ui_thread_data_;
84 // We have to get the URLRequestContextGetter from the UI thread before we
85 // can retrieve proxy_service_. If we receive any calls for GetProxyForURL
86 // before proxy_service_ is available, we save them in unsent_requests_.
87 struct UnsentRequest {
88 GURL url;
89 ppapi::host::ReplyMessageContext reply_context;
91 std::queue<UnsentRequest> unsent_requests_;
93 // Requests awaiting a response from ProxyService. We need to store these so
94 // that we can cancel them if we get destroyed.
95 std::queue<net::ProxyService::PacRequest*> pending_requests_;
97 base::WeakPtrFactory<PepperNetworkProxyHost> weak_factory_;
99 DISALLOW_COPY_AND_ASSIGN(PepperNetworkProxyHost);
102 } // namespace content
104 #endif // CONTENT_BROWSER_RENDERER_HOST_PEPPER_PEPPER_NETWORK_PROXY_HOST_H_