OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/fileapi/file_system_origin_database.h" | 5 #include "webkit/fileapi/file_system_origin_database.h" |
6 | 6 |
| 7 #include "base/format_macros.h" |
7 #include "base/logging.h" | 8 #include "base/logging.h" |
8 #include "base/string_number_conversions.h" | 9 #include "base/string_number_conversions.h" |
| 10 #include "base/stringprintf.h" |
9 #include "base/string_util.h" | 11 #include "base/string_util.h" |
10 #include "base/sys_string_conversions.h" | 12 #include "base/sys_string_conversions.h" |
11 #include "third_party/leveldb/include/leveldb/iterator.h" | 13 #include "third_party/leveldb/include/leveldb/iterator.h" |
12 #include "third_party/leveldb/include/leveldb/write_batch.h" | 14 #include "third_party/leveldb/include/leveldb/write_batch.h" |
13 | 15 |
14 namespace { | 16 namespace { |
15 | 17 |
16 const char kOriginKeyPrefix[] = "ORIGIN:"; | 18 const char kOriginKeyPrefix[] = "ORIGIN:"; |
17 const char kLastPathKey[] = "LAST_PATH"; | 19 const char kLastPathKey[] = "LAST_PATH"; |
18 | 20 |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 if (origin.empty()) | 88 if (origin.empty()) |
87 return false; | 89 return false; |
88 std::string path_string; | 90 std::string path_string; |
89 std::string origin_key = OriginToOriginKey(origin); | 91 std::string origin_key = OriginToOriginKey(origin); |
90 leveldb::Status status = | 92 leveldb::Status status = |
91 db_->Get(leveldb::ReadOptions(), origin_key, &path_string); | 93 db_->Get(leveldb::ReadOptions(), origin_key, &path_string); |
92 if (status.IsNotFound()) { | 94 if (status.IsNotFound()) { |
93 int last_path_number; | 95 int last_path_number; |
94 if (!GetLastPathNumber(&last_path_number)) | 96 if (!GetLastPathNumber(&last_path_number)) |
95 return false; | 97 return false; |
96 path_string = base::IntToString(last_path_number + 1); | 98 path_string = StringPrintf("%03u", last_path_number + 1); |
97 // store both back as a single transaction | 99 // store both back as a single transaction |
98 leveldb::WriteBatch batch; | 100 leveldb::WriteBatch batch; |
99 batch.Put(LastPathKey(), path_string); | 101 batch.Put(LastPathKey(), path_string); |
100 batch.Put(origin_key, path_string); | 102 batch.Put(origin_key, path_string); |
101 status = db_->Write(leveldb::WriteOptions(), &batch); | 103 status = db_->Write(leveldb::WriteOptions(), &batch); |
102 if (!status.ok()) { | 104 if (!status.ok()) { |
103 HandleError(status); | 105 HandleError(status); |
104 return false; | 106 return false; |
105 } | 107 } |
106 } | 108 } |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
181 db_->Put(leveldb::WriteOptions(), LastPathKey(), std::string("-1")); | 183 db_->Put(leveldb::WriteOptions(), LastPathKey(), std::string("-1")); |
182 if (!status.ok()) { | 184 if (!status.ok()) { |
183 HandleError(status); | 185 HandleError(status); |
184 return false; | 186 return false; |
185 } | 187 } |
186 *number = -1; | 188 *number = -1; |
187 return true; | 189 return true; |
188 } | 190 } |
189 | 191 |
190 } // namespace fileapi | 192 } // namespace fileapi |
OLD | NEW |