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

Side by Side Diff: chrome/browser/chromeos/drive/resource_metadata_storage.cc

Issue 17004011: drive: DriveIntegrationService owns ResourceMetadataStorage (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 6 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 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 "chrome/browser/chromeos/drive/resource_metadata_storage.h" 5 #include "chrome/browser/chromeos/drive/resource_metadata_storage.h"
6 6
7 #include "base/bind.h"
7 #include "base/file_util.h" 8 #include "base/file_util.h"
9 #include "base/location.h"
8 #include "base/logging.h" 10 #include "base/logging.h"
9 #include "base/metrics/histogram.h" 11 #include "base/metrics/histogram.h"
12 #include "base/sequenced_task_runner.h"
10 #include "base/threading/thread_restrictions.h" 13 #include "base/threading/thread_restrictions.h"
11 #include "chrome/browser/chromeos/drive/drive.pb.h" 14 #include "chrome/browser/chromeos/drive/drive.pb.h"
12 #include "third_party/leveldatabase/src/include/leveldb/db.h" 15 #include "third_party/leveldatabase/src/include/leveldb/db.h"
13 #include "third_party/leveldatabase/src/include/leveldb/write_batch.h" 16 #include "third_party/leveldatabase/src/include/leveldb/write_batch.h"
14 17
15 namespace drive { 18 namespace drive {
19 namespace internal {
16 20
17 namespace { 21 namespace {
18 22
19 // Enum to describe DB initialization status. 23 // Enum to describe DB initialization status.
20 enum DBInitStatus { 24 enum DBInitStatus {
21 DB_INIT_SUCCESS, 25 DB_INIT_SUCCESS,
22 DB_INIT_NOT_FOUND, 26 DB_INIT_NOT_FOUND,
23 DB_INIT_CORRUPTION, 27 DB_INIT_CORRUPTION,
24 DB_INIT_IO_ERROR, 28 DB_INIT_IO_ERROR,
25 DB_INIT_FAILED, 29 DB_INIT_FAILED,
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 // Drop the suffix |kDBKeyDelimeter + kCacheEntryKeySuffix| from the key. 191 // Drop the suffix |kDBKeyDelimeter + kCacheEntryKeySuffix| from the key.
188 const size_t kSuffixLength = arraysize(kCacheEntryKeySuffix) - 1; 192 const size_t kSuffixLength = arraysize(kCacheEntryKeySuffix) - 1;
189 const int id_length = it_->key().size() - 1 - kSuffixLength; 193 const int id_length = it_->key().size() - 1 - kSuffixLength;
190 resource_id_.assign(it_->key().data(), id_length); 194 resource_id_.assign(it_->key().data(), id_length);
191 break; 195 break;
192 } 196 }
193 } 197 }
194 } 198 }
195 199
196 ResourceMetadataStorage::ResourceMetadataStorage( 200 ResourceMetadataStorage::ResourceMetadataStorage(
197 const base::FilePath& directory_path) 201 const base::FilePath& directory_path,
198 : directory_path_(directory_path) { 202 base::SequencedTaskRunner* blocking_task_runner)
203 : directory_path_(directory_path),
204 blocking_task_runner_(blocking_task_runner) {
199 } 205 }
200 206
201 ResourceMetadataStorage::~ResourceMetadataStorage() { 207 void ResourceMetadataStorage::Destroy() {
202 base::ThreadRestrictions::AssertIOAllowed(); 208 blocking_task_runner_->PostTask(
209 FROM_HERE,
210 base::Bind(&ResourceMetadataStorage::DestroyOnBlockingPool,
211 base::Unretained(this)));
203 } 212 }
204 213
205 bool ResourceMetadataStorage::Initialize() { 214 bool ResourceMetadataStorage::Initialize() {
206 base::ThreadRestrictions::AssertIOAllowed(); 215 base::ThreadRestrictions::AssertIOAllowed();
207 216
208 // Remove unused child map DB. 217 // Remove unused child map DB.
209 const base::FilePath child_map_path = directory_path_.Append(kChildMapDBName); 218 const base::FilePath child_map_path = directory_path_.Append(kChildMapDBName);
210 file_util::Delete(child_map_path, true /* recursive */); 219 file_util::Delete(child_map_path, true /* recursive */);
211 220
212 resource_map_.reset(); 221 resource_map_.reset();
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after
457 466
458 scoped_ptr<ResourceMetadataStorage::CacheEntryIterator> 467 scoped_ptr<ResourceMetadataStorage::CacheEntryIterator>
459 ResourceMetadataStorage::GetCacheEntryIterator() { 468 ResourceMetadataStorage::GetCacheEntryIterator() {
460 base::ThreadRestrictions::AssertIOAllowed(); 469 base::ThreadRestrictions::AssertIOAllowed();
461 470
462 scoped_ptr<leveldb::Iterator> it( 471 scoped_ptr<leveldb::Iterator> it(
463 resource_map_->NewIterator(leveldb::ReadOptions())); 472 resource_map_->NewIterator(leveldb::ReadOptions()));
464 return make_scoped_ptr(new CacheEntryIterator(it.Pass())); 473 return make_scoped_ptr(new CacheEntryIterator(it.Pass()));
465 } 474 }
466 475
476 ResourceMetadataStorage::~ResourceMetadataStorage() {
477 base::ThreadRestrictions::AssertIOAllowed();
478 }
479
480 void ResourceMetadataStorage::DestroyOnBlockingPool() {
481 delete this;
482 }
483
467 // static 484 // static
468 std::string ResourceMetadataStorage::GetChildEntryKey( 485 std::string ResourceMetadataStorage::GetChildEntryKey(
469 const std::string& parent_resource_id, 486 const std::string& parent_resource_id,
470 const std::string& child_name) { 487 const std::string& child_name) {
471 std::string key = parent_resource_id; 488 std::string key = parent_resource_id;
472 key.push_back(kDBKeyDelimeter); 489 key.push_back(kDBKeyDelimeter);
473 key.append(child_name); 490 key.append(child_name);
474 key.push_back(kDBKeyDelimeter); 491 key.push_back(kDBKeyDelimeter);
475 return key; 492 return key;
476 } 493 }
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
586 } 603 }
587 } 604 }
588 if (!it->status().ok() || num_child_entries != num_entries_with_parent) { 605 if (!it->status().ok() || num_child_entries != num_entries_with_parent) {
589 DLOG(ERROR) << "Error during checking resource map. status = " 606 DLOG(ERROR) << "Error during checking resource map. status = "
590 << it->status().ToString(); 607 << it->status().ToString();
591 return false; 608 return false;
592 } 609 }
593 return true; 610 return true;
594 } 611 }
595 612
613 } // namespace internal
596 } // namespace drive 614 } // namespace drive
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698