| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "net/base/file_stream_context.h" | 5 #include "net/base/file_stream_context.h" |
| 6 | 6 |
| 7 #include <windows.h> | 7 #include <windows.h> |
| 8 | 8 |
| 9 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/metrics/histogram.h" | 11 #include "base/metrics/histogram.h" |
| 12 #include "base/profiler/scoped_tracker.h" |
| 12 #include "base/task_runner.h" | 13 #include "base/task_runner.h" |
| 13 #include "net/base/io_buffer.h" | 14 #include "net/base/io_buffer.h" |
| 14 #include "net/base/net_errors.h" | 15 #include "net/base/net_errors.h" |
| 15 | 16 |
| 16 namespace net { | 17 namespace net { |
| 17 | 18 |
| 18 namespace { | 19 namespace { |
| 19 | 20 |
| 20 void SetOffset(OVERLAPPED* overlapped, const LARGE_INTEGER& offset) { | 21 void SetOffset(OVERLAPPED* overlapped, const LARGE_INTEGER& offset) { |
| 21 overlapped->Offset = offset.LowPart; | 22 overlapped->Offset = offset.LowPart; |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 55 OnFileOpened(); | 56 OnFileOpened(); |
| 56 } | 57 } |
| 57 } | 58 } |
| 58 | 59 |
| 59 FileStream::Context::~Context() { | 60 FileStream::Context::~Context() { |
| 60 } | 61 } |
| 61 | 62 |
| 62 int FileStream::Context::Read(IOBuffer* buf, | 63 int FileStream::Context::Read(IOBuffer* buf, |
| 63 int buf_len, | 64 int buf_len, |
| 64 const CompletionCallback& callback) { | 65 const CompletionCallback& callback) { |
| 66 // TODO(vadimt): Remove ScopedTracker below once crbug.com/423948 is fixed. |
| 67 tracked_objects::ScopedTracker tracking_profile( |
| 68 FROM_HERE_WITH_EXPLICIT_FUNCTION("423948 FileStream::Context::Read")); |
| 69 |
| 65 DCHECK(!async_in_progress_); | 70 DCHECK(!async_in_progress_); |
| 66 | 71 |
| 67 DWORD bytes_read; | 72 DWORD bytes_read; |
| 68 if (!ReadFile(file_.GetPlatformFile(), buf->data(), buf_len, | 73 if (!ReadFile(file_.GetPlatformFile(), buf->data(), buf_len, |
| 69 &bytes_read, &io_context_.overlapped)) { | 74 &bytes_read, &io_context_.overlapped)) { |
| 70 IOResult error = IOResult::FromOSError(GetLastError()); | 75 IOResult error = IOResult::FromOSError(GetLastError()); |
| 71 if (error.os_error == ERROR_HANDLE_EOF) | 76 if (error.os_error == ERROR_HANDLE_EOF) |
| 72 return 0; // Report EOF by returning 0 bytes read. | 77 return 0; // Report EOF by returning 0 bytes read. |
| 73 if (error.os_error == ERROR_IO_PENDING) | 78 if (error.os_error == ERROR_IO_PENDING) |
| 74 IOCompletionIsPending(callback, buf); | 79 IOCompletionIsPending(callback, buf); |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 154 } | 159 } |
| 155 | 160 |
| 156 CompletionCallback temp_callback = callback_; | 161 CompletionCallback temp_callback = callback_; |
| 157 callback_.Reset(); | 162 callback_.Reset(); |
| 158 scoped_refptr<IOBuffer> temp_buf = in_flight_buf_; | 163 scoped_refptr<IOBuffer> temp_buf = in_flight_buf_; |
| 159 in_flight_buf_ = NULL; | 164 in_flight_buf_ = NULL; |
| 160 temp_callback.Run(result); | 165 temp_callback.Run(result); |
| 161 } | 166 } |
| 162 | 167 |
| 163 } // namespace net | 168 } // namespace net |
| OLD | NEW |