| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "base/callback.h" | 5 #include "base/callback.h" |
| 6 #include "base/compiler_specific.h" | 6 #include "base/compiler_specific.h" |
| 7 #include "base/message_loop.h" | 7 #include "base/message_loop.h" |
| 8 #include "base/process_util.h" | 8 #include "base/process_util.h" |
| 9 #include "base/stl_util-inl.h" | 9 #include "base/stl_util-inl.h" |
| 10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
| (...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 314 | 314 |
| 315 void BufferedResourceLoader::OnReceivedData(const char* data, int len) { | 315 void BufferedResourceLoader::OnReceivedData(const char* data, int len) { |
| 316 DCHECK(bridge_.get()); | 316 DCHECK(bridge_.get()); |
| 317 | 317 |
| 318 // If this loader has been stopped, |buffer_| would be destroyed. | 318 // If this loader has been stopped, |buffer_| would be destroyed. |
| 319 // In this case we shouldn't do anything. | 319 // In this case we shouldn't do anything. |
| 320 if (!buffer_.get()) | 320 if (!buffer_.get()) |
| 321 return; | 321 return; |
| 322 | 322 |
| 323 // Writes more data to |buffer_|. | 323 // Writes more data to |buffer_|. |
| 324 buffer_->Append(len, reinterpret_cast<const uint8*>(data)); | 324 buffer_->Append(reinterpret_cast<const uint8*>(data), len); |
| 325 | 325 |
| 326 // If there is an active read request, try to fulfill the request. | 326 // If there is an active read request, try to fulfill the request. |
| 327 if (HasPendingRead() && CanFulfillRead()) { | 327 if (HasPendingRead() && CanFulfillRead()) { |
| 328 ReadInternal(); | 328 ReadInternal(); |
| 329 } | 329 } |
| 330 | 330 |
| 331 // At last see if the buffer is full and we need to defer the downloading. | 331 // At last see if the buffer is full and we need to defer the downloading. |
| 332 EnableDeferIfNeeded(); | 332 EnableDeferIfNeeded(); |
| 333 | 333 |
| 334 // Notify that we have received some data. | 334 // Notify that we have received some data. |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 444 | 444 |
| 445 return true; | 445 return true; |
| 446 } | 446 } |
| 447 | 447 |
| 448 void BufferedResourceLoader::ReadInternal() { | 448 void BufferedResourceLoader::ReadInternal() { |
| 449 // Seek to the first byte requested. | 449 // Seek to the first byte requested. |
| 450 bool ret = buffer_->Seek(first_offset_); | 450 bool ret = buffer_->Seek(first_offset_); |
| 451 DCHECK(ret); | 451 DCHECK(ret); |
| 452 | 452 |
| 453 // Then do the read. | 453 // Then do the read. |
| 454 int read = static_cast<int>(buffer_->Read(read_size_, read_buffer_)); | 454 int read = static_cast<int>(buffer_->Read(read_buffer_, read_size_)); |
| 455 offset_ += first_offset_ + read; | 455 offset_ += first_offset_ + read; |
| 456 | 456 |
| 457 // And report with what we have read. | 457 // And report with what we have read. |
| 458 DoneRead(read); | 458 DoneRead(read); |
| 459 } | 459 } |
| 460 | 460 |
| 461 bool BufferedResourceLoader::VerifyPartialResponse( | 461 bool BufferedResourceLoader::VerifyPartialResponse( |
| 462 const ResourceLoaderBridge::ResponseInfo& info) { | 462 const ResourceLoaderBridge::ResponseInfo& info) { |
| 463 int64 first_byte_position, last_byte_position, instance_size; | 463 int64 first_byte_position, last_byte_position, instance_size; |
| 464 if (!info.headers->GetContentRange(&first_byte_position, | 464 if (!info.headers->GetContentRange(&first_byte_position, |
| (...skipping 531 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 996 return; | 996 return; |
| 997 | 997 |
| 998 if (network_activity != network_activity_) { | 998 if (network_activity != network_activity_) { |
| 999 network_activity_ = network_activity; | 999 network_activity_ = network_activity; |
| 1000 host()->SetNetworkActivity(network_activity); | 1000 host()->SetNetworkActivity(network_activity); |
| 1001 } | 1001 } |
| 1002 host()->SetBufferedBytes(buffered_last_byte_position + 1); | 1002 host()->SetBufferedBytes(buffered_last_byte_position + 1); |
| 1003 } | 1003 } |
| 1004 | 1004 |
| 1005 } // namespace webkit_glue | 1005 } // namespace webkit_glue |
| OLD | NEW |