OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "webkit/database/vfs_backend.h" | 5 #include "webkit/database/vfs_backend.h" |
6 | 6 |
7 #include "base/file_path.h" | 7 #include "base/file_path.h" |
8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "third_party/sqlite/sqlite3.h" | 10 #include "third_party/sqlite/sqlite3.h" |
11 | 11 |
12 namespace webkit_database { | 12 namespace webkit_database { |
13 | 13 |
14 static const int kFileTypeMask = 0x00007F00; | 14 static const int kFileTypeMask = 0x00007F00; |
15 | 15 |
16 // static | 16 // static |
17 void VfsBackend::GetFileHandleForProcess(base::ProcessHandle process_handle, | |
18 const base::PlatformFile& file_handle, | |
19 base::PlatformFile* target_handle, | |
20 bool close_source_handle) { | |
21 if (file_handle == base::kInvalidPlatformFileValue) { | |
22 *target_handle = base::kInvalidPlatformFileValue; | |
23 return; | |
24 } | |
25 | |
26 #if defined(OS_WIN) | |
27 // Duplicate the file handle. | |
28 if (!DuplicateHandle(GetCurrentProcess(), file_handle, | |
29 process_handle, target_handle, 0, false, | |
30 DUPLICATE_SAME_ACCESS | | |
31 (close_source_handle ? DUPLICATE_CLOSE_SOURCE : 0))) { | |
32 // file_handle is closed whether or not DuplicateHandle succeeds. | |
33 *target_handle = INVALID_HANDLE_VALUE; | |
34 } | |
35 #elif defined(OS_POSIX) | |
36 *target_handle = file_handle; | |
37 #endif | |
38 } | |
39 | |
40 // static | |
41 bool VfsBackend::FileTypeIsMainDB(int desired_flags) { | 17 bool VfsBackend::FileTypeIsMainDB(int desired_flags) { |
42 return (desired_flags & kFileTypeMask) == SQLITE_OPEN_MAIN_DB; | 18 return (desired_flags & kFileTypeMask) == SQLITE_OPEN_MAIN_DB; |
43 } | 19 } |
44 | 20 |
45 // static | 21 // static |
46 bool VfsBackend::FileTypeIsJournal(int desired_flags) { | 22 bool VfsBackend::FileTypeIsJournal(int desired_flags) { |
47 int file_type = desired_flags & kFileTypeMask; | 23 int file_type = desired_flags & kFileTypeMask; |
48 return ((file_type == SQLITE_OPEN_MAIN_JOURNAL) || | 24 return ((file_type == SQLITE_OPEN_MAIN_JOURNAL) || |
49 (file_type == SQLITE_OPEN_TEMP_JOURNAL) || | 25 (file_type == SQLITE_OPEN_TEMP_JOURNAL) || |
50 (file_type == SQLITE_OPEN_SUBJOURNAL) || | 26 (file_type == SQLITE_OPEN_SUBJOURNAL) || |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
192 return attributes; | 168 return attributes; |
193 } | 169 } |
194 | 170 |
195 // static | 171 // static |
196 int64 VfsBackend::GetFileSize(const FilePath& file_path) { | 172 int64 VfsBackend::GetFileSize(const FilePath& file_path) { |
197 int64 size = 0; | 173 int64 size = 0; |
198 return (file_util::GetFileSize(file_path, &size) ? size : 0); | 174 return (file_util::GetFileSize(file_path, &size) ? size : 0); |
199 } | 175 } |
200 | 176 |
201 } // namespace webkit_database | 177 } // namespace webkit_database |
OLD | NEW |