OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "storage/browser/fileapi/sandbox_prioritized_origin_database.h" | 5 #include "storage/browser/fileapi/sandbox_prioritized_origin_database.h" |
6 | 6 |
7 #include "base/files/file.h" | 7 #include "base/files/file.h" |
8 #include "base/files/file_util.h" | 8 #include "base/files/file_util.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/pickle.h" | 10 #include "base/pickle.h" |
(...skipping 12 matching lines...) Expand all Loading... |
23 | 23 |
24 namespace { | 24 namespace { |
25 | 25 |
26 bool WritePrimaryOriginFile(const base::FilePath& path, | 26 bool WritePrimaryOriginFile(const base::FilePath& path, |
27 const std::string& origin) { | 27 const std::string& origin) { |
28 base::File file(path, base::File::FLAG_OPEN_ALWAYS | base::File::FLAG_WRITE); | 28 base::File file(path, base::File::FLAG_OPEN_ALWAYS | base::File::FLAG_WRITE); |
29 if (!file.IsValid()) | 29 if (!file.IsValid()) |
30 return false; | 30 return false; |
31 if (!file.created()) | 31 if (!file.created()) |
32 file.SetLength(0); | 32 file.SetLength(0); |
33 Pickle pickle; | 33 base::Pickle pickle; |
34 pickle.WriteString(origin); | 34 pickle.WriteString(origin); |
35 file.Write(0, static_cast<const char*>(pickle.data()), pickle.size()); | 35 file.Write(0, static_cast<const char*>(pickle.data()), pickle.size()); |
36 file.Flush(); | 36 file.Flush(); |
37 return true; | 37 return true; |
38 } | 38 } |
39 | 39 |
40 bool ReadPrimaryOriginFile(const base::FilePath& path, | 40 bool ReadPrimaryOriginFile(const base::FilePath& path, |
41 std::string* origin) { | 41 std::string* origin) { |
42 std::string buffer; | 42 std::string buffer; |
43 if (!base::ReadFileToString(path, &buffer)) | 43 if (!base::ReadFileToString(path, &buffer)) |
44 return false; | 44 return false; |
45 Pickle pickle(buffer.data(), buffer.size()); | 45 base::Pickle pickle(buffer.data(), buffer.size()); |
46 PickleIterator iter(pickle); | 46 base::PickleIterator iter(pickle); |
47 return iter.ReadString(origin) && !origin->empty(); | 47 return iter.ReadString(origin) && !origin->empty(); |
48 } | 48 } |
49 | 49 |
50 } // namespace | 50 } // namespace |
51 | 51 |
52 SandboxPrioritizedOriginDatabase::SandboxPrioritizedOriginDatabase( | 52 SandboxPrioritizedOriginDatabase::SandboxPrioritizedOriginDatabase( |
53 const base::FilePath& file_system_directory, | 53 const base::FilePath& file_system_directory, |
54 leveldb::Env* env_override) | 54 leveldb::Env* env_override) |
55 : file_system_directory_(file_system_directory), | 55 : file_system_directory_(file_system_directory), |
56 env_override_(env_override), | 56 env_override_(env_override), |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
216 } | 216 } |
217 } | 217 } |
218 | 218 |
219 SandboxOriginDatabase* | 219 SandboxOriginDatabase* |
220 SandboxPrioritizedOriginDatabase::GetSandboxOriginDatabase() { | 220 SandboxPrioritizedOriginDatabase::GetSandboxOriginDatabase() { |
221 MaybeInitializeNonPrimaryDatabase(true); | 221 MaybeInitializeNonPrimaryDatabase(true); |
222 return origin_database_.get(); | 222 return origin_database_.get(); |
223 } | 223 } |
224 | 224 |
225 } // namespace storage | 225 } // namespace storage |
OLD | NEW |