OLD | NEW |
1 // Copyright (c) 2010 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, |
11 // this file makes use of net::URLRequest from a background IO thread. Requests | 11 // this file makes use of net::URLRequest from a background IO thread. Requests |
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
284 if (!peer_) | 284 if (!peer_) |
285 return; | 285 return; |
286 | 286 |
287 // Continue reading more data, see the comment in NotifyReceivedData. | 287 // Continue reading more data, see the comment in NotifyReceivedData. |
288 g_io_thread->message_loop()->PostTask(FROM_HERE, NewRunnableMethod( | 288 g_io_thread->message_loop()->PostTask(FROM_HERE, NewRunnableMethod( |
289 this, &RequestProxy::AsyncReadData)); | 289 this, &RequestProxy::AsyncReadData)); |
290 | 290 |
291 peer_->OnDownloadedData(bytes_read); | 291 peer_->OnDownloadedData(bytes_read); |
292 } | 292 } |
293 | 293 |
294 void NotifyCompletedRequest(const URLRequestStatus& status, | 294 void NotifyCompletedRequest(const net::URLRequestStatus& status, |
295 const std::string& security_info, | 295 const std::string& security_info, |
296 const base::Time& complete_time) { | 296 const base::Time& complete_time) { |
297 if (peer_) { | 297 if (peer_) { |
298 peer_->OnCompletedRequest(status, security_info, complete_time); | 298 peer_->OnCompletedRequest(status, security_info, complete_time); |
299 DropPeer(); // ensure no further notifications | 299 DropPeer(); // ensure no further notifications |
300 } | 300 } |
301 } | 301 } |
302 | 302 |
303 void NotifyUploadProgress(uint64 position, uint64 size) { | 303 void NotifyUploadProgress(uint64 position, uint64 size) { |
304 if (peer_) | 304 if (peer_) |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
416 file_stream_.Write(buf_->data(), bytes_read, NULL); | 416 file_stream_.Write(buf_->data(), bytes_read, NULL); |
417 owner_loop_->PostTask(FROM_HERE, NewRunnableMethod( | 417 owner_loop_->PostTask(FROM_HERE, NewRunnableMethod( |
418 this, &RequestProxy::NotifyDownloadedData, bytes_read)); | 418 this, &RequestProxy::NotifyDownloadedData, bytes_read)); |
419 return; | 419 return; |
420 } | 420 } |
421 | 421 |
422 owner_loop_->PostTask(FROM_HERE, NewRunnableMethod( | 422 owner_loop_->PostTask(FROM_HERE, NewRunnableMethod( |
423 this, &RequestProxy::NotifyReceivedData, bytes_read)); | 423 this, &RequestProxy::NotifyReceivedData, bytes_read)); |
424 } | 424 } |
425 | 425 |
426 virtual void OnCompletedRequest(const URLRequestStatus& status, | 426 virtual void OnCompletedRequest(const net::URLRequestStatus& status, |
427 const std::string& security_info, | 427 const std::string& security_info, |
428 const base::Time& complete_time) { | 428 const base::Time& complete_time) { |
429 if (download_to_file_) | 429 if (download_to_file_) |
430 file_stream_.Close(); | 430 file_stream_.Close(); |
431 owner_loop_->PostTask(FROM_HERE, NewRunnableMethod( | 431 owner_loop_->PostTask(FROM_HERE, NewRunnableMethod( |
432 this, | 432 this, |
433 &RequestProxy::NotifyCompletedRequest, | 433 &RequestProxy::NotifyCompletedRequest, |
434 status, | 434 status, |
435 security_info, | 435 security_info, |
436 complete_time)); | 436 complete_time)); |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
604 } | 604 } |
605 | 605 |
606 virtual void OnReceivedData(int bytes_read) { | 606 virtual void OnReceivedData(int bytes_read) { |
607 if (download_to_file_) | 607 if (download_to_file_) |
608 file_stream_.Write(buf_->data(), bytes_read, NULL); | 608 file_stream_.Write(buf_->data(), bytes_read, NULL); |
609 else | 609 else |
610 result_->data.append(buf_->data(), bytes_read); | 610 result_->data.append(buf_->data(), bytes_read); |
611 AsyncReadData(); // read more (may recurse) | 611 AsyncReadData(); // read more (may recurse) |
612 } | 612 } |
613 | 613 |
614 virtual void OnCompletedRequest(const URLRequestStatus& status, | 614 virtual void OnCompletedRequest(const net::URLRequestStatus& status, |
615 const std::string& security_info, | 615 const std::string& security_info, |
616 const base::Time& complete_time) { | 616 const base::Time& complete_time) { |
617 if (download_to_file_) | 617 if (download_to_file_) |
618 file_stream_.Close(); | 618 file_stream_.Close(); |
619 result_->status = status; | 619 result_->status = status; |
620 event_.Signal(); | 620 event_.Signal(); |
621 } | 621 } |
622 | 622 |
623 private: | 623 private: |
624 ResourceLoaderBridge::SyncLoadResponse* result_; | 624 ResourceLoaderBridge::SyncLoadResponse* result_; |
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
928 | 928 |
929 // static | 929 // static |
930 scoped_refptr<base::MessageLoopProxy> | 930 scoped_refptr<base::MessageLoopProxy> |
931 SimpleResourceLoaderBridge::GetIoThread() { | 931 SimpleResourceLoaderBridge::GetIoThread() { |
932 if (!EnsureIOThread()) { | 932 if (!EnsureIOThread()) { |
933 LOG(DFATAL) << "Failed to create IO thread."; | 933 LOG(DFATAL) << "Failed to create IO thread."; |
934 return NULL; | 934 return NULL; |
935 } | 935 } |
936 return g_io_thread->message_loop_proxy(); | 936 return g_io_thread->message_loop_proxy(); |
937 } | 937 } |
OLD | NEW |