OLD | NEW |
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 "webkit/browser/fileapi/sandbox_directory_database.h" | 5 #include "webkit/browser/fileapi/sandbox_directory_database.h" |
6 | 6 |
7 #include <math.h> | 7 #include <math.h> |
8 #include <limits> | 8 #include <limits> |
9 | 9 |
10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
76 FileId file_id; | 76 FileId file_id; |
77 | 77 |
78 FileInfo info; | 78 FileInfo info; |
79 info.parent_id = parent_id; | 79 info.parent_id = parent_id; |
80 info.name = name; | 80 info.name = name; |
81 info.data_path = base::FilePath(data_path).NormalizePathSeparators(); | 81 info.data_path = base::FilePath(data_path).NormalizePathSeparators(); |
82 ASSERT_EQ(base::PLATFORM_FILE_OK, db_->AddFileInfo(info, &file_id)); | 82 ASSERT_EQ(base::PLATFORM_FILE_OK, db_->AddFileInfo(info, &file_id)); |
83 | 83 |
84 base::FilePath local_path = path().Append(data_path); | 84 base::FilePath local_path = path().Append(data_path); |
85 if (!base::DirectoryExists(local_path.DirName())) | 85 if (!base::DirectoryExists(local_path.DirName())) |
86 ASSERT_TRUE(file_util::CreateDirectory(local_path.DirName())); | 86 ASSERT_TRUE(base::CreateDirectory(local_path.DirName())); |
87 | 87 |
88 bool created = false; | 88 bool created = false; |
89 base::PlatformFileError error = base::PLATFORM_FILE_ERROR_FAILED; | 89 base::PlatformFileError error = base::PLATFORM_FILE_ERROR_FAILED; |
90 base::PlatformFile file = base::CreatePlatformFile( | 90 base::PlatformFile file = base::CreatePlatformFile( |
91 local_path, | 91 local_path, |
92 base::PLATFORM_FILE_CREATE | base::PLATFORM_FILE_WRITE, | 92 base::PLATFORM_FILE_CREATE | base::PLATFORM_FILE_WRITE, |
93 &created, &error); | 93 &created, &error); |
94 ASSERT_EQ(base::PLATFORM_FILE_OK, error); | 94 ASSERT_EQ(base::PLATFORM_FILE_OK, error); |
95 ASSERT_TRUE(created); | 95 ASSERT_TRUE(created); |
96 ASSERT_TRUE(base::ClosePlatformFile(file)); | 96 ASSERT_TRUE(base::ClosePlatformFile(file)); |
97 | 97 |
98 if (file_id_out) | 98 if (file_id_out) |
99 *file_id_out = file_id; | 99 *file_id_out = file_id; |
100 } | 100 } |
101 | 101 |
102 void ClearDatabaseAndDirectory() { | 102 void ClearDatabaseAndDirectory() { |
103 db_.reset(); | 103 db_.reset(); |
104 ASSERT_TRUE(base::DeleteFile(path(), true /* recursive */)); | 104 ASSERT_TRUE(base::DeleteFile(path(), true /* recursive */)); |
105 ASSERT_TRUE(file_util::CreateDirectory(path())); | 105 ASSERT_TRUE(base::CreateDirectory(path())); |
106 db_.reset(new SandboxDirectoryDatabase(path())); | 106 db_.reset(new SandboxDirectoryDatabase(path())); |
107 } | 107 } |
108 | 108 |
109 bool RepairDatabase() { | 109 bool RepairDatabase() { |
110 return db()->RepairDatabase( | 110 return db()->RepairDatabase( |
111 FilePathToString(path().Append(kDirectoryDatabaseName))); | 111 FilePathToString(path().Append(kDirectoryDatabaseName))); |
112 } | 112 } |
113 | 113 |
114 const base::FilePath& path() { | 114 const base::FilePath& path() { |
115 return base_.path(); | 115 return base_.path(); |
(...skipping 556 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
672 EXPECT_FALSE(db()->IsFileSystemConsistent()); | 672 EXPECT_FALSE(db()->IsFileSystemConsistent()); |
673 | 673 |
674 FileId file_id; | 674 FileId file_id; |
675 EXPECT_TRUE(db()->GetChildWithName(0, kFileName, &file_id)); | 675 EXPECT_TRUE(db()->GetChildWithName(0, kFileName, &file_id)); |
676 EXPECT_EQ(file_id_prev, file_id); | 676 EXPECT_EQ(file_id_prev, file_id); |
677 | 677 |
678 EXPECT_TRUE(db()->IsFileSystemConsistent()); | 678 EXPECT_TRUE(db()->IsFileSystemConsistent()); |
679 } | 679 } |
680 | 680 |
681 } // namespace fileapi | 681 } // namespace fileapi |
OLD | NEW |