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

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

Issue 21966004: Pepper: Move FileRef to the "new" resource proxy. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: CreateInfo/DetailedInfo rename Created 7 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) 2013 The Chromium Authors. All rights reserved. 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 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/url_loader_resource.h" 5 #include "ppapi/proxy/url_loader_resource.h"
6 6
7 #include "base/debug/stack_trace.h"
yzshen1 2013/08/08 23:16:21 It seems we don't need it?
teravest 2013/08/09 02:00:08 Done.
7 #include "base/logging.h" 8 #include "base/logging.h"
8 #include "ppapi/c/pp_completion_callback.h" 9 #include "ppapi/c/pp_completion_callback.h"
9 #include "ppapi/c/pp_errors.h" 10 #include "ppapi/c/pp_errors.h"
10 #include "ppapi/c/ppb_url_loader.h" 11 #include "ppapi/c/ppb_url_loader.h"
11 #include "ppapi/proxy/dispatch_reply_message.h" 12 #include "ppapi/proxy/dispatch_reply_message.h"
13 #include "ppapi/proxy/file_ref_resource.h"
12 #include "ppapi/proxy/ppapi_messages.h" 14 #include "ppapi/proxy/ppapi_messages.h"
13 #include "ppapi/proxy/ppb_file_ref_proxy.h"
14 #include "ppapi/proxy/url_request_info_resource.h" 15 #include "ppapi/proxy/url_request_info_resource.h"
15 #include "ppapi/proxy/url_response_info_resource.h" 16 #include "ppapi/proxy/url_response_info_resource.h"
16 #include "ppapi/shared_impl/ppapi_globals.h" 17 #include "ppapi/shared_impl/ppapi_globals.h"
17 #include "ppapi/shared_impl/url_response_info_data.h" 18 #include "ppapi/shared_impl/url_response_info_data.h"
18 #include "ppapi/thunk/enter.h" 19 #include "ppapi/thunk/enter.h"
19 #include "ppapi/thunk/resource_creation_api.h" 20 #include "ppapi/thunk/resource_creation_api.h"
20 21
21 using ppapi::thunk::EnterResourceNoLock; 22 using ppapi::thunk::EnterResourceNoLock;
22 using ppapi::thunk::PPB_URLLoader_API; 23 using ppapi::thunk::PPB_URLLoader_API;
23 using ppapi::thunk::PPB_URLRequestInfo_API; 24 using ppapi::thunk::PPB_URLRequestInfo_API;
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 return 0; 152 return 0;
152 } 153 }
153 154
154 int32_t URLLoaderResource::ReadResponseBody( 155 int32_t URLLoaderResource::ReadResponseBody(
155 void* buffer, 156 void* buffer,
156 int32_t bytes_to_read, 157 int32_t bytes_to_read,
157 scoped_refptr<TrackedCallback> callback) { 158 scoped_refptr<TrackedCallback> callback) {
158 int32_t rv = ValidateCallback(callback); 159 int32_t rv = ValidateCallback(callback);
159 if (rv != PP_OK) 160 if (rv != PP_OK)
160 return rv; 161 return rv;
161 if (!response_info_.get() || 162 if (!response_info_.get())
162 !response_info_->data().body_as_file_ref.resource.is_null())
163 return PP_ERROR_FAILED; 163 return PP_ERROR_FAILED;
164
165 // Fail if we have a valid file ref.
166 // ReadResponseBody() is for reading to a user-provided buffer.
167 if (response_info_->data().body_as_file_ref.IsValid())
168 return PP_ERROR_FAILED;
169
164 if (bytes_to_read <= 0 || !buffer) 170 if (bytes_to_read <= 0 || !buffer)
165 return PP_ERROR_BADARGUMENT; 171 return PP_ERROR_BADARGUMENT;
166 172
167 user_buffer_ = static_cast<char*>(buffer); 173 user_buffer_ = static_cast<char*>(buffer);
168 user_buffer_size_ = bytes_to_read; 174 user_buffer_size_ = bytes_to_read;
169 175
170 if (!buffer_.empty()) 176 if (!buffer_.empty())
171 return FillUserBuffer(); 177 return FillUserBuffer();
172 178
173 // We may have already reached EOF. 179 // We may have already reached EOF.
174 if (done_status_ != PP_OK_COMPLETIONPENDING) { 180 if (done_status_ != PP_OK_COMPLETIONPENDING) {
175 user_buffer_ = NULL; 181 user_buffer_ = NULL;
176 user_buffer_size_ = 0; 182 user_buffer_size_ = 0;
177 return done_status_; 183 return done_status_;
178 } 184 }
179 185
180 RegisterCallback(callback); 186 RegisterCallback(callback);
181 return PP_OK_COMPLETIONPENDING; 187 return PP_OK_COMPLETIONPENDING;
182 } 188 }
183 189
184 int32_t URLLoaderResource::FinishStreamingToFile( 190 int32_t URLLoaderResource::FinishStreamingToFile(
185 scoped_refptr<TrackedCallback> callback) { 191 scoped_refptr<TrackedCallback> callback) {
186 int32_t rv = ValidateCallback(callback); 192 int32_t rv = ValidateCallback(callback);
187 if (rv != PP_OK) 193 if (rv != PP_OK)
188 return rv; 194 return rv;
189 if (!response_info_.get() || 195 if (!response_info_.get())
190 response_info_->data().body_as_file_ref.resource.is_null()) 196 return PP_ERROR_FAILED;
197
198 // Fail if we do not have a valid file ref.
199 if (!response_info_->data().body_as_file_ref.IsValid())
191 return PP_ERROR_FAILED; 200 return PP_ERROR_FAILED;
192 201
193 // We may have already reached EOF. 202 // We may have already reached EOF.
194 if (done_status_ != PP_OK_COMPLETIONPENDING) 203 if (done_status_ != PP_OK_COMPLETIONPENDING)
195 return done_status_; 204 return done_status_;
196 205
197 is_streaming_to_file_ = true; 206 is_streaming_to_file_ = true;
198 if (is_asynchronous_load_suspended_) 207 if (is_asynchronous_load_suspended_)
199 SetDefersLoading(false); 208 SetDefersLoading(false);
200 209
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
350 // As a second line of defense, clear the |user_buffer_| in case the 359 // As a second line of defense, clear the |user_buffer_| in case the
351 // callbacks get called in an unexpected order. 360 // callbacks get called in an unexpected order.
352 user_buffer_ = NULL; 361 user_buffer_ = NULL;
353 user_buffer_size_ = 0; 362 user_buffer_size_ = 0;
354 pending_callback_->Run(result); 363 pending_callback_->Run(result);
355 } 364 }
356 365
357 void URLLoaderResource::SaveResponseInfo(const URLResponseInfoData& data) { 366 void URLLoaderResource::SaveResponseInfo(const URLResponseInfoData& data) {
358 // Create a proxy resource for the the file ref host resource if needed. 367 // Create a proxy resource for the the file ref host resource if needed.
359 PP_Resource body_as_file_ref = 0; 368 PP_Resource body_as_file_ref = 0;
360 if (!data.body_as_file_ref.resource.is_null()) { 369 if (data.body_as_file_ref.IsValid()) {
361 thunk::EnterResourceCreationNoLock enter(pp_instance()); 370 body_as_file_ref = FileRefResource::CreateFileRef(connection(),
362 body_as_file_ref = 371 pp_instance(),
363 enter.functions()->CreateFileRef(data.body_as_file_ref); 372 data.body_as_file_ref);
364 } 373 }
365 response_info_ = new URLResponseInfoResource( 374 response_info_ = new URLResponseInfoResource(
366 connection(), pp_instance(), data, body_as_file_ref); 375 connection(), pp_instance(), data, body_as_file_ref);
367 } 376 }
368 377
369 size_t URLLoaderResource::FillUserBuffer() { 378 size_t URLLoaderResource::FillUserBuffer() {
370 DCHECK(user_buffer_); 379 DCHECK(user_buffer_);
371 DCHECK(user_buffer_size_); 380 DCHECK(user_buffer_size_);
372 381
373 size_t bytes_to_copy = std::min(buffer_.size(), user_buffer_size_); 382 size_t bytes_to_copy = std::min(buffer_.size(), user_buffer_size_);
374 std::copy(buffer_.begin(), buffer_.begin() + bytes_to_copy, user_buffer_); 383 std::copy(buffer_.begin(), buffer_.begin() + bytes_to_copy, user_buffer_);
375 buffer_.erase(buffer_.begin(), buffer_.begin() + bytes_to_copy); 384 buffer_.erase(buffer_.begin(), buffer_.begin() + bytes_to_copy);
376 385
377 // If the buffer is getting too empty, resume asynchronous loading. 386 // If the buffer is getting too empty, resume asynchronous loading.
378 if (is_asynchronous_load_suspended_ && 387 if (is_asynchronous_load_suspended_ &&
379 buffer_.size() <= static_cast<size_t>( 388 buffer_.size() <= static_cast<size_t>(
380 request_data_.prefetch_buffer_lower_threshold)) { 389 request_data_.prefetch_buffer_lower_threshold)) {
381 DVLOG(1) << "Resuming async load - buffer size: " << buffer_.size(); 390 DVLOG(1) << "Resuming async load - buffer size: " << buffer_.size();
382 SetDefersLoading(false); 391 SetDefersLoading(false);
383 } 392 }
384 393
385 // Reset for next time. 394 // Reset for next time.
386 user_buffer_ = NULL; 395 user_buffer_ = NULL;
387 user_buffer_size_ = 0; 396 user_buffer_size_ = 0;
388 return bytes_to_copy; 397 return bytes_to_copy;
389 } 398 }
390 399
391 } // namespace proxy 400 } // namespace proxy
392 } // namespace ppapi 401 } // namespace ppapi
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698