Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(147)

Side by Side Diff: net/base/file_stream_context_win.cc

Issue 1148383003: Only support seeking file streams from the beginning of the file. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix Win DBG build by Pass()-ing file out of CreateForAsyncHandle. Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « net/base/file_stream_context_posix.cc ('k') | net/base/file_stream_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/location.h" 10 #include "base/location.h"
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 async_in_progress_(false), 56 async_in_progress_(false),
57 orphaned_(false), 57 orphaned_(false),
58 task_runner_(task_runner), 58 task_runner_(task_runner),
59 async_read_initiated_(false), 59 async_read_initiated_(false),
60 async_read_completed_(false), 60 async_read_completed_(false),
61 io_complete_for_read_received_(false), 61 io_complete_for_read_received_(false),
62 result_(0) { 62 result_(0) {
63 io_context_.handler = this; 63 io_context_.handler = this;
64 memset(&io_context_.overlapped, 0, sizeof(io_context_.overlapped)); 64 memset(&io_context_.overlapped, 0, sizeof(io_context_.overlapped));
65 if (file_.IsValid()) { 65 if (file_.IsValid()) {
66 // TODO(hashimoto): Check that file_ is async. 66 DCHECK(file_.async());
67 OnFileOpened(); 67 OnFileOpened();
68 } 68 }
69 } 69 }
70 70
71 FileStream::Context::~Context() { 71 FileStream::Context::~Context() {
72 } 72 }
73 73
74 int FileStream::Context::Read(IOBuffer* buf, 74 int FileStream::Context::Read(IOBuffer* buf,
75 int buf_len, 75 int buf_len,
76 const CompletionCallback& callback) { 76 const CompletionCallback& callback) {
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 else 108 else
109 LOG(WARNING) << "WriteFile failed: " << error.os_error; 109 LOG(WARNING) << "WriteFile failed: " << error.os_error;
110 return static_cast<int>(error.result); 110 return static_cast<int>(error.result);
111 } 111 }
112 112
113 IOCompletionIsPending(callback, buf); 113 IOCompletionIsPending(callback, buf);
114 return ERR_IO_PENDING; 114 return ERR_IO_PENDING;
115 } 115 }
116 116
117 FileStream::Context::IOResult FileStream::Context::SeekFileImpl( 117 FileStream::Context::IOResult FileStream::Context::SeekFileImpl(
118 base::File::Whence whence,
119 int64_t offset) { 118 int64_t offset) {
120 LARGE_INTEGER result; 119 LARGE_INTEGER result;
121 result.QuadPart = file_.Seek(whence, offset); 120 result.QuadPart = offset;
122 if (result.QuadPart >= 0) { 121 SetOffset(&io_context_.overlapped, result);
123 SetOffset(&io_context_.overlapped, result); 122 return IOResult(result.QuadPart, 0);
124 return IOResult(result.QuadPart, 0);
125 }
126
127 return IOResult::FromOSError(GetLastError());
128 } 123 }
129 124
130 void FileStream::Context::OnFileOpened() { 125 void FileStream::Context::OnFileOpened() {
131 base::MessageLoopForIO::current()->RegisterIOHandler(file_.GetPlatformFile(), 126 base::MessageLoopForIO::current()->RegisterIOHandler(file_.GetPlatformFile(),
132 this); 127 this);
133 } 128 }
134 129
135 void FileStream::Context::IOCompletionIsPending( 130 void FileStream::Context::IOCompletionIsPending(
136 const CompletionCallback& callback, 131 const CompletionCallback& callback,
137 IOBuffer* buf) { 132 IOBuffer* buf) {
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
241 236
242 IOResult error = IOResult::FromOSError(os_error); 237 IOResult error = IOResult::FromOSError(os_error);
243 if (error.os_error == ERROR_IO_PENDING) { 238 if (error.os_error == ERROR_IO_PENDING) {
244 InvokeUserCallback(); 239 InvokeUserCallback();
245 } else { 240 } else {
246 OnIOCompleted(&io_context_, 0, error.os_error); 241 OnIOCompleted(&io_context_, 0, error.os_error);
247 } 242 }
248 } 243 }
249 244
250 } // namespace net 245 } // namespace net
OLDNEW
« no previous file with comments | « net/base/file_stream_context_posix.cc ('k') | net/base/file_stream_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698