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

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

Issue 10548028: NetLogEventParameter to Callback refactoring 8. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Fix bad paste Created 8 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | net/base/host_resolver_impl.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.h" 5 #include "net/base/file_stream.h"
6 6
7 #include <windows.h> 7 #include <windows.h>
8 8
9 #include "base/file_path.h" 9 #include "base/file_path.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 NetLog::StringCallback("file_name", &file_name)); 70 NetLog::StringCallback("file_name", &file_name));
71 71
72 *file = base::CreatePlatformFile(path, open_flags, NULL, NULL); 72 *file = base::CreatePlatformFile(path, open_flags, NULL, NULL);
73 if (*file == base::kInvalidPlatformFileValue) { 73 if (*file == base::kInvalidPlatformFileValue) {
74 DWORD error = GetLastError(); 74 DWORD error = GetLastError();
75 LOG(WARNING) << "Failed to open file: " << error; 75 LOG(WARNING) << "Failed to open file: " << error;
76 *result = RecordAndMapError(error, 76 *result = RecordAndMapError(error,
77 FILE_ERROR_SOURCE_OPEN, 77 FILE_ERROR_SOURCE_OPEN,
78 record_uma, 78 record_uma,
79 bound_net_log); 79 bound_net_log);
80 bound_net_log.EndEvent(net::NetLog::TYPE_FILE_STREAM_OPEN, NULL); 80 bound_net_log.EndEvent(net::NetLog::TYPE_FILE_STREAM_OPEN);
81 return; 81 return;
82 } 82 }
83 } 83 }
84 84
85 // Closes a file with some network logging. 85 // Closes a file with some network logging.
86 void CloseFile(base::PlatformFile file, 86 void CloseFile(base::PlatformFile file,
87 const net::BoundNetLog& bound_net_log) { 87 const net::BoundNetLog& bound_net_log) {
88 bound_net_log.AddEvent(net::NetLog::TYPE_FILE_STREAM_CLOSE, NULL); 88 bound_net_log.AddEvent(net::NetLog::TYPE_FILE_STREAM_CLOSE);
89 if (file == base::kInvalidPlatformFileValue) 89 if (file == base::kInvalidPlatformFileValue)
90 return; 90 return;
91 91
92 CancelIo(file); 92 CancelIo(file);
93 93
94 if (!base::ClosePlatformFile(file)) 94 if (!base::ClosePlatformFile(file))
95 NOTREACHED(); 95 NOTREACHED();
96 bound_net_log.EndEvent(net::NetLog::TYPE_FILE_STREAM_OPEN, NULL); 96 bound_net_log.EndEvent(net::NetLog::TYPE_FILE_STREAM_OPEN);
97 } 97 }
98 98
99 // Closes a file with CloseFile() and signals the completion. 99 // Closes a file with CloseFile() and signals the completion.
100 void CloseFileAndSignal(base::PlatformFile* file, 100 void CloseFileAndSignal(base::PlatformFile* file,
101 base::WaitableEvent* on_io_complete, 101 base::WaitableEvent* on_io_complete,
102 const net::BoundNetLog& bound_net_log) { 102 const net::BoundNetLog& bound_net_log) {
103 CloseFile(*file, bound_net_log); 103 CloseFile(*file, bound_net_log);
104 *file = base::kInvalidPlatformFileValue; 104 *file = base::kInvalidPlatformFileValue;
105 on_io_complete->Signal(); 105 on_io_complete->Signal();
106 } 106 }
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 // FileStream ------------------------------------------------------------ 204 // FileStream ------------------------------------------------------------
205 205
206 FileStreamWin::FileStreamWin(net::NetLog* net_log) 206 FileStreamWin::FileStreamWin(net::NetLog* net_log)
207 : file_(base::kInvalidPlatformFileValue), 207 : file_(base::kInvalidPlatformFileValue),
208 open_flags_(0), 208 open_flags_(0),
209 auto_closed_(true), 209 auto_closed_(true),
210 record_uma_(false), 210 record_uma_(false),
211 bound_net_log_(net::BoundNetLog::Make(net_log, 211 bound_net_log_(net::BoundNetLog::Make(net_log,
212 net::NetLog::SOURCE_FILESTREAM)), 212 net::NetLog::SOURCE_FILESTREAM)),
213 weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { 213 weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) {
214 bound_net_log_.BeginEvent(net::NetLog::TYPE_FILE_STREAM_ALIVE, NULL); 214 bound_net_log_.BeginEvent(net::NetLog::TYPE_FILE_STREAM_ALIVE);
215 } 215 }
216 216
217 FileStreamWin::FileStreamWin( 217 FileStreamWin::FileStreamWin(
218 base::PlatformFile file, int flags, net::NetLog* net_log) 218 base::PlatformFile file, int flags, net::NetLog* net_log)
219 : file_(file), 219 : file_(file),
220 open_flags_(flags), 220 open_flags_(flags),
221 auto_closed_(false), 221 auto_closed_(false),
222 record_uma_(false), 222 record_uma_(false),
223 bound_net_log_(net::BoundNetLog::Make(net_log, 223 bound_net_log_(net::BoundNetLog::Make(net_log,
224 net::NetLog::SOURCE_FILESTREAM)), 224 net::NetLog::SOURCE_FILESTREAM)),
225 weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { 225 weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) {
226 bound_net_log_.BeginEvent(net::NetLog::TYPE_FILE_STREAM_ALIVE, NULL); 226 bound_net_log_.BeginEvent(net::NetLog::TYPE_FILE_STREAM_ALIVE);
227 227
228 // If the file handle is opened with base::PLATFORM_FILE_ASYNC, we need to 228 // If the file handle is opened with base::PLATFORM_FILE_ASYNC, we need to
229 // make sure we will perform asynchronous File IO to it. 229 // make sure we will perform asynchronous File IO to it.
230 if (flags & base::PLATFORM_FILE_ASYNC) { 230 if (flags & base::PLATFORM_FILE_ASYNC) {
231 async_context_.reset(new AsyncContext(bound_net_log_)); 231 async_context_.reset(new AsyncContext(bound_net_log_));
232 MessageLoopForIO::current()->RegisterIOHandler(file_, 232 MessageLoopForIO::current()->RegisterIOHandler(file_,
233 async_context_.get()); 233 async_context_.get());
234 } 234 }
235 } 235 }
236 236
(...skipping 15 matching lines...) Expand all
252 FROM_HERE, 252 FROM_HERE,
253 base::Bind(&CloseFile, file_, bound_net_log_), 253 base::Bind(&CloseFile, file_, bound_net_log_),
254 true /* task_is_slow */); 254 true /* task_is_slow */);
255 DCHECK(posted); 255 DCHECK(posted);
256 } 256 }
257 } else { 257 } else {
258 CloseSync(); 258 CloseSync();
259 } 259 }
260 } 260 }
261 261
262 bound_net_log_.EndEvent(net::NetLog::TYPE_FILE_STREAM_ALIVE, NULL); 262 bound_net_log_.EndEvent(net::NetLog::TYPE_FILE_STREAM_ALIVE);
263 } 263 }
264 264
265 void FileStreamWin::Close(const CompletionCallback& callback) { 265 void FileStreamWin::Close(const CompletionCallback& callback) {
266 DCHECK(open_flags_ & base::PLATFORM_FILE_ASYNC); 266 DCHECK(open_flags_ & base::PLATFORM_FILE_ASYNC);
267 DCHECK(!weak_ptr_factory_.HasWeakPtrs()); 267 DCHECK(!weak_ptr_factory_.HasWeakPtrs());
268 DCHECK(!on_io_complete_.get()); 268 DCHECK(!on_io_complete_.get());
269 on_io_complete_.reset(new base::WaitableEvent( 269 on_io_complete_.reset(new base::WaitableEvent(
270 false /* manual_reset */, false /* initially_signaled */)); 270 false /* manual_reset */, false /* initially_signaled */));
271 271
272 // Passing &file_ to a thread pool looks unsafe but it's safe here as the 272 // Passing &file_ to a thread pool looks unsafe but it's safe here as the
(...skipping 12 matching lines...) Expand all
285 285
286 void FileStreamWin::CloseSync() { 286 void FileStreamWin::CloseSync() {
287 // The logic here is similar to CloseFile() but async_context_.reset() is 287 // The logic here is similar to CloseFile() but async_context_.reset() is
288 // caled in this function. 288 // caled in this function.
289 289
290 // Block until the in-flight open operation is complete. 290 // Block until the in-flight open operation is complete.
291 // TODO(satorux): Replace this with a DCHECK(open_flags & ASYNC) once this 291 // TODO(satorux): Replace this with a DCHECK(open_flags & ASYNC) once this
292 // once all async clients are migrated to use Close(). crbug.com/114783 292 // once all async clients are migrated to use Close(). crbug.com/114783
293 WaitForIOCompletion(); 293 WaitForIOCompletion();
294 294
295 bound_net_log_.AddEvent(net::NetLog::TYPE_FILE_STREAM_CLOSE, NULL); 295 bound_net_log_.AddEvent(net::NetLog::TYPE_FILE_STREAM_CLOSE);
296 if (file_ != base::kInvalidPlatformFileValue) 296 if (file_ != base::kInvalidPlatformFileValue)
297 CancelIo(file_); 297 CancelIo(file_);
298 298
299 // Block until the last read/write operation is complete. 299 // Block until the last read/write operation is complete.
300 async_context_.reset(); 300 async_context_.reset();
301 301
302 if (file_ != base::kInvalidPlatformFileValue) { 302 if (file_ != base::kInvalidPlatformFileValue) {
303 if (!base::ClosePlatformFile(file_)) 303 if (!base::ClosePlatformFile(file_))
304 NOTREACHED(); 304 NOTREACHED();
305 file_ = base::kInvalidPlatformFileValue; 305 file_ = base::kInvalidPlatformFileValue;
306 306
307 bound_net_log_.EndEvent(net::NetLog::TYPE_FILE_STREAM_OPEN, NULL); 307 bound_net_log_.EndEvent(net::NetLog::TYPE_FILE_STREAM_OPEN);
308 } 308 }
309 } 309 }
310 310
311 int FileStreamWin::Open(const FilePath& path, int open_flags, 311 int FileStreamWin::Open(const FilePath& path, int open_flags,
312 const CompletionCallback& callback) { 312 const CompletionCallback& callback) {
313 if (IsOpen()) { 313 if (IsOpen()) {
314 DLOG(FATAL) << "File is already open!"; 314 DLOG(FATAL) << "File is already open!";
315 return ERR_UNEXPECTED; 315 return ERR_UNEXPECTED;
316 } 316 }
317 317
(...skipping 404 matching lines...) Expand 10 before | Expand all | Expand 10 after
722 void FileStreamWin::WaitForIOCompletion() { 722 void FileStreamWin::WaitForIOCompletion() {
723 // http://crbug.com/115067 723 // http://crbug.com/115067
724 base::ThreadRestrictions::ScopedAllowWait allow_wait; 724 base::ThreadRestrictions::ScopedAllowWait allow_wait;
725 if (on_io_complete_.get()) { 725 if (on_io_complete_.get()) {
726 on_io_complete_->Wait(); 726 on_io_complete_->Wait();
727 on_io_complete_.reset(); 727 on_io_complete_.reset();
728 } 728 }
729 } 729 }
730 730
731 } // namespace net 731 } // namespace net
OLDNEW
« no previous file with comments | « no previous file | net/base/host_resolver_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698