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

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

Issue 10581038: chromeos: Stop returning scoped_ptr from GDataCache::GetCacheEntry (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 8 years, 5 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 | « chrome/browser/chromeos/gdata/gdata_cache_unittest.cc ('k') | 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 <errno.h> 5 #include <errno.h>
6 #include <string> 6 #include <string>
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/bind_helpers.h" 10 #include "base/bind_helpers.h"
(...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after
413 413
414 FilePath GetCacheFilePath(const std::string& resource_id, 414 FilePath GetCacheFilePath(const std::string& resource_id,
415 const std::string& md5, 415 const std::string& md5,
416 GDataCache::CacheSubDirectoryType sub_dir_type, 416 GDataCache::CacheSubDirectoryType sub_dir_type,
417 GDataCache::CachedFileOrigin file_origin) { 417 GDataCache::CachedFileOrigin file_origin) {
418 return cache_->GetCacheFilePath(resource_id, md5, sub_dir_type, 418 return cache_->GetCacheFilePath(resource_id, md5, sub_dir_type,
419 file_origin); 419 file_origin);
420 } 420 }
421 421
422 // Helper function to call GetCacheEntry from origin thread. 422 // Helper function to call GetCacheEntry from origin thread.
423 scoped_ptr<GDataCacheEntry> GetCacheEntryFromOriginThread( 423 bool GetCacheEntryFromOriginThread(const std::string& resource_id,
424 const std::string& resource_id, 424 const std::string& md5,
425 const std::string& md5) { 425 GDataCacheEntry* cache_entry) {
426 scoped_ptr<GDataCacheEntry> cache_entry; 426 bool result = false;
427 content::BrowserThread::GetBlockingPool() 427 content::BrowserThread::GetBlockingPool()
428 ->GetSequencedTaskRunner(sequence_token_)->PostTask( 428 ->GetSequencedTaskRunner(sequence_token_)->PostTask(
429 FROM_HERE, 429 FROM_HERE,
430 base::Bind( 430 base::Bind(
431 &GDataFileSystemTest::GetCacheEntryFromOriginThreadInternal, 431 &GDataFileSystemTest::GetCacheEntryFromOriginThreadInternal,
432 base::Unretained(this), 432 base::Unretained(this),
433 resource_id, 433 resource_id,
434 md5, 434 md5,
435 &cache_entry)); 435 cache_entry,
436 &result));
436 test_util::RunBlockingPoolTask(); 437 test_util::RunBlockingPoolTask();
437 return cache_entry.Pass(); 438 return result;
438 } 439 }
439 440
440 // Used to implement GetCacheEntry. 441 // Used to implement GetCacheEntry.
441 void GetCacheEntryFromOriginThreadInternal( 442 void GetCacheEntryFromOriginThreadInternal(
442 const std::string& resource_id, 443 const std::string& resource_id,
443 const std::string& md5, 444 const std::string& md5,
444 scoped_ptr<GDataCacheEntry>* cache_entry) { 445 GDataCacheEntry* cache_entry,
445 cache_entry->reset(cache_->GetCacheEntry(resource_id, md5).release()); 446 bool* result) {
447 *result = cache_->GetCacheEntry(resource_id, md5, cache_entry);
446 } 448 }
447 449
448 // Returns true if the cache entry exists for the given resource ID and MD5. 450 // Returns true if the cache entry exists for the given resource ID and MD5.
449 bool CacheEntryExists(const std::string& resource_id, 451 bool CacheEntryExists(const std::string& resource_id,
450 const std::string& md5) { 452 const std::string& md5) {
451 return GetCacheEntryFromOriginThread(resource_id, md5).get(); 453 GDataCacheEntry cache_entry;
454 return GetCacheEntryFromOriginThread(resource_id, md5, &cache_entry);
452 } 455 }
453 456
454 // Returns true if the cache file exists for the given resource ID and MD5. 457 // Returns true if the cache file exists for the given resource ID and MD5.
455 bool CacheFileExists(const std::string& resource_id, 458 bool CacheFileExists(const std::string& resource_id,
456 const std::string& md5) { 459 const std::string& md5) {
457 const FilePath file_path = cache_->GetCacheFilePath( 460 const FilePath file_path = cache_->GetCacheFilePath(
458 resource_id, 461 resource_id,
459 md5, 462 md5,
460 GDataCache::CACHE_TYPE_TMP, 463 GDataCache::CACHE_TYPE_TMP,
461 GDataCache::CACHED_FILE_FROM_SERVER); 464 GDataCache::CACHED_FILE_FROM_SERVER);
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
588 } 591 }
589 592
590 void VerifyCacheFileState(base::PlatformFileError error, 593 void VerifyCacheFileState(base::PlatformFileError error,
591 const std::string& resource_id, 594 const std::string& resource_id,
592 const std::string& md5) { 595 const std::string& md5) {
593 ++num_callback_invocations_; 596 ++num_callback_invocations_;
594 597
595 EXPECT_EQ(expected_error_, error); 598 EXPECT_EQ(expected_error_, error);
596 599
597 // Verify cache map. 600 // Verify cache map.
598 scoped_ptr<GDataCacheEntry> cache_entry = 601 GDataCacheEntry cache_entry;
599 GetCacheEntryFromOriginThread(resource_id, md5); 602 const bool cache_entry_found =
603 GetCacheEntryFromOriginThread(resource_id, md5, &cache_entry);
600 if (ToCacheEntry(expected_cache_state_).IsPresent() || 604 if (ToCacheEntry(expected_cache_state_).IsPresent() ||
601 ToCacheEntry(expected_cache_state_).IsPinned()) { 605 ToCacheEntry(expected_cache_state_).IsPinned()) {
602 ASSERT_TRUE(cache_entry.get()); 606 ASSERT_TRUE(cache_entry_found);
603 EXPECT_EQ(expected_cache_state_, cache_entry->cache_state()); 607 EXPECT_EQ(expected_cache_state_, cache_entry.cache_state());
604 EXPECT_EQ(expected_sub_dir_type_, 608 EXPECT_EQ(expected_sub_dir_type_,
605 GDataCache::GetSubDirectoryType(*cache_entry)); 609 GDataCache::GetSubDirectoryType(cache_entry));
606 } else { 610 } else {
607 EXPECT_FALSE(cache_entry.get()); 611 EXPECT_FALSE(cache_entry_found);
608 } 612 }
609 613
610 // Verify actual cache file. 614 // Verify actual cache file.
611 FilePath dest_path = cache_->GetCacheFilePath( 615 FilePath dest_path = cache_->GetCacheFilePath(
612 resource_id, 616 resource_id,
613 md5, 617 md5,
614 ToCacheEntry(expected_cache_state_).IsPinned() || 618 ToCacheEntry(expected_cache_state_).IsPinned() ||
615 ToCacheEntry(expected_cache_state_).IsDirty() ? 619 ToCacheEntry(expected_cache_state_).IsDirty() ?
616 GDataCache::CACHE_TYPE_PERSISTENT : 620 GDataCache::CACHE_TYPE_PERSISTENT :
617 GDataCache::CACHE_TYPE_TMP, 621 GDataCache::CACHE_TYPE_TMP,
(...skipping 1907 matching lines...) Expand 10 before | Expand all | Expand 10 after
2525 2529
2526 // Try to close the same file twice. 2530 // Try to close the same file twice.
2527 file_system_->CloseFile(kFileInRoot, close_file_callback); 2531 file_system_->CloseFile(kFileInRoot, close_file_callback);
2528 message_loop_.Run(); 2532 message_loop_.Run();
2529 2533
2530 // It must fail. 2534 // It must fail.
2531 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, callback_helper_->last_error_); 2535 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, callback_helper_->last_error_);
2532 } 2536 }
2533 2537
2534 } // namespace gdata 2538 } // namespace gdata
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/gdata/gdata_cache_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698