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/os_file.h" | 5 #include "base/platform_file.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 | 8 |
9 namespace disk_cache { | 9 namespace base { |
10 | 10 |
11 OSFile CreateOSFile(const std::wstring& name, int flags, bool* created) { | 11 PlatformFile CreatePlatformFile(const std::wstring& name, |
| 12 int flags, |
| 13 bool* created) { |
12 DWORD disposition = 0; | 14 DWORD disposition = 0; |
13 | 15 |
14 if (flags & OS_FILE_OPEN) | 16 if (flags & PLATFORM_FILE_OPEN) |
15 disposition = OPEN_EXISTING; | 17 disposition = OPEN_EXISTING; |
16 | 18 |
17 if (flags & OS_FILE_CREATE) { | 19 if (flags & PLATFORM_FILE_CREATE) { |
18 DCHECK(!disposition); | 20 DCHECK(!disposition); |
19 disposition = CREATE_NEW; | 21 disposition = CREATE_NEW; |
20 } | 22 } |
21 | 23 |
22 if (flags & OS_FILE_OPEN_ALWAYS) { | 24 if (flags & PLATFORM_FILE_OPEN_ALWAYS) { |
23 DCHECK(!disposition); | 25 DCHECK(!disposition); |
24 disposition = OPEN_ALWAYS; | 26 disposition = OPEN_ALWAYS; |
25 } | 27 } |
26 | 28 |
27 if (flags & OS_FILE_CREATE_ALWAYS) { | 29 if (flags & PLATFORM_FILE_CREATE_ALWAYS) { |
28 DCHECK(!disposition); | 30 DCHECK(!disposition); |
29 disposition = CREATE_ALWAYS; | 31 disposition = CREATE_ALWAYS; |
30 } | 32 } |
31 | 33 |
32 if (!disposition) { | 34 if (!disposition) { |
33 NOTREACHED(); | 35 NOTREACHED(); |
34 return NULL; | 36 return NULL; |
35 } | 37 } |
36 | 38 |
37 DWORD access = (flags & OS_FILE_READ) ? GENERIC_READ : 0; | 39 DWORD access = (flags & PLATFORM_FILE_READ) ? GENERIC_READ : 0; |
38 if (flags & OS_FILE_WRITE) | 40 if (flags & PLATFORM_FILE_WRITE) |
39 access |= GENERIC_WRITE; | 41 access |= GENERIC_WRITE; |
40 | 42 |
41 DWORD sharing = (flags & OS_FILE_SHARE_READ) ? FILE_SHARE_READ : 0; | 43 DWORD sharing = (flags & PLATFORM_FILE_EXCLUSIVE_READ) ? 0 : FILE_SHARE_READ; |
42 if (flags & OS_FILE_SHARE_WRITE) | 44 if (!(flags & PLATFORM_FILE_EXCLUSIVE_WRITE)) |
43 access |= FILE_SHARE_WRITE; | 45 sharing |= FILE_SHARE_WRITE; |
44 | 46 |
45 HANDLE file = CreateFile(name.c_str(), access, sharing, NULL, disposition, 0, | 47 DWORD create_flags = 0; |
46 NULL); | 48 if (flags & PLATFORM_FILE_ASYNC) |
| 49 create_flags |= FILE_FLAG_OVERLAPPED; |
47 | 50 |
48 if ((flags & OS_FILE_OPEN_ALWAYS) && created && | 51 HANDLE file = CreateFile(name.c_str(), access, sharing, NULL, disposition, |
| 52 create_flags, NULL); |
| 53 |
| 54 if ((flags & PLATFORM_FILE_OPEN_ALWAYS) && created && |
49 INVALID_HANDLE_VALUE != file) { | 55 INVALID_HANDLE_VALUE != file) { |
50 *created = (ERROR_ALREADY_EXISTS != GetLastError()); | 56 *created = (ERROR_ALREADY_EXISTS != GetLastError()); |
51 } | 57 } |
52 | 58 |
53 return file; | 59 return file; |
54 } | 60 } |
55 | 61 |
56 } // namespace disk_cache | 62 } // namespace disk_cache |
57 | 63 |
OLD | NEW |