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

Side by Side Diff: webkit/plugins/ppapi/ppb_url_loader_impl.cc

Issue 7706021: Convert FileRefImpl and URLRequestInfo to shared_impl. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Tests fixed Created 9 years, 3 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 "webkit/plugins/ppapi/ppb_url_loader_impl.h" 5 #include "webkit/plugins/ppapi/ppb_url_loader_impl.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "net/base/net_errors.h" 8 #include "net/base/net_errors.h"
9 #include "ppapi/c/pp_completion_callback.h" 9 #include "ppapi/c/pp_completion_callback.h"
10 #include "ppapi/c/pp_errors.h" 10 #include "ppapi/c/pp_errors.h"
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 108
109 if (request->RequiresUniversalAccess() && !has_universal_access_) 109 if (request->RequiresUniversalAccess() && !has_universal_access_)
110 return PP_ERROR_NOACCESS; 110 return PP_ERROR_NOACCESS;
111 111
112 if (loader_.get()) 112 if (loader_.get())
113 return PP_ERROR_INPROGRESS; 113 return PP_ERROR_INPROGRESS;
114 114
115 WebFrame* frame = GetFrameForResource(this); 115 WebFrame* frame = GetFrameForResource(this);
116 if (!frame) 116 if (!frame)
117 return PP_ERROR_FAILED; 117 return PP_ERROR_FAILED;
118 WebURLRequest web_request(request->ToWebURLRequest(frame)); 118 WebURLRequest web_request;
119 if (!request->ToWebURLRequest(frame, &web_request))
120 return PP_ERROR_FAILED;
121
122 // Save a copy of the request info so the plugin can continue to use and
123 // change it while we're doing the request without affecting us. We must do
124 // this after ToWebURLRequest since that fills out the file refs.
125 request_data_ = request->GetData();
119 126
120 WebURLLoaderOptions options; 127 WebURLLoaderOptions options;
121 if (has_universal_access_) { 128 if (has_universal_access_) {
122 // Universal access allows cross-origin requests and sends credentials. 129 // Universal access allows cross-origin requests and sends credentials.
123 options.crossOriginRequestPolicy = 130 options.crossOriginRequestPolicy =
124 WebURLLoaderOptions::CrossOriginRequestPolicyAllow; 131 WebURLLoaderOptions::CrossOriginRequestPolicyAllow;
125 options.allowCredentials = true; 132 options.allowCredentials = true;
126 } else if (request->allow_cross_origin_requests()) { 133 } else if (request_data_.allow_cross_origin_requests) {
127 // Otherwise, allow cross-origin requests with access control. 134 // Otherwise, allow cross-origin requests with access control.
128 options.crossOriginRequestPolicy = 135 options.crossOriginRequestPolicy =
129 WebURLLoaderOptions::CrossOriginRequestPolicyUseAccessControl; 136 WebURLLoaderOptions::CrossOriginRequestPolicyUseAccessControl;
130 options.allowCredentials = request->allow_credentials(); 137 options.allowCredentials = request_data_.allow_credentials;
131 } 138 }
132 139
133 is_asynchronous_load_suspended_ = false; 140 is_asynchronous_load_suspended_ = false;
134 loader_.reset(frame->createAssociatedURLLoader(options)); 141 loader_.reset(frame->createAssociatedURLLoader(options));
135 if (!loader_.get()) 142 if (!loader_.get())
136 return PP_ERROR_FAILED; 143 return PP_ERROR_FAILED;
137 144
138 loader_->loadAsynchronously(web_request, this); 145 loader_->loadAsynchronously(web_request, this);
139 146
140 request_info_ = scoped_refptr<PPB_URLRequestInfo_Impl>(request);
141
142 // Notify completion when we receive a redirect or response headers. 147 // Notify completion when we receive a redirect or response headers.
143 RegisterCallback(callback); 148 RegisterCallback(callback);
144 return PP_OK_COMPLETIONPENDING; 149 return PP_OK_COMPLETIONPENDING;
145 } 150 }
146 151
147 int32_t PPB_URLLoader_Impl::FollowRedirect(PP_CompletionCallback callback) { 152 int32_t PPB_URLLoader_Impl::FollowRedirect(PP_CompletionCallback callback) {
148 int32_t rv = ValidateCallback(callback); 153 int32_t rv = ValidateCallback(callback);
149 if (rv != PP_OK) 154 if (rv != PP_OK)
150 return rv; 155 return rv;
151 156
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
253 258
254 void PPB_URLLoader_Impl::SetStatusCallback( 259 void PPB_URLLoader_Impl::SetStatusCallback(
255 PP_URLLoaderTrusted_StatusCallback cb) { 260 PP_URLLoaderTrusted_StatusCallback cb) {
256 status_callback_ = cb; 261 status_callback_ = cb;
257 } 262 }
258 263
259 void PPB_URLLoader_Impl::willSendRequest( 264 void PPB_URLLoader_Impl::willSendRequest(
260 WebURLLoader* loader, 265 WebURLLoader* loader,
261 WebURLRequest& new_request, 266 WebURLRequest& new_request,
262 const WebURLResponse& redirect_response) { 267 const WebURLResponse& redirect_response) {
263 if (!request_info_->follow_redirects()) { 268 if (!request_data_.follow_redirects) {
264 SaveResponse(redirect_response); 269 SaveResponse(redirect_response);
265 loader_->setDefersLoading(true); 270 loader_->setDefersLoading(true);
266 RunCallback(PP_OK); 271 RunCallback(PP_OK);
267 } 272 }
268 } 273 }
269 274
270 void PPB_URLLoader_Impl::didSendData( 275 void PPB_URLLoader_Impl::didSendData(
271 WebURLLoader* loader, 276 WebURLLoader* loader,
272 unsigned long long bytes_sent, 277 unsigned long long bytes_sent,
273 unsigned long long total_bytes_to_be_sent) { 278 unsigned long long total_bytes_to_be_sent) {
(...skipping 29 matching lines...) Expand all
303 buffer_.insert(buffer_.end(), data, data + data_length); 308 buffer_.insert(buffer_.end(), data, data + data_length);
304 if (user_buffer_) { 309 if (user_buffer_) {
305 RunCallback(FillUserBuffer()); 310 RunCallback(FillUserBuffer());
306 } else { 311 } else {
307 DCHECK(!pending_callback_.get() || pending_callback_->completed()); 312 DCHECK(!pending_callback_.get() || pending_callback_->completed());
308 } 313 }
309 314
310 // To avoid letting the network stack download an entire stream all at once, 315 // To avoid letting the network stack download an entire stream all at once,
311 // defer loading when we have enough buffer. 316 // defer loading when we have enough buffer.
312 // Check the buffer size after potentially moving some to the user buffer. 317 // Check the buffer size after potentially moving some to the user buffer.
313 DCHECK(!request_info_ || 318 DCHECK(request_data_.prefetch_buffer_lower_threshold <
314 (request_info_->prefetch_buffer_lower_threshold() < 319 request_data_.prefetch_buffer_upper_threshold);
315 request_info_->prefetch_buffer_upper_threshold()));
316 if (!is_streaming_to_file_ && 320 if (!is_streaming_to_file_ &&
317 !is_asynchronous_load_suspended_ && 321 !is_asynchronous_load_suspended_ &&
318 request_info_ &&
319 (buffer_.size() >= static_cast<size_t>( 322 (buffer_.size() >= static_cast<size_t>(
320 request_info_->prefetch_buffer_upper_threshold()))) { 323 request_data_.prefetch_buffer_upper_threshold))) {
321 DVLOG(1) << "Suspending async load - buffer size: " << buffer_.size(); 324 DVLOG(1) << "Suspending async load - buffer size: " << buffer_.size();
322 loader->setDefersLoading(true); 325 loader->setDefersLoading(true);
323 is_asynchronous_load_suspended_ = true; 326 is_asynchronous_load_suspended_ = true;
324 } 327 }
325 } 328 }
326 329
327 void PPB_URLLoader_Impl::didFinishLoading(WebURLLoader* loader, 330 void PPB_URLLoader_Impl::didFinishLoading(WebURLLoader* loader,
328 double finish_time) { 331 double finish_time) {
329 FinishLoading(PP_OK); 332 FinishLoading(PP_OK);
330 } 333 }
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
395 398
396 size_t PPB_URLLoader_Impl::FillUserBuffer() { 399 size_t PPB_URLLoader_Impl::FillUserBuffer() {
397 DCHECK(user_buffer_); 400 DCHECK(user_buffer_);
398 DCHECK(user_buffer_size_); 401 DCHECK(user_buffer_size_);
399 402
400 size_t bytes_to_copy = std::min(buffer_.size(), user_buffer_size_); 403 size_t bytes_to_copy = std::min(buffer_.size(), user_buffer_size_);
401 std::copy(buffer_.begin(), buffer_.begin() + bytes_to_copy, user_buffer_); 404 std::copy(buffer_.begin(), buffer_.begin() + bytes_to_copy, user_buffer_);
402 buffer_.erase(buffer_.begin(), buffer_.begin() + bytes_to_copy); 405 buffer_.erase(buffer_.begin(), buffer_.begin() + bytes_to_copy);
403 406
404 // If the buffer is getting too empty, resume asynchronous loading. 407 // If the buffer is getting too empty, resume asynchronous loading.
405 DCHECK(!is_asynchronous_load_suspended_ || request_info_); 408 DCHECK(!is_asynchronous_load_suspended_);
406 if (is_asynchronous_load_suspended_ && 409 if (is_asynchronous_load_suspended_ &&
407 buffer_.size() <= static_cast<size_t>( 410 buffer_.size() <= static_cast<size_t>(
408 request_info_->prefetch_buffer_lower_threshold())) { 411 request_data_.prefetch_buffer_lower_threshold)) {
409 DVLOG(1) << "Resuming async load - buffer size: " << buffer_.size(); 412 DVLOG(1) << "Resuming async load - buffer size: " << buffer_.size();
410 loader_->setDefersLoading(false); 413 loader_->setDefersLoading(false);
411 is_asynchronous_load_suspended_ = false; 414 is_asynchronous_load_suspended_ = false;
412 } 415 }
413 416
414 // Reset for next time. 417 // Reset for next time.
415 user_buffer_ = NULL; 418 user_buffer_ = NULL;
416 user_buffer_size_ = 0; 419 user_buffer_size_ = 0;
417 return bytes_to_copy; 420 return bytes_to_copy;
418 } 421 }
(...skipping 16 matching lines...) Expand all
435 status_callback_( 438 status_callback_(
436 pp_instance(), pp_resource(), 439 pp_instance(), pp_resource(),
437 RecordUploadProgress() ? bytes_sent_ : -1, 440 RecordUploadProgress() ? bytes_sent_ : -1,
438 RecordUploadProgress() ? total_bytes_to_be_sent_ : -1, 441 RecordUploadProgress() ? total_bytes_to_be_sent_ : -1,
439 RecordDownloadProgress() ? bytes_received_ : -1, 442 RecordDownloadProgress() ? bytes_received_ : -1,
440 RecordDownloadProgress() ? total_bytes_to_be_received_ : -1); 443 RecordDownloadProgress() ? total_bytes_to_be_received_ : -1);
441 } 444 }
442 } 445 }
443 446
444 bool PPB_URLLoader_Impl::RecordDownloadProgress() const { 447 bool PPB_URLLoader_Impl::RecordDownloadProgress() const {
445 return request_info_ && request_info_->record_download_progress(); 448 return request_data_.record_download_progress;
446 } 449 }
447 450
448 bool PPB_URLLoader_Impl::RecordUploadProgress() const { 451 bool PPB_URLLoader_Impl::RecordUploadProgress() const {
449 return request_info_ && request_info_->record_upload_progress(); 452 return request_data_.record_upload_progress;
450 } 453 }
451 454
452 } // namespace ppapi 455 } // namespace ppapi
453 } // namespace webkit 456 } // namespace webkit
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698