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

Side by Side Diff: chrome/browser/chromeos/gdata/drive_cache_metadata.cc

Issue 10981030: UMA counts for corrupt cache db. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: satorux feedback Created 8 years, 2 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 "chrome/browser/chromeos/gdata/drive_cache_metadata.h" 5 #include "chrome/browser/chromeos/gdata/drive_cache_metadata.h"
6 6
7 #include <leveldb/db.h> 7 #include <leveldb/db.h>
8 8
9 #include "base/callback.h" 9 #include "base/callback.h"
10 #include "base/file_util.h" 10 #include "base/file_util.h"
11 #include "base/metrics/histogram.h"
11 #include "base/sequenced_task_runner.h" 12 #include "base/sequenced_task_runner.h"
12 #include "chrome/browser/chromeos/gdata/drive.pb.h" 13 #include "chrome/browser/chromeos/gdata/drive.pb.h"
13 #include "chrome/browser/chromeos/gdata/drive_file_system_util.h" 14 #include "chrome/browser/chromeos/gdata/drive_file_system_util.h"
14 15
15 namespace gdata { 16 namespace gdata {
16 17
17 namespace { 18 namespace {
18 19
20 enum DBOpenStatus {
21 DB_OPEN_SUCCESS,
22 DB_OPEN_FAILURE_CORRUPTION,
23 DB_OPEN_FAILURE_OTHER,
24 DB_OPEN_MAX_VALUE,
25 };
26
19 // A map table of resource ID to file path. 27 // A map table of resource ID to file path.
20 typedef std::map<std::string, FilePath> ResourceIdToFilePathMap; 28 typedef std::map<std::string, FilePath> ResourceIdToFilePathMap;
21 29
22 // Returns true if |file_path| is a valid symbolic link as |sub_dir_type|. 30 // Returns true if |file_path| is a valid symbolic link as |sub_dir_type|.
23 // Otherwise, returns false with the reason. 31 // Otherwise, returns false with the reason.
24 bool IsValidSymbolicLink(const FilePath& file_path, 32 bool IsValidSymbolicLink(const FilePath& file_path,
25 DriveCache::CacheSubDirectoryType sub_dir_type, 33 DriveCache::CacheSubDirectoryType sub_dir_type,
26 const std::vector<FilePath>& cache_paths, 34 const std::vector<FilePath>& cache_paths,
27 std::string* reason) { 35 std::string* reason) {
28 DCHECK(sub_dir_type == DriveCache::CACHE_TYPE_PINNED || 36 DCHECK(sub_dir_type == DriveCache::CACHE_TYPE_PINNED ||
(...skipping 430 matching lines...) Expand 10 before | Expand all | Expand 10 after
459 bool scan_cache = !file_util::PathExists(db_path); 467 bool scan_cache = !file_util::PathExists(db_path);
460 468
461 leveldb::DB* level_db = NULL; 469 leveldb::DB* level_db = NULL;
462 leveldb::Options options; 470 leveldb::Options options;
463 options.create_if_missing = true; 471 options.create_if_missing = true;
464 leveldb::Status db_status = leveldb::DB::Open(options, db_path.value(), 472 leveldb::Status db_status = leveldb::DB::Open(options, db_path.value(),
465 &level_db); 473 &level_db);
466 474
467 // Delete the db and scan the physical cache. This will fix a corrupt db, but 475 // Delete the db and scan the physical cache. This will fix a corrupt db, but
468 // perhaps not other causes of failed DB::Open. 476 // perhaps not other causes of failed DB::Open.
477 DBOpenStatus uma_status = DB_OPEN_SUCCESS;
469 if (!db_status.ok()) { 478 if (!db_status.ok()) {
470 DVLOG(1) << "Detected corrupt db"; 479 LOG(WARNING) << "Cache db failed to open: " << db_status.ToString();
satorux1 2012/09/25 23:09:03 ToString() is neat!
480 uma_status = db_status.IsCorruption() ?
481 DB_OPEN_FAILURE_CORRUPTION : DB_OPEN_FAILURE_OTHER;
471 const bool deleted = file_util::Delete(db_path, true); 482 const bool deleted = file_util::Delete(db_path, true);
472 DCHECK(deleted); 483 DCHECK(deleted);
473 db_status = leveldb::DB::Open(options, db_path.value(), &level_db); 484 db_status = leveldb::DB::Open(options, db_path.value(), &level_db);
474 // TODO(satorux): Handle the situation where DB::Open fails because of lack 485 // TODO(satorux): Handle the situation where DB::Open fails because of lack
475 // of disk space, permissions, or other causes. crbug.com/150840. 486 // of disk space, permissions, or other causes. crbug.com/150840.
476 CHECK(db_status.ok()); // Must succeed or we'll crash later. 487 CHECK(db_status.ok()); // Must succeed or we'll crash later.
477 scan_cache = true; 488 scan_cache = true;
478 } 489 }
479 DCHECK(level_db); 490 DCHECK(level_db);
480 level_db_.reset(level_db); 491 level_db_.reset(level_db);
481 492
493 UMA_HISTOGRAM_ENUMERATION(
494 "Drive.CacheMetadataDBOpen", uma_status, DB_OPEN_MAX_VALUE);
495
482 // We scan the cache directories to initialize the cache database if we 496 // We scan the cache directories to initialize the cache database if we
483 // were previously using the cache map. 497 // were previously using the cache map.
484 if (scan_cache) { 498 if (scan_cache) {
485 CacheMap cache_map; 499 CacheMap cache_map;
486 ScanCachePaths(cache_paths, &cache_map); 500 ScanCachePaths(cache_paths, &cache_map);
487 InsertMapIntoDB(cache_map); 501 InsertMapIntoDB(cache_map);
488 } 502 }
489 } 503 }
490 504
491 void DriveCacheMetadataDB::InsertMapIntoDB(const CacheMap& cache_map) { 505 void DriveCacheMetadataDB::InsertMapIntoDB(const CacheMap& cache_map) {
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
612 return scoped_ptr<DriveCacheMetadata>( 626 return scoped_ptr<DriveCacheMetadata>(
613 new FakeDriveCacheMetadata(blocking_task_runner)); 627 new FakeDriveCacheMetadata(blocking_task_runner));
614 } 628 }
615 629
616 void DriveCacheMetadata::AssertOnSequencedWorkerPool() { 630 void DriveCacheMetadata::AssertOnSequencedWorkerPool() {
617 DCHECK(!blocking_task_runner_ || 631 DCHECK(!blocking_task_runner_ ||
618 blocking_task_runner_->RunsTasksOnCurrentThread()); 632 blocking_task_runner_->RunsTasksOnCurrentThread());
619 } 633 }
620 634
621 } // namespace gdata 635 } // namespace gdata
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