| 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 "chrome/browser/chromeos/gdata/gdata_cache_metadata.h" | 5 #include "chrome/browser/chromeos/gdata/gdata_cache_metadata.h" |
| 6 | 6 |
| 7 #include <leveldb/db.h> | 7 #include <leveldb/db.h> |
| 8 | 8 |
| 9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
| 10 #include "base/sequenced_task_runner.h" | 10 #include "base/sequenced_task_runner.h" |
| 11 #include "chrome/browser/chromeos/gdata/gdata.pb.h" | 11 #include "chrome/browser/chromeos/gdata/drive.pb.h" |
| 12 #include "chrome/browser/chromeos/gdata/gdata_util.h" | 12 #include "chrome/browser/chromeos/gdata/gdata_util.h" |
| 13 | 13 |
| 14 namespace gdata { | 14 namespace gdata { |
| 15 | 15 |
| 16 namespace { | 16 namespace { |
| 17 | 17 |
| 18 // A map table of resource ID to file path. | 18 // A map table of resource ID to file path. |
| 19 typedef std::map<std::string, FilePath> ResourceIdToFilePathMap; | 19 typedef std::map<std::string, FilePath> ResourceIdToFilePathMap; |
| 20 | 20 |
| 21 const FilePath::CharType kGDataCacheMetadataDBPath[] = | 21 const FilePath::CharType kGDataCacheMetadataDBPath[] = |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 GDataCacheMetadata::CacheMap* cache_map) { | 70 GDataCacheMetadata::CacheMap* cache_map) { |
| 71 for (ResourceIdToFilePathMap::const_iterator iter = | 71 for (ResourceIdToFilePathMap::const_iterator iter = |
| 72 persistent_file_map.begin(); | 72 persistent_file_map.begin(); |
| 73 iter != persistent_file_map.end(); ++iter) { | 73 iter != persistent_file_map.end(); ++iter) { |
| 74 const std::string& resource_id = iter->first; | 74 const std::string& resource_id = iter->first; |
| 75 const FilePath& file_path = iter->second; | 75 const FilePath& file_path = iter->second; |
| 76 | 76 |
| 77 GDataCacheMetadata::CacheMap::iterator cache_map_iter = | 77 GDataCacheMetadata::CacheMap::iterator cache_map_iter = |
| 78 cache_map->find(resource_id); | 78 cache_map->find(resource_id); |
| 79 if (cache_map_iter != cache_map->end()) { | 79 if (cache_map_iter != cache_map->end()) { |
| 80 const GDataCacheEntry& cache_entry = cache_map_iter->second; | 80 const DriveCacheEntry& cache_entry = cache_map_iter->second; |
| 81 // If the file is dirty but not committed, remove it. | 81 // If the file is dirty but not committed, remove it. |
| 82 if (cache_entry.is_dirty() && | 82 if (cache_entry.is_dirty() && |
| 83 outgoing_file_map.count(resource_id) == 0) { | 83 outgoing_file_map.count(resource_id) == 0) { |
| 84 LOG(WARNING) << "Removing dirty-but-not-committed file: " | 84 LOG(WARNING) << "Removing dirty-but-not-committed file: " |
| 85 << file_path.value(); | 85 << file_path.value(); |
| 86 file_util::Delete(file_path, false); | 86 file_util::Delete(file_path, false); |
| 87 cache_map->erase(cache_map_iter); | 87 cache_map->erase(cache_map_iter); |
| 88 } else if (!cache_entry.is_dirty() && | 88 } else if (!cache_entry.is_dirty() && |
| 89 !cache_entry.is_pinned()) { | 89 !cache_entry.is_pinned()) { |
| 90 // If the file is neither dirty nor pinned, remove it. | 90 // If the file is neither dirty nor pinned, remove it. |
| (...skipping 26 matching lines...) Expand all Loading... |
| 117 util::kWildCard); | 117 util::kWildCard); |
| 118 for (FilePath current = enumerator.Next(); !current.empty(); | 118 for (FilePath current = enumerator.Next(); !current.empty(); |
| 119 current = enumerator.Next()) { | 119 current = enumerator.Next()) { |
| 120 // Extract resource_id and md5 from filename. | 120 // Extract resource_id and md5 from filename. |
| 121 std::string resource_id; | 121 std::string resource_id; |
| 122 std::string md5; | 122 std::string md5; |
| 123 std::string extra_extension; | 123 std::string extra_extension; |
| 124 util::ParseCacheFilePath(current, &resource_id, &md5, &extra_extension); | 124 util::ParseCacheFilePath(current, &resource_id, &md5, &extra_extension); |
| 125 | 125 |
| 126 // Determine cache state. | 126 // Determine cache state. |
| 127 GDataCacheEntry cache_entry; | 127 DriveCacheEntry cache_entry; |
| 128 cache_entry.set_md5(md5); | 128 cache_entry.set_md5(md5); |
| 129 // If we're scanning pinned directory and if entry already exists, just | 129 // If we're scanning pinned directory and if entry already exists, just |
| 130 // update its pinned state. | 130 // update its pinned state. |
| 131 if (sub_dir_type == GDataCache::CACHE_TYPE_PINNED) { | 131 if (sub_dir_type == GDataCache::CACHE_TYPE_PINNED) { |
| 132 std::string reason; | 132 std::string reason; |
| 133 if (!IsValidSymbolicLink(current, sub_dir_type, cache_paths, &reason)) { | 133 if (!IsValidSymbolicLink(current, sub_dir_type, cache_paths, &reason)) { |
| 134 LOG(WARNING) << "Removing an invalid symlink: " << current.value() | 134 LOG(WARNING) << "Removing an invalid symlink: " << current.value() |
| 135 << ": " << reason; | 135 << ": " << reason; |
| 136 file_util::Delete(current, false); | 136 file_util::Delete(current, false); |
| 137 continue; | 137 continue; |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 255 RemoveInvalidFilesFromPersistentDirectory(persistent_file_map, | 255 RemoveInvalidFilesFromPersistentDirectory(persistent_file_map, |
| 256 outgoing_file_map, | 256 outgoing_file_map, |
| 257 cache_map); | 257 cache_map); |
| 258 DVLOG(1) << "Directory scan finished"; | 258 DVLOG(1) << "Directory scan finished"; |
| 259 } | 259 } |
| 260 | 260 |
| 261 // Returns true if |md5| matches the one in |cache_entry| with some | 261 // Returns true if |md5| matches the one in |cache_entry| with some |
| 262 // exceptions. See the function definition for details. | 262 // exceptions. See the function definition for details. |
| 263 bool CheckIfMd5Matches( | 263 bool CheckIfMd5Matches( |
| 264 const std::string& md5, | 264 const std::string& md5, |
| 265 const GDataCacheEntry& cache_entry) { | 265 const DriveCacheEntry& cache_entry) { |
| 266 if (cache_entry.is_dirty()) { | 266 if (cache_entry.is_dirty()) { |
| 267 // If the entry is dirty, its MD5 may have been replaced by "local" | 267 // If the entry is dirty, its MD5 may have been replaced by "local" |
| 268 // during cache initialization, so we don't compare MD5. | 268 // during cache initialization, so we don't compare MD5. |
| 269 return true; | 269 return true; |
| 270 } else if (cache_entry.is_pinned() && cache_entry.md5().empty()) { | 270 } else if (cache_entry.is_pinned() && cache_entry.md5().empty()) { |
| 271 // If the entry is pinned, it's ok for the entry to have an empty | 271 // If the entry is pinned, it's ok for the entry to have an empty |
| 272 // MD5. This can happen if the pinned file is not fetched. MD5 for pinned | 272 // MD5. This can happen if the pinned file is not fetched. MD5 for pinned |
| 273 // files are collected from files in "persistent" directory, but the | 273 // files are collected from files in "persistent" directory, but the |
| 274 // persistent files do not exisit if these are not fetched yet. | 274 // persistent files do not exisit if these are not fetched yet. |
| 275 return true; | 275 return true; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 292 explicit FakeGDataCacheMetadata( | 292 explicit FakeGDataCacheMetadata( |
| 293 base::SequencedTaskRunner* blocking_task_runner); | 293 base::SequencedTaskRunner* blocking_task_runner); |
| 294 | 294 |
| 295 private: | 295 private: |
| 296 virtual ~FakeGDataCacheMetadata(); | 296 virtual ~FakeGDataCacheMetadata(); |
| 297 | 297 |
| 298 // GDataCacheMetadata overrides: | 298 // GDataCacheMetadata overrides: |
| 299 virtual void Initialize(const std::vector<FilePath>& cache_paths) OVERRIDE; | 299 virtual void Initialize(const std::vector<FilePath>& cache_paths) OVERRIDE; |
| 300 virtual void AddOrUpdateCacheEntry( | 300 virtual void AddOrUpdateCacheEntry( |
| 301 const std::string& resource_id, | 301 const std::string& resource_id, |
| 302 const GDataCacheEntry& cache_entry) OVERRIDE; | 302 const DriveCacheEntry& cache_entry) OVERRIDE; |
| 303 virtual void RemoveCacheEntry(const std::string& resource_id) OVERRIDE; | 303 virtual void RemoveCacheEntry(const std::string& resource_id) OVERRIDE; |
| 304 virtual bool GetCacheEntry(const std::string& resource_id, | 304 virtual bool GetCacheEntry(const std::string& resource_id, |
| 305 const std::string& md5, | 305 const std::string& md5, |
| 306 GDataCacheEntry* cache_entry) OVERRIDE; | 306 DriveCacheEntry* cache_entry) OVERRIDE; |
| 307 virtual void RemoveTemporaryFiles() OVERRIDE; | 307 virtual void RemoveTemporaryFiles() OVERRIDE; |
| 308 virtual void Iterate(const IterateCallback& callback) OVERRIDE; | 308 virtual void Iterate(const IterateCallback& callback) OVERRIDE; |
| 309 virtual void ForceRescanForTesting( | 309 virtual void ForceRescanForTesting( |
| 310 const std::vector<FilePath>& cache_paths) OVERRIDE; | 310 const std::vector<FilePath>& cache_paths) OVERRIDE; |
| 311 | 311 |
| 312 CacheMap cache_map_; | 312 CacheMap cache_map_; |
| 313 | 313 |
| 314 DISALLOW_COPY_AND_ASSIGN(FakeGDataCacheMetadata); | 314 DISALLOW_COPY_AND_ASSIGN(FakeGDataCacheMetadata); |
| 315 }; | 315 }; |
| 316 | 316 |
| 317 FakeGDataCacheMetadata::FakeGDataCacheMetadata( | 317 FakeGDataCacheMetadata::FakeGDataCacheMetadata( |
| 318 base::SequencedTaskRunner* blocking_task_runner) | 318 base::SequencedTaskRunner* blocking_task_runner) |
| 319 : GDataCacheMetadata(blocking_task_runner) { | 319 : GDataCacheMetadata(blocking_task_runner) { |
| 320 AssertOnSequencedWorkerPool(); | 320 AssertOnSequencedWorkerPool(); |
| 321 } | 321 } |
| 322 | 322 |
| 323 FakeGDataCacheMetadata::~FakeGDataCacheMetadata() { | 323 FakeGDataCacheMetadata::~FakeGDataCacheMetadata() { |
| 324 AssertOnSequencedWorkerPool(); | 324 AssertOnSequencedWorkerPool(); |
| 325 } | 325 } |
| 326 | 326 |
| 327 void FakeGDataCacheMetadata::Initialize( | 327 void FakeGDataCacheMetadata::Initialize( |
| 328 const std::vector<FilePath>& cache_paths) { | 328 const std::vector<FilePath>& cache_paths) { |
| 329 AssertOnSequencedWorkerPool(); | 329 AssertOnSequencedWorkerPool(); |
| 330 | 330 |
| 331 ScanCachePaths(cache_paths, &cache_map_); | 331 ScanCachePaths(cache_paths, &cache_map_); |
| 332 } | 332 } |
| 333 | 333 |
| 334 void FakeGDataCacheMetadata::AddOrUpdateCacheEntry( | 334 void FakeGDataCacheMetadata::AddOrUpdateCacheEntry( |
| 335 const std::string& resource_id, | 335 const std::string& resource_id, |
| 336 const GDataCacheEntry& cache_entry) { | 336 const DriveCacheEntry& cache_entry) { |
| 337 AssertOnSequencedWorkerPool(); | 337 AssertOnSequencedWorkerPool(); |
| 338 | 338 |
| 339 CacheMap::iterator iter = cache_map_.find(resource_id); | 339 CacheMap::iterator iter = cache_map_.find(resource_id); |
| 340 if (iter == cache_map_.end()) { // New resource, create new entry. | 340 if (iter == cache_map_.end()) { // New resource, create new entry. |
| 341 cache_map_.insert(std::make_pair(resource_id, cache_entry)); | 341 cache_map_.insert(std::make_pair(resource_id, cache_entry)); |
| 342 } else { // Resource exists. | 342 } else { // Resource exists. |
| 343 cache_map_[resource_id] = cache_entry; | 343 cache_map_[resource_id] = cache_entry; |
| 344 } | 344 } |
| 345 } | 345 } |
| 346 | 346 |
| 347 void FakeGDataCacheMetadata::RemoveCacheEntry(const std::string& resource_id) { | 347 void FakeGDataCacheMetadata::RemoveCacheEntry(const std::string& resource_id) { |
| 348 AssertOnSequencedWorkerPool(); | 348 AssertOnSequencedWorkerPool(); |
| 349 | 349 |
| 350 CacheMap::iterator iter = cache_map_.find(resource_id); | 350 CacheMap::iterator iter = cache_map_.find(resource_id); |
| 351 if (iter != cache_map_.end()) { | 351 if (iter != cache_map_.end()) { |
| 352 // Delete the CacheEntry and remove it from the map. | 352 // Delete the CacheEntry and remove it from the map. |
| 353 cache_map_.erase(iter); | 353 cache_map_.erase(iter); |
| 354 } | 354 } |
| 355 } | 355 } |
| 356 | 356 |
| 357 bool FakeGDataCacheMetadata::GetCacheEntry(const std::string& resource_id, | 357 bool FakeGDataCacheMetadata::GetCacheEntry(const std::string& resource_id, |
| 358 const std::string& md5, | 358 const std::string& md5, |
| 359 GDataCacheEntry* entry) { | 359 DriveCacheEntry* entry) { |
| 360 DCHECK(entry); | 360 DCHECK(entry); |
| 361 AssertOnSequencedWorkerPool(); | 361 AssertOnSequencedWorkerPool(); |
| 362 | 362 |
| 363 CacheMap::iterator iter = cache_map_.find(resource_id); | 363 CacheMap::iterator iter = cache_map_.find(resource_id); |
| 364 if (iter == cache_map_.end()) { | 364 if (iter == cache_map_.end()) { |
| 365 DVLOG(1) << "Can't find " << resource_id << " in cache map"; | 365 DVLOG(1) << "Can't find " << resource_id << " in cache map"; |
| 366 return false; | 366 return false; |
| 367 } | 367 } |
| 368 | 368 |
| 369 const GDataCacheEntry& cache_entry = iter->second; | 369 const DriveCacheEntry& cache_entry = iter->second; |
| 370 | 370 |
| 371 if (!CheckIfMd5Matches(md5, cache_entry)) { | 371 if (!CheckIfMd5Matches(md5, cache_entry)) { |
| 372 return false; | 372 return false; |
| 373 } | 373 } |
| 374 | 374 |
| 375 *entry = cache_entry; | 375 *entry = cache_entry; |
| 376 return true; | 376 return true; |
| 377 } | 377 } |
| 378 | 378 |
| 379 void FakeGDataCacheMetadata::RemoveTemporaryFiles() { | 379 void FakeGDataCacheMetadata::RemoveTemporaryFiles() { |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 414 explicit GDataCacheMetadataDB( | 414 explicit GDataCacheMetadataDB( |
| 415 base::SequencedTaskRunner* blocking_task_runner); | 415 base::SequencedTaskRunner* blocking_task_runner); |
| 416 | 416 |
| 417 private: | 417 private: |
| 418 virtual ~GDataCacheMetadataDB(); | 418 virtual ~GDataCacheMetadataDB(); |
| 419 | 419 |
| 420 // GDataCacheMetadata overrides: | 420 // GDataCacheMetadata overrides: |
| 421 virtual void Initialize(const std::vector<FilePath>& cache_paths) OVERRIDE; | 421 virtual void Initialize(const std::vector<FilePath>& cache_paths) OVERRIDE; |
| 422 virtual void AddOrUpdateCacheEntry( | 422 virtual void AddOrUpdateCacheEntry( |
| 423 const std::string& resource_id, | 423 const std::string& resource_id, |
| 424 const GDataCacheEntry& cache_entry) OVERRIDE; | 424 const DriveCacheEntry& cache_entry) OVERRIDE; |
| 425 virtual void RemoveCacheEntry(const std::string& resource_id) OVERRIDE; | 425 virtual void RemoveCacheEntry(const std::string& resource_id) OVERRIDE; |
| 426 virtual bool GetCacheEntry(const std::string& resource_id, | 426 virtual bool GetCacheEntry(const std::string& resource_id, |
| 427 const std::string& md5, | 427 const std::string& md5, |
| 428 GDataCacheEntry* cache_entry) OVERRIDE; | 428 DriveCacheEntry* cache_entry) OVERRIDE; |
| 429 virtual void RemoveTemporaryFiles() OVERRIDE; | 429 virtual void RemoveTemporaryFiles() OVERRIDE; |
| 430 virtual void Iterate(const IterateCallback& callback) OVERRIDE; | 430 virtual void Iterate(const IterateCallback& callback) OVERRIDE; |
| 431 virtual void ForceRescanForTesting( | 431 virtual void ForceRescanForTesting( |
| 432 const std::vector<FilePath>& cache_paths) OVERRIDE; | 432 const std::vector<FilePath>& cache_paths) OVERRIDE; |
| 433 | 433 |
| 434 // Helper function to insert |cache_map| entries into the database. | 434 // Helper function to insert |cache_map| entries into the database. |
| 435 void InsertMapIntoDB(const CacheMap& cache_map); | 435 void InsertMapIntoDB(const CacheMap& cache_map); |
| 436 | 436 |
| 437 scoped_ptr<leveldb::DB> level_db_; | 437 scoped_ptr<leveldb::DB> level_db_; |
| 438 | 438 |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 486 void GDataCacheMetadataDB::InsertMapIntoDB(const CacheMap& cache_map) { | 486 void GDataCacheMetadataDB::InsertMapIntoDB(const CacheMap& cache_map) { |
| 487 DVLOG(1) << "InsertMapIntoDB"; | 487 DVLOG(1) << "InsertMapIntoDB"; |
| 488 for (CacheMap::const_iterator it = cache_map.begin(); | 488 for (CacheMap::const_iterator it = cache_map.begin(); |
| 489 it != cache_map.end(); ++it) { | 489 it != cache_map.end(); ++it) { |
| 490 AddOrUpdateCacheEntry(it->first, it->second); | 490 AddOrUpdateCacheEntry(it->first, it->second); |
| 491 } | 491 } |
| 492 } | 492 } |
| 493 | 493 |
| 494 void GDataCacheMetadataDB::AddOrUpdateCacheEntry( | 494 void GDataCacheMetadataDB::AddOrUpdateCacheEntry( |
| 495 const std::string& resource_id, | 495 const std::string& resource_id, |
| 496 const GDataCacheEntry& cache_entry) { | 496 const DriveCacheEntry& cache_entry) { |
| 497 AssertOnSequencedWorkerPool(); | 497 AssertOnSequencedWorkerPool(); |
| 498 | 498 |
| 499 DVLOG(1) << "AddOrUpdateCacheEntry, resource_id=" << resource_id; | 499 DVLOG(1) << "AddOrUpdateCacheEntry, resource_id=" << resource_id; |
| 500 std::string serialized; | 500 std::string serialized; |
| 501 const bool ok = cache_entry.SerializeToString(&serialized); | 501 const bool ok = cache_entry.SerializeToString(&serialized); |
| 502 if (ok) | 502 if (ok) |
| 503 level_db_->Put(leveldb::WriteOptions(), | 503 level_db_->Put(leveldb::WriteOptions(), |
| 504 leveldb::Slice(resource_id), | 504 leveldb::Slice(resource_id), |
| 505 leveldb::Slice(serialized)); | 505 leveldb::Slice(serialized)); |
| 506 } | 506 } |
| 507 | 507 |
| 508 void GDataCacheMetadataDB::RemoveCacheEntry(const std::string& resource_id) { | 508 void GDataCacheMetadataDB::RemoveCacheEntry(const std::string& resource_id) { |
| 509 AssertOnSequencedWorkerPool(); | 509 AssertOnSequencedWorkerPool(); |
| 510 | 510 |
| 511 DVLOG(1) << "RemoveCacheEntry, resource_id=" << resource_id; | 511 DVLOG(1) << "RemoveCacheEntry, resource_id=" << resource_id; |
| 512 level_db_->Delete(leveldb::WriteOptions(), leveldb::Slice(resource_id)); | 512 level_db_->Delete(leveldb::WriteOptions(), leveldb::Slice(resource_id)); |
| 513 } | 513 } |
| 514 | 514 |
| 515 bool GDataCacheMetadataDB::GetCacheEntry(const std::string& resource_id, | 515 bool GDataCacheMetadataDB::GetCacheEntry(const std::string& resource_id, |
| 516 const std::string& md5, | 516 const std::string& md5, |
| 517 GDataCacheEntry* entry) { | 517 DriveCacheEntry* entry) { |
| 518 DCHECK(entry); | 518 DCHECK(entry); |
| 519 AssertOnSequencedWorkerPool(); | 519 AssertOnSequencedWorkerPool(); |
| 520 | 520 |
| 521 std::string serialized; | 521 std::string serialized; |
| 522 const leveldb::Status status = level_db_->Get(leveldb::ReadOptions(), | 522 const leveldb::Status status = level_db_->Get(leveldb::ReadOptions(), |
| 523 leveldb::Slice(resource_id), &serialized); | 523 leveldb::Slice(resource_id), &serialized); |
| 524 if (!status.ok()) { | 524 if (!status.ok()) { |
| 525 DVLOG(1) << "Can't find " << resource_id << " in cache db"; | 525 DVLOG(1) << "Can't find " << resource_id << " in cache db"; |
| 526 return false; | 526 return false; |
| 527 } | 527 } |
| 528 | 528 |
| 529 GDataCacheEntry cache_entry; | 529 DriveCacheEntry cache_entry; |
| 530 const bool ok = cache_entry.ParseFromString(serialized); | 530 const bool ok = cache_entry.ParseFromString(serialized); |
| 531 if (!ok) { | 531 if (!ok) { |
| 532 LOG(ERROR) << "Failed to parse " << serialized; | 532 LOG(ERROR) << "Failed to parse " << serialized; |
| 533 return false; | 533 return false; |
| 534 } | 534 } |
| 535 | 535 |
| 536 if (!CheckIfMd5Matches(md5, cache_entry)) { | 536 if (!CheckIfMd5Matches(md5, cache_entry)) { |
| 537 return false; | 537 return false; |
| 538 } | 538 } |
| 539 | 539 |
| 540 *entry = cache_entry; | 540 *entry = cache_entry; |
| 541 return true; | 541 return true; |
| 542 } | 542 } |
| 543 | 543 |
| 544 void GDataCacheMetadataDB::RemoveTemporaryFiles() { | 544 void GDataCacheMetadataDB::RemoveTemporaryFiles() { |
| 545 AssertOnSequencedWorkerPool(); | 545 AssertOnSequencedWorkerPool(); |
| 546 | 546 |
| 547 scoped_ptr<leveldb::Iterator> iter(level_db_->NewIterator( | 547 scoped_ptr<leveldb::Iterator> iter(level_db_->NewIterator( |
| 548 leveldb::ReadOptions())); | 548 leveldb::ReadOptions())); |
| 549 for (iter->SeekToFirst(); iter->Valid(); iter->Next()) { | 549 for (iter->SeekToFirst(); iter->Valid(); iter->Next()) { |
| 550 GDataCacheEntry cache_entry; | 550 DriveCacheEntry cache_entry; |
| 551 const bool ok = cache_entry.ParseFromString(iter->value().ToString()); | 551 const bool ok = cache_entry.ParseFromString(iter->value().ToString()); |
| 552 if (ok && !cache_entry.is_persistent()) | 552 if (ok && !cache_entry.is_persistent()) |
| 553 level_db_->Delete(leveldb::WriteOptions(), iter->key()); | 553 level_db_->Delete(leveldb::WriteOptions(), iter->key()); |
| 554 } | 554 } |
| 555 } | 555 } |
| 556 | 556 |
| 557 void GDataCacheMetadataDB::Iterate(const IterateCallback& callback) { | 557 void GDataCacheMetadataDB::Iterate(const IterateCallback& callback) { |
| 558 AssertOnSequencedWorkerPool(); | 558 AssertOnSequencedWorkerPool(); |
| 559 | 559 |
| 560 scoped_ptr<leveldb::Iterator> iter(level_db_->NewIterator( | 560 scoped_ptr<leveldb::Iterator> iter(level_db_->NewIterator( |
| 561 leveldb::ReadOptions())); | 561 leveldb::ReadOptions())); |
| 562 for (iter->SeekToFirst(); iter->Valid(); iter->Next()) { | 562 for (iter->SeekToFirst(); iter->Valid(); iter->Next()) { |
| 563 GDataCacheEntry cache_entry; | 563 DriveCacheEntry cache_entry; |
| 564 const bool ok = cache_entry.ParseFromString(iter->value().ToString()); | 564 const bool ok = cache_entry.ParseFromString(iter->value().ToString()); |
| 565 if (ok) | 565 if (ok) |
| 566 callback.Run(iter->key().ToString(), cache_entry); | 566 callback.Run(iter->key().ToString(), cache_entry); |
| 567 } | 567 } |
| 568 } | 568 } |
| 569 | 569 |
| 570 void GDataCacheMetadataDB::ForceRescanForTesting( | 570 void GDataCacheMetadataDB::ForceRescanForTesting( |
| 571 const std::vector<FilePath>& cache_paths) { | 571 const std::vector<FilePath>& cache_paths) { |
| 572 AssertOnSequencedWorkerPool(); | 572 AssertOnSequencedWorkerPool(); |
| 573 | 573 |
| (...skipping 28 matching lines...) Expand all Loading... |
| 602 return scoped_ptr<GDataCacheMetadata>( | 602 return scoped_ptr<GDataCacheMetadata>( |
| 603 new FakeGDataCacheMetadata(blocking_task_runner)); | 603 new FakeGDataCacheMetadata(blocking_task_runner)); |
| 604 } | 604 } |
| 605 | 605 |
| 606 void GDataCacheMetadata::AssertOnSequencedWorkerPool() { | 606 void GDataCacheMetadata::AssertOnSequencedWorkerPool() { |
| 607 DCHECK(!blocking_task_runner_ || | 607 DCHECK(!blocking_task_runner_ || |
| 608 blocking_task_runner_->RunsTasksOnCurrentThread()); | 608 blocking_task_runner_->RunsTasksOnCurrentThread()); |
| 609 } | 609 } |
| 610 | 610 |
| 611 } // namespace gdata | 611 } // namespace gdata |
| OLD | NEW |