| OLD | NEW |
| 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 // This file contains an implementation of the ResourceLoaderBridge class. | 5 // This file contains an implementation of the ResourceLoaderBridge class. |
| 6 // The class is implemented using net::URLRequest, meaning it is a "simple" | 6 // The class is implemented using net::URLRequest, meaning it is a "simple" |
| 7 // version that directly issues requests. The more complicated one used in the | 7 // version that directly issues requests. The more complicated one used in the |
| 8 // browser uses IPC. | 8 // browser uses IPC. |
| 9 // | 9 // |
| 10 // Because net::URLRequest only provides an asynchronous resource loading API, | 10 // Because net::URLRequest only provides an asynchronous resource loading API, |
| (...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 263 | 263 |
| 264 // Continue reading more data, see the comment in NotifyReceivedData. | 264 // Continue reading more data, see the comment in NotifyReceivedData. |
| 265 g_io_thread->message_loop()->PostTask(FROM_HERE, NewRunnableMethod( | 265 g_io_thread->message_loop()->PostTask(FROM_HERE, NewRunnableMethod( |
| 266 this, &RequestProxy::AsyncReadData)); | 266 this, &RequestProxy::AsyncReadData)); |
| 267 | 267 |
| 268 peer_->OnDownloadedData(bytes_read); | 268 peer_->OnDownloadedData(bytes_read); |
| 269 } | 269 } |
| 270 | 270 |
| 271 void NotifyCompletedRequest(const net::URLRequestStatus& status, | 271 void NotifyCompletedRequest(const net::URLRequestStatus& status, |
| 272 const std::string& security_info, | 272 const std::string& security_info, |
| 273 const base::Time& complete_time) { | 273 const base::TimeTicks& complete_time) { |
| 274 if (peer_) { | 274 if (peer_) { |
| 275 peer_->OnCompletedRequest(status, security_info, complete_time); | 275 peer_->OnCompletedRequest(status, security_info, complete_time); |
| 276 DropPeer(); // ensure no further notifications | 276 DropPeer(); // ensure no further notifications |
| 277 } | 277 } |
| 278 } | 278 } |
| 279 | 279 |
| 280 void NotifyUploadProgress(uint64 position, uint64 size) { | 280 void NotifyUploadProgress(uint64 position, uint64 size) { |
| 281 if (peer_) | 281 if (peer_) |
| 282 peer_->OnUploadProgress(position, size); | 282 peer_->OnUploadProgress(position, size); |
| 283 } | 283 } |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 394 this, &RequestProxy::NotifyDownloadedData, bytes_read)); | 394 this, &RequestProxy::NotifyDownloadedData, bytes_read)); |
| 395 return; | 395 return; |
| 396 } | 396 } |
| 397 | 397 |
| 398 owner_loop_->PostTask(FROM_HERE, NewRunnableMethod( | 398 owner_loop_->PostTask(FROM_HERE, NewRunnableMethod( |
| 399 this, &RequestProxy::NotifyReceivedData, bytes_read)); | 399 this, &RequestProxy::NotifyReceivedData, bytes_read)); |
| 400 } | 400 } |
| 401 | 401 |
| 402 virtual void OnCompletedRequest(const net::URLRequestStatus& status, | 402 virtual void OnCompletedRequest(const net::URLRequestStatus& status, |
| 403 const std::string& security_info, | 403 const std::string& security_info, |
| 404 const base::Time& complete_time) { | 404 const base::TimeTicks& complete_time) { |
| 405 if (download_to_file_) | 405 if (download_to_file_) |
| 406 file_stream_.Close(); | 406 file_stream_.Close(); |
| 407 owner_loop_->PostTask(FROM_HERE, NewRunnableMethod( | 407 owner_loop_->PostTask(FROM_HERE, NewRunnableMethod( |
| 408 this, | 408 this, |
| 409 &RequestProxy::NotifyCompletedRequest, | 409 &RequestProxy::NotifyCompletedRequest, |
| 410 status, | 410 status, |
| 411 security_info, | 411 security_info, |
| 412 complete_time)); | 412 complete_time)); |
| 413 } | 413 } |
| 414 | 414 |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 479 | 479 |
| 480 // -------------------------------------------------------------------------- | 480 // -------------------------------------------------------------------------- |
| 481 // Helpers and data: | 481 // Helpers and data: |
| 482 | 482 |
| 483 void Done() { | 483 void Done() { |
| 484 if (upload_progress_timer_.IsRunning()) { | 484 if (upload_progress_timer_.IsRunning()) { |
| 485 MaybeUpdateUploadProgress(); | 485 MaybeUpdateUploadProgress(); |
| 486 upload_progress_timer_.Stop(); | 486 upload_progress_timer_.Stop(); |
| 487 } | 487 } |
| 488 DCHECK(request_.get()); | 488 DCHECK(request_.get()); |
| 489 OnCompletedRequest(request_->status(), std::string(), base::Time()); | 489 OnCompletedRequest(request_->status(), std::string(), base::TimeTicks()); |
| 490 request_.reset(); // destroy on the io thread | 490 request_.reset(); // destroy on the io thread |
| 491 } | 491 } |
| 492 | 492 |
| 493 // Called on the IO thread. | 493 // Called on the IO thread. |
| 494 void MaybeUpdateUploadProgress() { | 494 void MaybeUpdateUploadProgress() { |
| 495 // If a redirect is received upload is cancelled in net::URLRequest, we | 495 // If a redirect is received upload is cancelled in net::URLRequest, we |
| 496 // should try to stop the |upload_progress_timer_| timer and return. | 496 // should try to stop the |upload_progress_timer_| timer and return. |
| 497 if (!request_->has_upload()) { | 497 if (!request_->has_upload()) { |
| 498 if (upload_progress_timer_.IsRunning()) | 498 if (upload_progress_timer_.IsRunning()) |
| 499 upload_progress_timer_.Stop(); | 499 upload_progress_timer_.Stop(); |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 607 virtual void OnReceivedData(int bytes_read) { | 607 virtual void OnReceivedData(int bytes_read) { |
| 608 if (download_to_file_) | 608 if (download_to_file_) |
| 609 file_stream_.Write(buf_->data(), bytes_read, NULL); | 609 file_stream_.Write(buf_->data(), bytes_read, NULL); |
| 610 else | 610 else |
| 611 result_->data.append(buf_->data(), bytes_read); | 611 result_->data.append(buf_->data(), bytes_read); |
| 612 AsyncReadData(); // read more (may recurse) | 612 AsyncReadData(); // read more (may recurse) |
| 613 } | 613 } |
| 614 | 614 |
| 615 virtual void OnCompletedRequest(const net::URLRequestStatus& status, | 615 virtual void OnCompletedRequest(const net::URLRequestStatus& status, |
| 616 const std::string& security_info, | 616 const std::string& security_info, |
| 617 const base::Time& complete_time) { | 617 const base::TimeTicks& complete_time) { |
| 618 if (download_to_file_) | 618 if (download_to_file_) |
| 619 file_stream_.Close(); | 619 file_stream_.Close(); |
| 620 result_->status = status; | 620 result_->status = status; |
| 621 event_.Signal(); | 621 event_.Signal(); |
| 622 } | 622 } |
| 623 | 623 |
| 624 private: | 624 private: |
| 625 ResourceLoaderBridge::SyncLoadResponse* result_; | 625 ResourceLoaderBridge::SyncLoadResponse* result_; |
| 626 base::WaitableEvent event_; | 626 base::WaitableEvent event_; |
| 627 }; | 627 }; |
| (...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 919 | 919 |
| 920 // static | 920 // static |
| 921 scoped_refptr<base::MessageLoopProxy> | 921 scoped_refptr<base::MessageLoopProxy> |
| 922 SimpleResourceLoaderBridge::GetIoThread() { | 922 SimpleResourceLoaderBridge::GetIoThread() { |
| 923 if (!EnsureIOThread()) { | 923 if (!EnsureIOThread()) { |
| 924 LOG(DFATAL) << "Failed to create IO thread."; | 924 LOG(DFATAL) << "Failed to create IO thread."; |
| 925 return NULL; | 925 return NULL; |
| 926 } | 926 } |
| 927 return g_io_thread->message_loop_proxy(); | 927 return g_io_thread->message_loop_proxy(); |
| 928 } | 928 } |
| OLD | NEW |