| 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.h" | 5 #include "chrome/browser/chromeos/gdata/gdata_cache.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/chromeos/chromeos_version.h" | 9 #include "base/chromeos/chromeos_version.h" |
| 10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
| (...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 339 FilePath* cache_file_path) { | 339 FilePath* cache_file_path) { |
| 340 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 340 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 341 DCHECK(error); | 341 DCHECK(error); |
| 342 DCHECK(cache_file_path); | 342 DCHECK(cache_file_path); |
| 343 | 343 |
| 344 if (!callback.is_null()) | 344 if (!callback.is_null()) |
| 345 callback.Run(*error, resource_id, md5, *cache_file_path); | 345 callback.Run(*error, resource_id, md5, *cache_file_path); |
| 346 } | 346 } |
| 347 | 347 |
| 348 // Runs callback with pointers dereferenced. | 348 // Runs callback with pointers dereferenced. |
| 349 // Used to implement GetResourceIdsOfBacklog(). | 349 // Used to implement GetResourceIdsOfBacklogOnUIThread(). |
| 350 void RunGetResourceIdsCallback(const GetResourceIdsCallback& callback, | 350 void RunGetResourceIdsCallback(const GetResourceIdsCallback& callback, |
| 351 std::vector<std::string>* to_fetch, | 351 std::vector<std::string>* to_fetch, |
| 352 std::vector<std::string>* to_upload) { | 352 std::vector<std::string>* to_upload) { |
| 353 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 353 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 354 DCHECK(to_fetch); | 354 DCHECK(to_fetch); |
| 355 DCHECK(to_upload); | 355 DCHECK(to_upload); |
| 356 | 356 |
| 357 if (!callback.is_null()) | 357 if (!callback.is_null()) |
| 358 callback.Run(*to_fetch, *to_upload); | 358 callback.Run(*to_fetch, *to_upload); |
| 359 } | 359 } |
| 360 | 360 |
| 361 // Runs callback with pointers dereferenced. |
| 362 // Used to implement GetCacheEntryOnUIThread(). |
| 363 void RunGetCacheEntryCallback( |
| 364 const GDataCache::GetCacheEntryCallback& callback, |
| 365 bool* success, |
| 366 GDataCache::CacheEntry* cache_entry) { |
| 367 DCHECK(success); |
| 368 DCHECK(cache_entry); |
| 369 |
| 370 if (!callback.is_null()) |
| 371 callback.Run(*success, *cache_entry); |
| 372 } |
| 373 |
| 361 } // namespace | 374 } // namespace |
| 362 | 375 |
| 363 std::string GDataCache::CacheEntry::ToString() const { | 376 std::string GDataCache::CacheEntry::ToString() const { |
| 364 std::vector<std::string> cache_states; | 377 std::vector<std::string> cache_states; |
| 365 if (GDataCache::IsCachePresent(cache_state)) | 378 if (GDataCache::IsCachePresent(cache_state)) |
| 366 cache_states.push_back("present"); | 379 cache_states.push_back("present"); |
| 367 if (GDataCache::IsCachePinned(cache_state)) | 380 if (GDataCache::IsCachePinned(cache_state)) |
| 368 cache_states.push_back("pinned"); | 381 cache_states.push_back("pinned"); |
| 369 if (GDataCache::IsCacheDirty(cache_state)) | 382 if (GDataCache::IsCacheDirty(cache_state)) |
| 370 cache_states.push_back("dirty"); | 383 cache_states.push_back("dirty"); |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 438 void GDataCache::AddObserver(Observer* observer) { | 451 void GDataCache::AddObserver(Observer* observer) { |
| 439 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 452 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 440 observers_.AddObserver(observer); | 453 observers_.AddObserver(observer); |
| 441 } | 454 } |
| 442 | 455 |
| 443 void GDataCache::RemoveObserver(Observer* observer) { | 456 void GDataCache::RemoveObserver(Observer* observer) { |
| 444 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 457 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 445 observers_.RemoveObserver(observer); | 458 observers_.RemoveObserver(observer); |
| 446 } | 459 } |
| 447 | 460 |
| 461 void GDataCache::GetCacheEntryOnUIThread( |
| 462 const std::string& resource_id, |
| 463 const std::string& md5, |
| 464 const GetCacheEntryCallback& callback) { |
| 465 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 466 |
| 467 bool* success = new bool(false); |
| 468 GDataCache::CacheEntry* cache_entry = new GDataCache::CacheEntry; |
| 469 pool_->GetSequencedTaskRunner(sequence_token_)->PostTaskAndReply( |
| 470 FROM_HERE, |
| 471 base::Bind(&GDataCache::GetCacheEntryHelper, |
| 472 base::Unretained(this), |
| 473 resource_id, |
| 474 md5, |
| 475 success, |
| 476 cache_entry), |
| 477 base::Bind(&RunGetCacheEntryCallback, |
| 478 callback, |
| 479 base::Owned(success), |
| 480 base::Owned(cache_entry))); |
| 481 } |
| 482 |
| 448 void GDataCache::GetResourceIdsOfBacklogOnUIThread( | 483 void GDataCache::GetResourceIdsOfBacklogOnUIThread( |
| 449 const GetResourceIdsCallback& callback) { | 484 const GetResourceIdsCallback& callback) { |
| 450 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 485 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 451 | 486 |
| 452 std::vector<std::string>* to_fetch = new std::vector<std::string>; | 487 std::vector<std::string>* to_fetch = new std::vector<std::string>; |
| 453 std::vector<std::string>* to_upload = new std::vector<std::string>; | 488 std::vector<std::string>* to_upload = new std::vector<std::string>; |
| 454 pool_->GetSequencedTaskRunner(sequence_token_)->PostTaskAndReply( | 489 pool_->GetSequencedTaskRunner(sequence_token_)->PostTaskAndReply( |
| 455 FROM_HERE, | 490 FROM_HERE, |
| 456 base::Bind(&GDataCache::GetResourceIdsOfBacklog, | 491 base::Bind(&GDataCache::GetResourceIdsOfBacklog, |
| 457 base::Unretained(this), | 492 base::Unretained(this), |
| (...skipping 998 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1456 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1491 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 1457 DCHECK(error); | 1492 DCHECK(error); |
| 1458 | 1493 |
| 1459 if (!callback.is_null()) | 1494 if (!callback.is_null()) |
| 1460 callback.Run(*error, resource_id, md5); | 1495 callback.Run(*error, resource_id, md5); |
| 1461 | 1496 |
| 1462 if (*error == base::PLATFORM_FILE_OK) | 1497 if (*error == base::PLATFORM_FILE_OK) |
| 1463 FOR_EACH_OBSERVER(Observer, observers_, OnCacheCommitted(resource_id)); | 1498 FOR_EACH_OBSERVER(Observer, observers_, OnCacheCommitted(resource_id)); |
| 1464 } | 1499 } |
| 1465 | 1500 |
| 1501 void GDataCache::GetCacheEntryHelper(const std::string& resource_id, |
| 1502 const std::string& md5, |
| 1503 bool* success, |
| 1504 GDataCache::CacheEntry* cache_entry) { |
| 1505 AssertOnSequencedWorkerPool(); |
| 1506 DCHECK(success); |
| 1507 DCHECK(cache_entry); |
| 1508 |
| 1509 scoped_ptr<GDataCache::CacheEntry> value(GetCacheEntry(resource_id, md5)); |
| 1510 *success = value.get(); |
| 1511 if (*success) |
| 1512 *cache_entry = *value; |
| 1513 } |
| 1514 |
| 1466 // static | 1515 // static |
| 1467 FilePath GDataCache::GetCacheRootPath(Profile* profile) { | 1516 FilePath GDataCache::GetCacheRootPath(Profile* profile) { |
| 1468 FilePath cache_base_path; | 1517 FilePath cache_base_path; |
| 1469 chrome::GetUserCacheDirectory(profile->GetPath(), &cache_base_path); | 1518 chrome::GetUserCacheDirectory(profile->GetPath(), &cache_base_path); |
| 1470 FilePath cache_root_path = | 1519 FilePath cache_root_path = |
| 1471 cache_base_path.Append(chrome::kGDataCacheDirname); | 1520 cache_base_path.Append(chrome::kGDataCacheDirname); |
| 1472 return cache_root_path.Append(kGDataCacheVersionDir); | 1521 return cache_root_path.Append(kGDataCacheVersionDir); |
| 1473 } | 1522 } |
| 1474 | 1523 |
| 1475 void SetFreeDiskSpaceGetterForTesting(FreeDiskSpaceGetterInterface* getter) { | 1524 void SetFreeDiskSpaceGetterForTesting(FreeDiskSpaceGetterInterface* getter) { |
| 1476 delete global_free_disk_getter_for_testing; // Safe to delete NULL; | 1525 delete global_free_disk_getter_for_testing; // Safe to delete NULL; |
| 1477 global_free_disk_getter_for_testing = getter; | 1526 global_free_disk_getter_for_testing = getter; |
| 1478 } | 1527 } |
| 1479 | 1528 |
| 1480 } // namespace gdata | 1529 } // namespace gdata |
| OLD | NEW |