OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 "content/browser/indexed_db/leveldb/leveldb_database.h" | 5 #include "content/browser/indexed_db/leveldb/leveldb_database.h" |
6 | 6 |
| 7 #include <stdint.h> |
| 8 |
7 #include <cerrno> | 9 #include <cerrno> |
8 | 10 |
9 #include "base/basictypes.h" | |
10 #include "base/files/file.h" | 11 #include "base/files/file.h" |
11 #include "base/logging.h" | 12 #include "base/logging.h" |
| 13 #include "base/macros.h" |
12 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
13 #include "base/metrics/histogram.h" | 15 #include "base/metrics/histogram.h" |
14 #include "base/strings/string16.h" | 16 #include "base/strings/string16.h" |
15 #include "base/strings/string_piece.h" | 17 #include "base/strings/string_piece.h" |
16 #include "base/strings/stringprintf.h" | 18 #include "base/strings/stringprintf.h" |
17 #include "base/strings/utf_string_conversions.h" | 19 #include "base/strings/utf_string_conversions.h" |
18 #include "base/sys_info.h" | 20 #include "base/sys_info.h" |
| 21 #include "build/build_config.h" |
19 #include "content/browser/indexed_db/indexed_db_class_factory.h" | 22 #include "content/browser/indexed_db/indexed_db_class_factory.h" |
20 #include "content/browser/indexed_db/indexed_db_tracing.h" | 23 #include "content/browser/indexed_db/indexed_db_tracing.h" |
21 #include "content/browser/indexed_db/leveldb/leveldb_comparator.h" | 24 #include "content/browser/indexed_db/leveldb/leveldb_comparator.h" |
22 #include "content/browser/indexed_db/leveldb/leveldb_env.h" | 25 #include "content/browser/indexed_db/leveldb/leveldb_env.h" |
23 #include "content/browser/indexed_db/leveldb/leveldb_iterator_impl.h" | 26 #include "content/browser/indexed_db/leveldb/leveldb_iterator_impl.h" |
24 #include "content/browser/indexed_db/leveldb/leveldb_write_batch.h" | 27 #include "content/browser/indexed_db/leveldb/leveldb_write_batch.h" |
25 #include "third_party/leveldatabase/env_chromium.h" | 28 #include "third_party/leveldatabase/env_chromium.h" |
26 #include "third_party/leveldatabase/src/helpers/memenv/memenv.h" | 29 #include "third_party/leveldatabase/src/helpers/memenv/memenv.h" |
27 #include "third_party/leveldatabase/src/include/leveldb/db.h" | 30 #include "third_party/leveldatabase/src/include/leveldb/db.h" |
28 #include "third_party/leveldatabase/src/include/leveldb/env.h" | 31 #include "third_party/leveldatabase/src/include/leveldb/env.h" |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
158 if (!status.ok()) | 161 if (!status.ok()) |
159 return scoped_ptr<LevelDBLock>(); | 162 return scoped_ptr<LevelDBLock>(); |
160 DCHECK(lock); | 163 DCHECK(lock); |
161 return scoped_ptr<LevelDBLock>(new LockImpl(env, lock)); | 164 return scoped_ptr<LevelDBLock>(new LockImpl(env, lock)); |
162 } | 165 } |
163 | 166 |
164 static int CheckFreeSpace(const char* const type, | 167 static int CheckFreeSpace(const char* const type, |
165 const base::FilePath& file_name) { | 168 const base::FilePath& file_name) { |
166 std::string name = | 169 std::string name = |
167 std::string("WebCore.IndexedDB.LevelDB.Open") + type + "FreeDiskSpace"; | 170 std::string("WebCore.IndexedDB.LevelDB.Open") + type + "FreeDiskSpace"; |
168 int64 free_disk_space_in_k_bytes = | 171 int64_t free_disk_space_in_k_bytes = |
169 base::SysInfo::AmountOfFreeDiskSpace(file_name) / 1024; | 172 base::SysInfo::AmountOfFreeDiskSpace(file_name) / 1024; |
170 if (free_disk_space_in_k_bytes < 0) { | 173 if (free_disk_space_in_k_bytes < 0) { |
171 base::Histogram::FactoryGet( | 174 base::Histogram::FactoryGet( |
172 "WebCore.IndexedDB.LevelDB.FreeDiskSpaceFailure", | 175 "WebCore.IndexedDB.LevelDB.FreeDiskSpaceFailure", |
173 1, | 176 1, |
174 2 /*boundary*/, | 177 2 /*boundary*/, |
175 2 /*boundary*/ + 1, | 178 2 /*boundary*/ + 1, |
176 base::HistogramBase::kUmaTargetedHistogramFlag)->Add(1 /*sample*/); | 179 base::HistogramBase::kUmaTargetedHistogramFlag)->Add(1 /*sample*/); |
177 return -1; | 180 return -1; |
178 } | 181 } |
179 int clamped_disk_space_k_bytes = free_disk_space_in_k_bytes > INT_MAX | 182 int clamped_disk_space_k_bytes = free_disk_space_in_k_bytes > INT_MAX |
180 ? INT_MAX | 183 ? INT_MAX |
181 : free_disk_space_in_k_bytes; | 184 : free_disk_space_in_k_bytes; |
182 const uint64 histogram_max = static_cast<uint64>(1e9); | 185 const uint64_t histogram_max = static_cast<uint64_t>(1e9); |
183 static_assert(histogram_max <= INT_MAX, "histogram_max too big"); | 186 static_assert(histogram_max <= INT_MAX, "histogram_max too big"); |
184 base::Histogram::FactoryGet(name, | 187 base::Histogram::FactoryGet(name, |
185 1, | 188 1, |
186 histogram_max, | 189 histogram_max, |
187 11 /*buckets*/, | 190 11 /*buckets*/, |
188 base::HistogramBase::kUmaTargetedHistogramFlag) | 191 base::HistogramBase::kUmaTargetedHistogramFlag) |
189 ->Add(clamped_disk_space_k_bytes); | 192 ->Add(clamped_disk_space_k_bytes); |
190 return clamped_disk_space_k_bytes; | 193 return clamped_disk_space_k_bytes; |
191 } | 194 } |
192 | 195 |
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
429 const leveldb::Slice start_slice = MakeSlice(start); | 432 const leveldb::Slice start_slice = MakeSlice(start); |
430 const leveldb::Slice stop_slice = MakeSlice(stop); | 433 const leveldb::Slice stop_slice = MakeSlice(stop); |
431 // NULL batch means just wait for earlier writes to be done | 434 // NULL batch means just wait for earlier writes to be done |
432 db_->Write(leveldb::WriteOptions(), NULL); | 435 db_->Write(leveldb::WriteOptions(), NULL); |
433 db_->CompactRange(&start_slice, &stop_slice); | 436 db_->CompactRange(&start_slice, &stop_slice); |
434 } | 437 } |
435 | 438 |
436 void LevelDBDatabase::CompactAll() { db_->CompactRange(NULL, NULL); } | 439 void LevelDBDatabase::CompactAll() { db_->CompactRange(NULL, NULL); } |
437 | 440 |
438 } // namespace content | 441 } // namespace content |
OLD | NEW |