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

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: One more instance where files need to be tagged as async. Created 5 years, 7 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
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/logging.h" 10 #include "base/logging.h"
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 async_in_progress_(false), 55 async_in_progress_(false),
56 orphaned_(false), 56 orphaned_(false),
57 task_runner_(task_runner), 57 task_runner_(task_runner),
58 async_read_initiated_(false), 58 async_read_initiated_(false),
59 async_read_completed_(false), 59 async_read_completed_(false),
60 io_complete_for_read_received_(false), 60 io_complete_for_read_received_(false),
61 result_(0) { 61 result_(0) {
62 io_context_.handler = this; 62 io_context_.handler = this;
63 memset(&io_context_.overlapped, 0, sizeof(io_context_.overlapped)); 63 memset(&io_context_.overlapped, 0, sizeof(io_context_.overlapped));
64 if (file_.IsValid()) { 64 if (file_.IsValid()) {
65 // TODO(hashimoto): Check that file_ is async. 65 DCHECK(file_.async());
66 OnFileOpened(); 66 OnFileOpened();
67 } 67 }
68 } 68 }
69 69
70 FileStream::Context::~Context() { 70 FileStream::Context::~Context() {
71 } 71 }
72 72
73 int FileStream::Context::Read(IOBuffer* buf, 73 int FileStream::Context::Read(IOBuffer* buf,
74 int buf_len, 74 int buf_len,
75 const CompletionCallback& callback) { 75 const CompletionCallback& callback) {
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 IOCompletionIsPending(callback, buf); 107 IOCompletionIsPending(callback, buf);
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(int64 offset) {
118 base::File::Whence whence,
119 int64 offset) {
120 LARGE_INTEGER result; 118 LARGE_INTEGER result;
121 result.QuadPart = file_.Seek(whence, offset); 119 result.QuadPart = offset;
122 if (result.QuadPart >= 0) { 120 SetOffset(&io_context_.overlapped, result);
123 SetOffset(&io_context_.overlapped, result); 121 return IOResult(result.QuadPart, 0);
124 return IOResult(result.QuadPart, 0);
125 }
126
127 return IOResult::FromOSError(GetLastError());
128 } 122 }
129 123
130 void FileStream::Context::OnFileOpened() { 124 void FileStream::Context::OnFileOpened() {
131 base::MessageLoopForIO::current()->RegisterIOHandler(file_.GetPlatformFile(), 125 base::MessageLoopForIO::current()->RegisterIOHandler(file_.GetPlatformFile(),
132 this); 126 this);
133 } 127 }
134 128
135 void FileStream::Context::IOCompletionIsPending( 129 void FileStream::Context::IOCompletionIsPending(
136 const CompletionCallback& callback, 130 const CompletionCallback& callback,
137 IOBuffer* buf) { 131 IOBuffer* buf) {
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
241 235
242 IOResult error = IOResult::FromOSError(os_error); 236 IOResult error = IOResult::FromOSError(os_error);
243 if (error.os_error == ERROR_IO_PENDING) { 237 if (error.os_error == ERROR_IO_PENDING) {
244 InvokeUserCallback(); 238 InvokeUserCallback();
245 } else { 239 } else {
246 OnIOCompleted(&io_context_, 0, error.os_error); 240 OnIOCompleted(&io_context_, 0, error.os_error);
247 } 241 }
248 } 242 }
249 243
250 } // namespace net 244 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698