Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(27)

Side by Side Diff: ppapi/proxy/ppb_url_request_info_proxy.cc

Issue 7629017: Add a unified resource tracker shared between the proxy and the impl. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address review comments Created 9 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ppapi/proxy/ppb_url_request_info_proxy.h" 5 #include "ppapi/proxy/ppb_url_request_info_proxy.h"
6 6
7 #include "ppapi/c/ppb_url_request_info.h" 7 #include "ppapi/c/ppb_url_request_info.h"
8 #include "ppapi/proxy/enter_proxy.h" 8 #include "ppapi/proxy/enter_proxy.h"
9 #include "ppapi/proxy/plugin_dispatcher.h" 9 #include "ppapi/proxy/plugin_dispatcher.h"
10 #include "ppapi/proxy/plugin_resource.h"
11 #include "ppapi/proxy/ppapi_messages.h" 10 #include "ppapi/proxy/ppapi_messages.h"
12 #include "ppapi/thunk/ppb_url_request_info_api.h" 11 #include "ppapi/thunk/ppb_url_request_info_api.h"
13 #include "ppapi/thunk/resource_creation_api.h" 12 #include "ppapi/thunk/resource_creation_api.h"
14 #include "ppapi/thunk/thunk.h" 13 #include "ppapi/thunk/thunk.h"
15 14
16 using ppapi::HostResource; 15 using ppapi::HostResource;
16 using ppapi::Resource;
17 using ppapi::thunk::EnterFunctionNoLock; 17 using ppapi::thunk::EnterFunctionNoLock;
18 using ppapi::thunk::PPB_URLRequestInfo_API; 18 using ppapi::thunk::PPB_URLRequestInfo_API;
19 using ppapi::thunk::ResourceCreationAPI; 19 using ppapi::thunk::ResourceCreationAPI;
20 20
21 namespace pp { 21 namespace pp {
22 namespace proxy { 22 namespace proxy {
23 23
24 namespace { 24 namespace {
25 25
26 InterfaceProxy* CreateURLRequestInfoProxy(Dispatcher* dispatcher, 26 InterfaceProxy* CreateURLRequestInfoProxy(Dispatcher* dispatcher,
27 const void* target_interface) { 27 const void* target_interface) {
28 return new PPB_URLRequestInfo_Proxy(dispatcher, target_interface); 28 return new PPB_URLRequestInfo_Proxy(dispatcher, target_interface);
29 } 29 }
30 30
31 } // namespace 31 } // namespace
32 32
33 class URLRequestInfo : public PluginResource, 33 class URLRequestInfo : public Resource,
34 public PPB_URLRequestInfo_API { 34 public PPB_URLRequestInfo_API {
35 public: 35 public:
36 URLRequestInfo(const HostResource& resource); 36 URLRequestInfo(const HostResource& resource);
37 virtual ~URLRequestInfo(); 37 virtual ~URLRequestInfo();
38 38
39 virtual PPB_URLRequestInfo_API* AsPPB_URLRequestInfo_API() OVERRIDE; 39 virtual PPB_URLRequestInfo_API* AsPPB_URLRequestInfo_API() OVERRIDE;
40 40
41 // PPB_URLRequestInfo_API implementation. 41 // PPB_URLRequestInfo_API implementation.
42 virtual PP_Bool SetProperty(PP_URLRequestProperty property, 42 virtual PP_Bool SetProperty(PP_URLRequestProperty property,
43 PP_Var var) OVERRIDE; 43 PP_Var var) OVERRIDE;
44 virtual PP_Bool AppendDataToBody(const void* data, uint32_t len) OVERRIDE; 44 virtual PP_Bool AppendDataToBody(const void* data, uint32_t len) OVERRIDE;
45 virtual PP_Bool AppendFileToBody( 45 virtual PP_Bool AppendFileToBody(
46 PP_Resource file_ref, 46 PP_Resource file_ref,
47 int64_t start_offset, 47 int64_t start_offset,
48 int64_t number_of_bytes, 48 int64_t number_of_bytes,
49 PP_Time expected_last_modified_time) OVERRIDE; 49 PP_Time expected_last_modified_time) OVERRIDE;
50 50
51 private: 51 private:
52 PluginDispatcher* GetDispatcher() const {
53 return PluginDispatcher::GetForResource(this);
54 }
55
52 DISALLOW_COPY_AND_ASSIGN(URLRequestInfo); 56 DISALLOW_COPY_AND_ASSIGN(URLRequestInfo);
53 }; 57 };
54 58
55 URLRequestInfo::URLRequestInfo(const HostResource& resource) 59 URLRequestInfo::URLRequestInfo(const HostResource& resource)
56 : PluginResource(resource) { 60 : Resource(resource) {
57 } 61 }
58 62
59 URLRequestInfo::~URLRequestInfo() { 63 URLRequestInfo::~URLRequestInfo() {
60 } 64 }
61 65
62 PPB_URLRequestInfo_API* URLRequestInfo::AsPPB_URLRequestInfo_API() { 66 PPB_URLRequestInfo_API* URLRequestInfo::AsPPB_URLRequestInfo_API() {
63 return this; 67 return this;
64 } 68 }
65 69
66 PP_Bool URLRequestInfo::SetProperty(PP_URLRequestProperty property, 70 PP_Bool URLRequestInfo::SetProperty(PP_URLRequestProperty property,
(...skipping 15 matching lines...) Expand all
82 86
83 // TODO(brettw) do some validation. We should be able to tell on the plugin 87 // TODO(brettw) do some validation. We should be able to tell on the plugin
84 // side whether the request will succeed or fail in the renderer. 88 // side whether the request will succeed or fail in the renderer.
85 return PP_TRUE; 89 return PP_TRUE;
86 } 90 }
87 91
88 PP_Bool URLRequestInfo::AppendFileToBody(PP_Resource file_ref, 92 PP_Bool URLRequestInfo::AppendFileToBody(PP_Resource file_ref,
89 int64_t start_offset, 93 int64_t start_offset,
90 int64_t number_of_bytes, 94 int64_t number_of_bytes,
91 PP_Time expected_last_modified_time) { 95 PP_Time expected_last_modified_time) {
92 PluginResource* file_ref_object = 96 Resource* file_ref_object =
93 PluginResourceTracker::GetInstance()->GetResourceObject(file_ref); 97 PluginResourceTracker::GetInstance()->GetResource(file_ref);
94 if (!file_ref_object) 98 if (!file_ref_object)
95 return PP_FALSE; 99 return PP_FALSE;
96 100
97 GetDispatcher()->Send(new PpapiHostMsg_PPBURLRequestInfo_AppendFileToBody( 101 GetDispatcher()->Send(new PpapiHostMsg_PPBURLRequestInfo_AppendFileToBody(
98 INTERFACE_ID_PPB_URL_REQUEST_INFO, host_resource(), 102 INTERFACE_ID_PPB_URL_REQUEST_INFO, host_resource(),
99 file_ref_object->host_resource(), 103 file_ref_object->host_resource(),
100 start_offset, number_of_bytes, expected_last_modified_time)); 104 start_offset, number_of_bytes, expected_last_modified_time));
101 105
102 // TODO(brettw) do some validation. We should be able to tell on the plugin 106 // TODO(brettw) do some validation. We should be able to tell on the plugin
103 // side whether the request will succeed or fail in the renderer. 107 // side whether the request will succeed or fail in the renderer.
(...skipping 28 matching lines...) Expand all
132 PP_Instance instance) { 136 PP_Instance instance) {
133 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance); 137 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance);
134 if (!dispatcher) 138 if (!dispatcher)
135 return 0; 139 return 0;
136 140
137 HostResource result; 141 HostResource result;
138 dispatcher->Send(new PpapiHostMsg_PPBURLRequestInfo_Create( 142 dispatcher->Send(new PpapiHostMsg_PPBURLRequestInfo_Create(
139 INTERFACE_ID_PPB_URL_REQUEST_INFO, instance, &result)); 143 INTERFACE_ID_PPB_URL_REQUEST_INFO, instance, &result));
140 if (result.is_null()) 144 if (result.is_null())
141 return 0; 145 return 0;
142 146 return (new URLRequestInfo(result))->GetReference();
143 return PluginResourceTracker::GetInstance()->AddResource(
144 new URLRequestInfo(result));
145 } 147 }
146 148
147 bool PPB_URLRequestInfo_Proxy::OnMessageReceived(const IPC::Message& msg) { 149 bool PPB_URLRequestInfo_Proxy::OnMessageReceived(const IPC::Message& msg) {
148 bool handled = true; 150 bool handled = true;
149 IPC_BEGIN_MESSAGE_MAP(PPB_URLRequestInfo_Proxy, msg) 151 IPC_BEGIN_MESSAGE_MAP(PPB_URLRequestInfo_Proxy, msg)
150 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBURLRequestInfo_Create, OnMsgCreate) 152 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBURLRequestInfo_Create, OnMsgCreate)
151 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBURLRequestInfo_SetProperty, 153 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBURLRequestInfo_SetProperty,
152 OnMsgSetProperty) 154 OnMsgSetProperty)
153 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBURLRequestInfo_AppendDataToBody, 155 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBURLRequestInfo_AppendDataToBody,
154 OnMsgAppendDataToBody) 156 OnMsgAppendDataToBody)
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 EnterHostFromHostResource<PPB_URLRequestInfo_API> enter(request); 200 EnterHostFromHostResource<PPB_URLRequestInfo_API> enter(request);
199 if (enter.succeeded()) { 201 if (enter.succeeded()) {
200 enter.object()->AppendFileToBody( 202 enter.object()->AppendFileToBody(
201 file_ref.host_resource(), start_offset, number_of_bytes, 203 file_ref.host_resource(), start_offset, number_of_bytes,
202 expected_last_modified_time); 204 expected_last_modified_time);
203 } 205 }
204 } 206 }
205 207
206 } // namespace proxy 208 } // namespace proxy
207 } // namespace pp 209 } // namespace pp
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698