Enable ManagePasswordsBubbleViewTest.TwoTabsWtihBubble on linux x32.
[chromium-blink-merge.git] / ppapi / proxy / url_loader_resource.h
blob49869326a203eec3dcf5f6353f68a3c5a966eb76
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 PPAPI_PROXY_URL_LOADER_RESOURCE_H_
6 #define PPAPI_PROXY_URL_LOADER_RESOURCE_H_
8 #include <deque>
10 #include "base/basictypes.h"
11 #include "base/compiler_specific.h"
12 #include "ppapi/c/trusted/ppb_url_loader_trusted.h"
13 #include "ppapi/proxy/plugin_resource.h"
14 #include "ppapi/proxy/ppapi_proxy_export.h"
15 #include "ppapi/shared_impl/url_request_info_data.h"
16 #include "ppapi/thunk/ppb_url_loader_api.h"
18 namespace ppapi {
19 namespace proxy {
21 class URLResponseInfoResource;
23 class PPAPI_PROXY_EXPORT URLLoaderResource
24 : public PluginResource,
25 public NON_EXPORTED_BASE(thunk::PPB_URLLoader_API) {
26 public:
27 // Constructor for plugin-initiated loads.
28 URLLoaderResource(Connection connection,
29 PP_Instance instance);
31 // Constructor for renderer-initiated (document) loads. The loader ID is the
32 // pending host ID for the already-created host in the renderer, and the
33 // response data is the response for the already-opened connection.
34 URLLoaderResource(Connection connection,
35 PP_Instance instance,
36 int pending_main_document_loader_id,
37 const URLResponseInfoData& data);
39 virtual ~URLLoaderResource();
41 // Resource override.
42 thunk::PPB_URLLoader_API* AsPPB_URLLoader_API() override;
44 // PPB_URLLoader_API implementation.
45 virtual int32_t Open(PP_Resource request_id,
46 scoped_refptr<TrackedCallback> callback) override;
47 virtual int32_t Open(const URLRequestInfoData& data,
48 int requestor_pid,
49 scoped_refptr<TrackedCallback> callback) override;
50 virtual int32_t FollowRedirect(
51 scoped_refptr<TrackedCallback> callback) override;
52 virtual PP_Bool GetUploadProgress(int64_t* bytes_sent,
53 int64_t* total_bytes_to_be_sent) override;
54 virtual PP_Bool GetDownloadProgress(
55 int64_t* bytes_received,
56 int64_t* total_bytes_to_be_received) override;
57 virtual PP_Resource GetResponseInfo() override;
58 virtual int32_t ReadResponseBody(
59 void* buffer,
60 int32_t bytes_to_read,
61 scoped_refptr<TrackedCallback> callback) override;
62 virtual int32_t FinishStreamingToFile(
63 scoped_refptr<TrackedCallback> callback) override;
64 virtual void Close() override;
65 virtual void GrantUniversalAccess() override;
66 virtual void RegisterStatusCallback(
67 PP_URLLoaderTrusted_StatusCallback callback) override;
69 // PluginResource implementation.
70 virtual void OnReplyReceived(const ResourceMessageReplyParams& params,
71 const IPC::Message& msg) override;
73 private:
74 enum Mode {
75 // The plugin has not called Open() yet.
76 MODE_WAITING_TO_OPEN,
78 // The plugin is waiting for the Open() or FollowRedirect callback.
79 MODE_OPENING,
81 // We've started to receive data and may receive more.
82 MODE_STREAMING_DATA,
84 // All data has been streamed or there was an error.
85 MODE_LOAD_COMPLETE
88 // IPC message handlers.
89 void OnPluginMsgReceivedResponse(const ResourceMessageReplyParams& params,
90 const URLResponseInfoData& data);
91 void OnPluginMsgSendData(const ResourceMessageReplyParams& params,
92 const IPC::Message& message);
93 void OnPluginMsgFinishedLoading(const ResourceMessageReplyParams& params,
94 int32_t result);
95 void OnPluginMsgUpdateProgress(const ResourceMessageReplyParams& params,
96 int64_t bytes_sent,
97 int64_t total_bytes_to_be_sent,
98 int64_t bytes_received,
99 int64_t total_bytes_to_be_received);
101 // Sends the defers loading message to the renderer to block or unblock the
102 // load.
103 void SetDefersLoading(bool defers_loading);
105 int32_t ValidateCallback(scoped_refptr<TrackedCallback> callback);
107 // Sets up |callback| as the pending callback. This should only be called once
108 // it is certain that |PP_OK_COMPLETIONPENDING| will be returned.
109 void RegisterCallback(scoped_refptr<TrackedCallback> callback);
111 void RunCallback(int32_t result);
113 // Saves the given response info to response_info_, handling file refs if
114 // necessary. This does not issue any callbacks.
115 void SaveResponseInfo(const URLResponseInfoData& data);
117 size_t FillUserBuffer();
119 Mode mode_;
120 URLRequestInfoData request_data_;
122 scoped_refptr<TrackedCallback> pending_callback_;
124 PP_URLLoaderTrusted_StatusCallback status_callback_;
126 std::deque<char> buffer_;
127 int64_t bytes_sent_;
128 int64_t total_bytes_to_be_sent_;
129 int64_t bytes_received_;
130 int64_t total_bytes_to_be_received_;
131 char* user_buffer_;
132 size_t user_buffer_size_;
133 int32_t done_status_;
134 bool is_streaming_to_file_;
135 bool is_asynchronous_load_suspended_;
137 // The response info if we've received it.
138 scoped_refptr<URLResponseInfoResource> response_info_;
140 DISALLOW_COPY_AND_ASSIGN(URLLoaderResource);
143 } // namespace proxy
144 } // namespace ppapi
146 #endif // PPAPI_PROXY_URL_LOADER_RESOURCE_H_