Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(413)

Side by Side Diff: webkit/dom_storage/session_storage_database.cc

Issue 12316124: Add UMA statistics for tracking session storage database opening failures. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/dom_storage/session_storage_database.h" 5 #include "webkit/dom_storage/session_storage_database.h"
6 6
7 #include "base/file_util.h" 7 #include "base/file_util.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/metrics/histogram.h"
9 #include "base/stringprintf.h" 10 #include "base/stringprintf.h"
10 #include "base/string_number_conversions.h" 11 #include "base/string_number_conversions.h"
11 #include "base/utf_string_conversions.h" 12 #include "base/utf_string_conversions.h"
12 #include "googleurl/src/gurl.h" 13 #include "googleurl/src/gurl.h"
13 #include "third_party/leveldatabase/src/include/leveldb/db.h" 14 #include "third_party/leveldatabase/src/include/leveldb/db.h"
14 #include "third_party/leveldatabase/src/include/leveldb/iterator.h" 15 #include "third_party/leveldatabase/src/include/leveldb/iterator.h"
15 #include "third_party/leveldatabase/src/include/leveldb/status.h" 16 #include "third_party/leveldatabase/src/include/leveldb/status.h"
16 #include "third_party/leveldatabase/src/include/leveldb/options.h" 17 #include "third_party/leveldatabase/src/include/leveldb/options.h"
17 #include "third_party/leveldatabase/src/include/leveldb/write_batch.h" 18 #include "third_party/leveldatabase/src/include/leveldb/write_batch.h"
18 19
20 namespace {
21
michaeln 2013/02/27 00:31:57 Can you define a constant for histogram name value
marja 2013/02/27 08:48:25 Done. I just #define'd it, because we cannot have
michaeln 2013/02/27 20:31:48 I would expect compilers to optimize the multiple
22 enum SessionStorageUMA {
23 SESSION_STORAGE_UMA_SUCCESS,
24 SESSION_STORAGE_UMA_RECREATED,
25 SESSION_STORAGE_UMA_FAIL,
26 SESSION_STORAGE_UMA_MAX
27 };
28
29 } // namespace
30
19 // Layout of the database: 31 // Layout of the database:
20 // | key | value | 32 // | key | value |
21 // ----------------------------------------------------------------------- 33 // -----------------------------------------------------------------------
22 // | map-1- | 2 (refcount, start of map-1-* keys)| 34 // | map-1- | 2 (refcount, start of map-1-* keys)|
23 // | map-1-a | b (a = b in map 1) | 35 // | map-1-a | b (a = b in map 1) |
24 // | ... | | 36 // | ... | |
25 // | namespace- | dummy (start of namespace-* keys) | 37 // | namespace- | dummy (start of namespace-* keys) |
26 // | namespace-1- (1 = namespace id)| dummy (start of namespace-1-* keys)| 38 // | namespace-1- (1 = namespace id)| dummy (start of namespace-1-* keys)|
27 // | namespace-1-origin1 | 1 (mapid) | 39 // | namespace-1-origin1 | 1 (mapid) |
28 // | namespace-1-origin2 | 2 | 40 // | namespace-1-origin2 | 2 |
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after
279 LOG(WARNING) << "Failed to open leveldb in " << file_path_.value() 291 LOG(WARNING) << "Failed to open leveldb in " << file_path_.value()
280 << ", error: " << s.ToString(); 292 << ", error: " << s.ToString();
281 DCHECK(db == NULL); 293 DCHECK(db == NULL);
282 294
283 // Clear the directory and try again. 295 // Clear the directory and try again.
284 file_util::Delete(file_path_, true); 296 file_util::Delete(file_path_, true);
285 s = TryToOpen(&db); 297 s = TryToOpen(&db);
286 if (!s.ok()) { 298 if (!s.ok()) {
287 LOG(WARNING) << "Failed to open leveldb in " << file_path_.value() 299 LOG(WARNING) << "Failed to open leveldb in " << file_path_.value()
288 << ", error: " << s.ToString(); 300 << ", error: " << s.ToString();
301 UMA_HISTOGRAM_ENUMERATION("SessionStorageDatabase.Open",
302 SESSION_STORAGE_UMA_FAIL,
303 SESSION_STORAGE_UMA_MAX);
289 DCHECK(db == NULL); 304 DCHECK(db == NULL);
290 db_error_ = true; 305 db_error_ = true;
291 return false; 306 return false;
292 } 307 }
308 UMA_HISTOGRAM_ENUMERATION("SessionStorageDatabase.Open",
309 SESSION_STORAGE_UMA_RECREATED,
310 SESSION_STORAGE_UMA_MAX);
311 } else {
312 UMA_HISTOGRAM_ENUMERATION("SessionStorageDatabase.Open",
313 SESSION_STORAGE_UMA_SUCCESS,
314 SESSION_STORAGE_UMA_MAX);
293 } 315 }
294 db_.reset(db); 316 db_.reset(db);
295 return true; 317 return true;
296 } 318 }
297 319
298 leveldb::Status SessionStorageDatabase::TryToOpen(leveldb::DB** db) { 320 leveldb::Status SessionStorageDatabase::TryToOpen(leveldb::DB** db) {
299 leveldb::Options options; 321 leveldb::Options options;
300 // The directory exists but a valid leveldb database might not exist inside it 322 // The directory exists but a valid leveldb database might not exist inside it
301 // (e.g., a subset of the needed files might be missing). Handle this 323 // (e.g., a subset of the needed files might be missing). Handle this
302 // situation gracefully by creating the database now. 324 // situation gracefully by creating the database now.
(...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after
641 std::string SessionStorageDatabase::MapKey(const std::string& map_id, 663 std::string SessionStorageDatabase::MapKey(const std::string& map_id,
642 const std::string& key) { 664 const std::string& key) {
643 return base::StringPrintf("map-%s-%s", map_id.c_str(), key.c_str()); 665 return base::StringPrintf("map-%s-%s", map_id.c_str(), key.c_str());
644 } 666 }
645 667
646 const char* SessionStorageDatabase::NextMapIdKey() { 668 const char* SessionStorageDatabase::NextMapIdKey() {
647 return "next-map-id"; 669 return "next-map-id";
648 } 670 }
649 671
650 } // namespace dom_storage 672 } // namespace dom_storage
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698