OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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/message_loop.h" | 8 #include "base/message_loop.h" |
8 #include "base/singleton.h" | 9 #include "base/singleton.h" |
9 #include "net/disk_cache/disk_cache.h" | 10 #include "net/disk_cache/disk_cache.h" |
10 | 11 |
11 namespace { | 12 namespace { |
12 | 13 |
13 // Structure used for asynchronous operations. | 14 // Structure used for asynchronous operations. |
14 struct MyOverlapped { | 15 struct MyOverlapped { |
15 MyOverlapped(disk_cache::File* file, size_t offset, | 16 MyOverlapped(disk_cache::File* file, size_t offset, |
16 disk_cache::FileIOCallback* callback); | 17 disk_cache::FileIOCallback* callback); |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 | 71 |
71 } // namespace | 72 } // namespace |
72 | 73 |
73 namespace disk_cache { | 74 namespace disk_cache { |
74 | 75 |
75 File::File(base::PlatformFile file) | 76 File::File(base::PlatformFile file) |
76 : init_(true), mixed_(true), platform_file_(INVALID_HANDLE_VALUE), | 77 : init_(true), mixed_(true), platform_file_(INVALID_HANDLE_VALUE), |
77 sync_platform_file_(file) { | 78 sync_platform_file_(file) { |
78 } | 79 } |
79 | 80 |
80 bool File::Init(const std::wstring& name) { | 81 bool File::Init(const FilePath& name) { |
81 DCHECK(!init_); | 82 DCHECK(!init_); |
82 if (init_) | 83 if (init_) |
83 return false; | 84 return false; |
84 | 85 |
85 platform_file_ = CreateFile(name.c_str(), GENERIC_READ | GENERIC_WRITE, | 86 platform_file_ = CreateFile(name.value().c_str(), |
| 87 GENERIC_READ | GENERIC_WRITE, |
86 FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, | 88 FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, |
87 OPEN_EXISTING, FILE_FLAG_OVERLAPPED, NULL); | 89 OPEN_EXISTING, FILE_FLAG_OVERLAPPED, NULL); |
88 | 90 |
89 if (INVALID_HANDLE_VALUE == platform_file_) | 91 if (INVALID_HANDLE_VALUE == platform_file_) |
90 return false; | 92 return false; |
91 | 93 |
92 MessageLoopForIO::current()->RegisterIOHandler( | 94 MessageLoopForIO::current()->RegisterIOHandler( |
93 platform_file_, Singleton<CompletionHandler>::get()); | 95 platform_file_, Singleton<CompletionHandler>::get()); |
94 | 96 |
95 init_ = true; | 97 init_ = true; |
96 sync_platform_file_ = CreateFile(name.c_str(), GENERIC_READ | GENERIC_WRITE, | 98 sync_platform_file_ = CreateFile(name.value().c_str(), |
| 99 GENERIC_READ | GENERIC_WRITE, |
97 FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, | 100 FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, |
98 OPEN_EXISTING, 0, NULL); | 101 OPEN_EXISTING, 0, NULL); |
99 | 102 |
100 if (INVALID_HANDLE_VALUE == sync_platform_file_) | 103 if (INVALID_HANDLE_VALUE == sync_platform_file_) |
101 return false; | 104 return false; |
102 | 105 |
103 return true; | 106 return true; |
104 } | 107 } |
105 | 108 |
106 File::~File() { | 109 File::~File() { |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
275 void File::WaitForPendingIO(int* num_pending_io) { | 278 void File::WaitForPendingIO(int* num_pending_io) { |
276 while (*num_pending_io) { | 279 while (*num_pending_io) { |
277 // Asynchronous IO operations may be in flight and the completion may end | 280 // Asynchronous IO operations may be in flight and the completion may end |
278 // up calling us back so let's wait for them. | 281 // up calling us back so let's wait for them. |
279 MessageLoopForIO::IOHandler* handler = Singleton<CompletionHandler>::get(); | 282 MessageLoopForIO::IOHandler* handler = Singleton<CompletionHandler>::get(); |
280 MessageLoopForIO::current()->WaitForIOCompletion(100, handler); | 283 MessageLoopForIO::current()->WaitForIOCompletion(100, handler); |
281 } | 284 } |
282 } | 285 } |
283 | 286 |
284 } // namespace disk_cache | 287 } // namespace disk_cache |
OLD | NEW |