| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "chrome/browser/chromeos/file_system_provider/fileapi/buffering_file_st
ream_reader.h" | 5 #include "chrome/browser/chromeos/file_system_provider/fileapi/buffering_file_st
ream_reader.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "net/base/io_buffer.h" | 9 #include "net/base/io_buffer.h" |
| 10 #include "net/base/net_errors.h" | 10 #include "net/base/net_errors.h" |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 77 return read_bytes; | 77 return read_bytes; |
| 78 } | 78 } |
| 79 | 79 |
| 80 void BufferingFileStreamReader::Preload( | 80 void BufferingFileStreamReader::Preload( |
| 81 const net::CompletionCallback& callback) { | 81 const net::CompletionCallback& callback) { |
| 82 // TODO(mtomasz): Dynamically calculate the chunk size. Start from a small | 82 // TODO(mtomasz): Dynamically calculate the chunk size. Start from a small |
| 83 // one, then increase for consecutive requests. That would improve performance | 83 // one, then increase for consecutive requests. That would improve performance |
| 84 // when reading just small chunks, instead of the entire file. | 84 // when reading just small chunks, instead of the entire file. |
| 85 const int preload_bytes = buffer_size_; | 85 const int preload_bytes = buffer_size_; |
| 86 | 86 |
| 87 const int result = | 87 const int result = file_stream_reader_->Read( |
| 88 file_stream_reader_->Read(preloading_buffer_, preload_bytes, callback); | 88 preloading_buffer_.get(), preload_bytes, callback); |
| 89 DCHECK_EQ(result, net::ERR_IO_PENDING); | 89 DCHECK_EQ(result, net::ERR_IO_PENDING); |
| 90 } | 90 } |
| 91 | 91 |
| 92 void BufferingFileStreamReader::OnPreloadCompleted( | 92 void BufferingFileStreamReader::OnPreloadCompleted( |
| 93 scoped_refptr<net::IOBuffer> buffer, | 93 scoped_refptr<net::IOBuffer> buffer, |
| 94 int buffer_length, | 94 int buffer_length, |
| 95 const net::CompletionCallback& callback, | 95 const net::CompletionCallback& callback, |
| 96 int result) { | 96 int result) { |
| 97 if (result < 0) { | 97 if (result < 0) { |
| 98 callback.Run(result); | 98 callback.Run(result); |
| 99 return; | 99 return; |
| 100 } | 100 } |
| 101 | 101 |
| 102 preloading_buffer_offset_ = 0; | 102 preloading_buffer_offset_ = 0; |
| 103 buffered_bytes_ = result; | 103 buffered_bytes_ = result; |
| 104 | 104 |
| 105 callback.Run(CopyFromPreloadingBuffer(buffer, buffer_length)); | 105 callback.Run(CopyFromPreloadingBuffer(buffer, buffer_length)); |
| 106 } | 106 } |
| 107 | 107 |
| 108 } // namespace file_system_provider | 108 } // namespace file_system_provider |
| 109 } // namespace chromeos | 109 } // namespace chromeos |
| OLD | NEW |