| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/disk_cache/file.h" | 5 #include "net/disk_cache/file.h" |
| 6 | 6 |
| 7 #include "base/file_path.h" | 7 #include "base/file_path.h" |
| 8 #include "base/lazy_instance.h" | 8 #include "base/lazy_instance.h" |
| 9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
| 10 #include "net/base/net_errors.h" | 10 #include "net/base/net_errors.h" |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 }; | 27 }; |
| 28 | 28 |
| 29 COMPILE_ASSERT(!offsetof(MyOverlapped, context_), starts_with_overlapped); | 29 COMPILE_ASSERT(!offsetof(MyOverlapped, context_), starts_with_overlapped); |
| 30 | 30 |
| 31 // Helper class to handle the IO completion notifications from the message loop. | 31 // Helper class to handle the IO completion notifications from the message loop. |
| 32 class CompletionHandler : public MessageLoopForIO::IOHandler { | 32 class CompletionHandler : public MessageLoopForIO::IOHandler { |
| 33 virtual void OnIOCompleted(MessageLoopForIO::IOContext* context, | 33 virtual void OnIOCompleted(MessageLoopForIO::IOContext* context, |
| 34 DWORD actual_bytes, DWORD error); | 34 DWORD actual_bytes, DWORD error); |
| 35 }; | 35 }; |
| 36 | 36 |
| 37 static base::LazyInstance<CompletionHandler> g_completion_handler( | 37 static base::LazyInstance<CompletionHandler> g_completion_handler = |
| 38 base::LINKER_INITIALIZED); | 38 LAZY_INSTANCE_INITIALIZER; |
| 39 | 39 |
| 40 void CompletionHandler::OnIOCompleted(MessageLoopForIO::IOContext* context, | 40 void CompletionHandler::OnIOCompleted(MessageLoopForIO::IOContext* context, |
| 41 DWORD actual_bytes, DWORD error) { | 41 DWORD actual_bytes, DWORD error) { |
| 42 MyOverlapped* data = reinterpret_cast<MyOverlapped*>(context); | 42 MyOverlapped* data = reinterpret_cast<MyOverlapped*>(context); |
| 43 | 43 |
| 44 if (error) { | 44 if (error) { |
| 45 DCHECK(!actual_bytes); | 45 DCHECK(!actual_bytes); |
| 46 actual_bytes = static_cast<DWORD>(net::ERR_CACHE_READ_FAILURE); | 46 actual_bytes = static_cast<DWORD>(net::ERR_CACHE_READ_FAILURE); |
| 47 NOTREACHED(); | 47 NOTREACHED(); |
| 48 } | 48 } |
| (...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 258 void File::WaitForPendingIO(int* num_pending_io) { | 258 void File::WaitForPendingIO(int* num_pending_io) { |
| 259 while (*num_pending_io) { | 259 while (*num_pending_io) { |
| 260 // Asynchronous IO operations may be in flight and the completion may end | 260 // Asynchronous IO operations may be in flight and the completion may end |
| 261 // up calling us back so let's wait for them. | 261 // up calling us back so let's wait for them. |
| 262 MessageLoopForIO::IOHandler* handler = g_completion_handler.Pointer(); | 262 MessageLoopForIO::IOHandler* handler = g_completion_handler.Pointer(); |
| 263 MessageLoopForIO::current()->WaitForIOCompletion(100, handler); | 263 MessageLoopForIO::current()->WaitForIOCompletion(100, handler); |
| 264 } | 264 } |
| 265 } | 265 } |
| 266 | 266 |
| 267 } // namespace disk_cache | 267 } // namespace disk_cache |
| OLD | NEW |