| 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/fileapi/file_system_origin_database.h" | 5 #include "webkit/fileapi/file_system_origin_database.h" |
| 6 | 6 |
| 7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
| 8 #include "base/format_macros.h" | 8 #include "base/format_macros.h" |
| 9 #include "base/location.h" | 9 #include "base/location.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/metrics/histogram.h" | 11 #include "base/metrics/histogram.h" |
| 12 #include "base/string_number_conversions.h" | 12 #include "base/string_number_conversions.h" |
| 13 #include "base/stringprintf.h" | 13 #include "base/stringprintf.h" |
| 14 #include "base/string_util.h" | 14 #include "base/string_util.h" |
| 15 #include "third_party/leveldatabase/src/include/leveldb/db.h" | 15 #include "third_party/leveldatabase/src/include/leveldb/db.h" |
| 16 #include "third_party/leveldatabase/src/include/leveldb/write_batch.h" | 16 #include "third_party/leveldatabase/src/include/leveldb/write_batch.h" |
| 17 #include "webkit/fileapi/file_system_util.h" | 17 #include "webkit/fileapi/file_system_util.h" |
| 18 | 18 |
| 19 namespace { | 19 namespace { |
| 20 | 20 |
| 21 const FilePath::CharType kOriginDatabaseName[] = FILE_PATH_LITERAL("Origins"); | 21 const FilePath::CharType kOriginDatabaseName[] = FILE_PATH_LITERAL("Origins"); |
| 22 const char kOriginKeyPrefix[] = "ORIGIN:"; | 22 const char kOriginKeyPrefix[] = "ORIGIN:"; |
| 23 const char kLastPathKey[] = "LAST_PATH"; | 23 const char kLastPathKey[] = "LAST_PATH"; |
| 24 const int64 kMinimumReportIntervalHours = 1; | 24 const int64 kMinimumReportIntervalHours = 1; |
| 25 const char kInitStatusHistogramLabel[] = "FileSystem.OriginDatabaseInit"; | 25 const char kInitStatusHistogramLabel[] = "FileSystem.OriginDatabaseInit"; |
| 26 | 26 |
| 27 enum InitStatus { | 27 enum InitStatus { |
| 28 INIT_STATUS_OK = 0, | 28 INIT_STATUS_OK = 0, |
| 29 INIT_STATUS_CORRUPTION, | 29 INIT_STATUS_CORRUPTION, |
| 30 INIT_STATUS_IO_ERROR, |
| 31 INIT_STATUS_UNKNOWN_ERROR, |
| 30 INIT_STATUS_MAX | 32 INIT_STATUS_MAX |
| 31 }; | 33 }; |
| 32 | 34 |
| 33 std::string OriginToOriginKey(const std::string& origin) { | 35 std::string OriginToOriginKey(const std::string& origin) { |
| 34 std::string key(kOriginKeyPrefix); | 36 std::string key(kOriginKeyPrefix); |
| 35 return key + origin; | 37 return key + origin; |
| 36 } | 38 } |
| 37 | 39 |
| 38 const char* LastPathKey() { | 40 const char* LastPathKey() { |
| 39 return kLastPathKey; | 41 return kLastPathKey; |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 171 base::Time now = base::Time::Now(); | 173 base::Time now = base::Time::Now(); |
| 172 base::TimeDelta minimum_interval = | 174 base::TimeDelta minimum_interval = |
| 173 base::TimeDelta::FromHours(kMinimumReportIntervalHours); | 175 base::TimeDelta::FromHours(kMinimumReportIntervalHours); |
| 174 if (last_reported_time_ + minimum_interval >= now) | 176 if (last_reported_time_ + minimum_interval >= now) |
| 175 return; | 177 return; |
| 176 last_reported_time_ = now; | 178 last_reported_time_ = now; |
| 177 | 179 |
| 178 if (status.ok()) { | 180 if (status.ok()) { |
| 179 UMA_HISTOGRAM_ENUMERATION(kInitStatusHistogramLabel, | 181 UMA_HISTOGRAM_ENUMERATION(kInitStatusHistogramLabel, |
| 180 INIT_STATUS_OK, INIT_STATUS_MAX); | 182 INIT_STATUS_OK, INIT_STATUS_MAX); |
| 183 } else if (status.IsCorruption()) { |
| 184 UMA_HISTOGRAM_ENUMERATION(kInitStatusHistogramLabel, |
| 185 INIT_STATUS_CORRUPTION, INIT_STATUS_MAX); |
| 186 } else if (status.IsIOError()) { |
| 187 UMA_HISTOGRAM_ENUMERATION(kInitStatusHistogramLabel, |
| 188 INIT_STATUS_IO_ERROR, INIT_STATUS_MAX); |
| 181 } else { | 189 } else { |
| 182 UMA_HISTOGRAM_ENUMERATION(kInitStatusHistogramLabel, | 190 UMA_HISTOGRAM_ENUMERATION(kInitStatusHistogramLabel, |
| 183 INIT_STATUS_CORRUPTION, INIT_STATUS_MAX); | 191 INIT_STATUS_UNKNOWN_ERROR, INIT_STATUS_MAX); |
| 184 } | 192 } |
| 185 } | 193 } |
| 186 | 194 |
| 187 bool FileSystemOriginDatabase::HasOriginPath(const std::string& origin) { | 195 bool FileSystemOriginDatabase::HasOriginPath(const std::string& origin) { |
| 188 if (!Init(REPAIR_ON_CORRUPTION)) | 196 if (!Init(REPAIR_ON_CORRUPTION)) |
| 189 return false; | 197 return false; |
| 190 if (origin.empty()) | 198 if (origin.empty()) |
| 191 return false; | 199 return false; |
| 192 std::string path; | 200 std::string path; |
| 193 leveldb::Status status = | 201 leveldb::Status status = |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 295 db_->Put(leveldb::WriteOptions(), LastPathKey(), std::string("-1")); | 303 db_->Put(leveldb::WriteOptions(), LastPathKey(), std::string("-1")); |
| 296 if (!status.ok()) { | 304 if (!status.ok()) { |
| 297 HandleError(FROM_HERE, status); | 305 HandleError(FROM_HERE, status); |
| 298 return false; | 306 return false; |
| 299 } | 307 } |
| 300 *number = -1; | 308 *number = -1; |
| 301 return true; | 309 return true; |
| 302 } | 310 } |
| 303 | 311 |
| 304 } // namespace fileapi | 312 } // namespace fileapi |
| OLD | NEW |