| 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 #ifndef CHROME_BROWSER_CHROMEOS_GDATA_DRIVE_CACHE_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_GDATA_DRIVE_CACHE_H_ |
| 6 #define CHROME_BROWSER_CHROMEOS_GDATA_DRIVE_CACHE_H_ | 6 #define CHROME_BROWSER_CHROMEOS_GDATA_DRIVE_CACHE_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "base/callback.h" | 12 #include "base/callback.h" |
| 13 #include "base/file_path.h" | 13 #include "base/file_path.h" |
| 14 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
| 15 #include "base/memory/weak_ptr.h" | 15 #include "base/memory/weak_ptr.h" |
| 16 #include "base/observer_list.h" | 16 #include "base/observer_list.h" |
| 17 #include "base/platform_file.h" | 17 #include "base/platform_file.h" |
| 18 #include "chrome/browser/chromeos/gdata/gdata_errorcode.h" | 18 #include "chrome/browser/chromeos/gdata/drive_errorcode.h" |
| 19 | 19 |
| 20 class Profile; | 20 class Profile; |
| 21 | 21 |
| 22 namespace base { | 22 namespace base { |
| 23 | 23 |
| 24 class SequencedTaskRunner; | 24 class SequencedTaskRunner; |
| 25 | 25 |
| 26 } // namespace base | 26 } // namespace base |
| 27 | 27 |
| 28 namespace gdata { | 28 namespace gdata { |
| 29 | 29 |
| 30 class DriveCacheEntry; | 30 class DriveCacheEntry; |
| 31 class DriveCacheMetadata; | 31 class DriveCacheMetadata; |
| 32 | 32 |
| 33 // Callback for SetMountedStateOnUIThread and ClearAllOnUIThread. | 33 // Callback for SetMountedStateOnUIThread and ClearAllOnUIThread. |
| 34 typedef base::Callback<void(GDataFileError error, | 34 typedef base::Callback<void(DriveFileError error, |
| 35 const FilePath& file_path)> | 35 const FilePath& file_path)> |
| 36 ChangeCacheStateCallback; | 36 ChangeCacheStateCallback; |
| 37 | 37 |
| 38 // Callback for completion of cache operation. | 38 // Callback for completion of cache operation. |
| 39 typedef base::Callback<void(GDataFileError error, | 39 typedef base::Callback<void(DriveFileError error, |
| 40 const std::string& resource_id, | 40 const std::string& resource_id, |
| 41 const std::string& md5)> CacheOperationCallback; | 41 const std::string& md5)> CacheOperationCallback; |
| 42 | 42 |
| 43 // Callback for GetFileFromCache. | 43 // Callback for GetFileFromCache. |
| 44 typedef base::Callback<void(GDataFileError error, | 44 typedef base::Callback<void(DriveFileError error, |
| 45 const std::string& resource_id, | 45 const std::string& resource_id, |
| 46 const std::string& md5, | 46 const std::string& md5, |
| 47 const FilePath& cache_file_path)> | 47 const FilePath& cache_file_path)> |
| 48 GetFileFromCacheCallback; | 48 GetFileFromCacheCallback; |
| 49 | 49 |
| 50 // Callback for GetResourceIdsOfBacklogOnUIThread. | 50 // Callback for GetResourceIdsOfBacklogOnUIThread. |
| 51 // |to_fetch| is for resource IDs of pinned-but-not-fetched files. | 51 // |to_fetch| is for resource IDs of pinned-but-not-fetched files. |
| 52 // |to_upload| is for resource IDs of dirty-but-not-uploaded files. | 52 // |to_upload| is for resource IDs of dirty-but-not-uploaded files. |
| 53 typedef base::Callback<void(const std::vector<std::string>& to_fetch, | 53 typedef base::Callback<void(const std::vector<std::string>& to_fetch, |
| 54 const std::vector<std::string>& to_upload)> | 54 const std::vector<std::string>& to_upload)> |
| (...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 351 void GetResourceIdsOfExistingPinnedFiles( | 351 void GetResourceIdsOfExistingPinnedFiles( |
| 352 std::vector<std::string>* resource_ids); | 352 std::vector<std::string>* resource_ids); |
| 353 | 353 |
| 354 // Used to implement GetResourceIdsOfAllFilesOnUIThread. | 354 // Used to implement GetResourceIdsOfAllFilesOnUIThread. |
| 355 void GetResourceIdsOfAllFiles( | 355 void GetResourceIdsOfAllFiles( |
| 356 std::vector<std::string>* resource_ids); | 356 std::vector<std::string>* resource_ids); |
| 357 | 357 |
| 358 // Used to implement GetFileOnUIThread. | 358 // Used to implement GetFileOnUIThread. |
| 359 void GetFile(const std::string& resource_id, | 359 void GetFile(const std::string& resource_id, |
| 360 const std::string& md5, | 360 const std::string& md5, |
| 361 GDataFileError* error, | 361 DriveFileError* error, |
| 362 FilePath* cache_file_path); | 362 FilePath* cache_file_path); |
| 363 | 363 |
| 364 // Used to implement StoreOnUIThread. | 364 // Used to implement StoreOnUIThread. |
| 365 void Store(const std::string& resource_id, | 365 void Store(const std::string& resource_id, |
| 366 const std::string& md5, | 366 const std::string& md5, |
| 367 const FilePath& source_path, | 367 const FilePath& source_path, |
| 368 FileOperationType file_operation_type, | 368 FileOperationType file_operation_type, |
| 369 GDataFileError* error); | 369 DriveFileError* error); |
| 370 | 370 |
| 371 // Used to implement PinOnUIThread. | 371 // Used to implement PinOnUIThread. |
| 372 void Pin(const std::string& resource_id, | 372 void Pin(const std::string& resource_id, |
| 373 const std::string& md5, | 373 const std::string& md5, |
| 374 FileOperationType file_operation_type, | 374 FileOperationType file_operation_type, |
| 375 GDataFileError* error); | 375 DriveFileError* error); |
| 376 | 376 |
| 377 // Used to implement UnpinOnUIThread. | 377 // Used to implement UnpinOnUIThread. |
| 378 void Unpin(const std::string& resource_id, | 378 void Unpin(const std::string& resource_id, |
| 379 const std::string& md5, | 379 const std::string& md5, |
| 380 FileOperationType file_operation_type, | 380 FileOperationType file_operation_type, |
| 381 GDataFileError* error); | 381 DriveFileError* error); |
| 382 | 382 |
| 383 // Used to implement SetMountedStateOnUIThread. | 383 // Used to implement SetMountedStateOnUIThread. |
| 384 void SetMountedState(const FilePath& file_path, | 384 void SetMountedState(const FilePath& file_path, |
| 385 bool to_mount, | 385 bool to_mount, |
| 386 GDataFileError* error, | 386 DriveFileError* error, |
| 387 FilePath* cache_file_path); | 387 FilePath* cache_file_path); |
| 388 | 388 |
| 389 // Used to implement MarkDirtyOnUIThread. | 389 // Used to implement MarkDirtyOnUIThread. |
| 390 void MarkDirty(const std::string& resource_id, | 390 void MarkDirty(const std::string& resource_id, |
| 391 const std::string& md5, | 391 const std::string& md5, |
| 392 FileOperationType file_operation_type, | 392 FileOperationType file_operation_type, |
| 393 GDataFileError* error, | 393 DriveFileError* error, |
| 394 FilePath* cache_file_path); | 394 FilePath* cache_file_path); |
| 395 | 395 |
| 396 // Used to implement CommitDirtyOnUIThread. | 396 // Used to implement CommitDirtyOnUIThread. |
| 397 void CommitDirty(const std::string& resource_id, | 397 void CommitDirty(const std::string& resource_id, |
| 398 const std::string& md5, | 398 const std::string& md5, |
| 399 FileOperationType file_operation_type, | 399 FileOperationType file_operation_type, |
| 400 GDataFileError* error); | 400 DriveFileError* error); |
| 401 | 401 |
| 402 // Used to implement ClearDirtyOnUIThread. | 402 // Used to implement ClearDirtyOnUIThread. |
| 403 void ClearDirty(const std::string& resource_id, | 403 void ClearDirty(const std::string& resource_id, |
| 404 const std::string& md5, | 404 const std::string& md5, |
| 405 FileOperationType file_operation_type, | 405 FileOperationType file_operation_type, |
| 406 GDataFileError* error); | 406 DriveFileError* error); |
| 407 | 407 |
| 408 // Used to implement RemoveOnUIThread. | 408 // Used to implement RemoveOnUIThread. |
| 409 void Remove(const std::string& resource_id, | 409 void Remove(const std::string& resource_id, |
| 410 GDataFileError* error); | 410 DriveFileError* error); |
| 411 | 411 |
| 412 // Used to implement ClearAllUIThread. | 412 // Used to implement ClearAllUIThread. |
| 413 void ClearAll(GDataFileError* error); | 413 void ClearAll(DriveFileError* error); |
| 414 | 414 |
| 415 // Runs callback and notifies the observers when file is pinned. | 415 // Runs callback and notifies the observers when file is pinned. |
| 416 void OnPinned(GDataFileError* error, | 416 void OnPinned(DriveFileError* error, |
| 417 const std::string& resource_id, | 417 const std::string& resource_id, |
| 418 const std::string& md5, | 418 const std::string& md5, |
| 419 const CacheOperationCallback& callback); | 419 const CacheOperationCallback& callback); |
| 420 | 420 |
| 421 // Runs callback and notifies the observers when file is unpinned. | 421 // Runs callback and notifies the observers when file is unpinned. |
| 422 void OnUnpinned(GDataFileError* error, | 422 void OnUnpinned(DriveFileError* error, |
| 423 const std::string& resource_id, | 423 const std::string& resource_id, |
| 424 const std::string& md5, | 424 const std::string& md5, |
| 425 const CacheOperationCallback& callback); | 425 const CacheOperationCallback& callback); |
| 426 | 426 |
| 427 // Runs callback and notifies the observers when file is committed. | 427 // Runs callback and notifies the observers when file is committed. |
| 428 void OnCommitDirty(GDataFileError* error, | 428 void OnCommitDirty(DriveFileError* error, |
| 429 const std::string& resource_id, | 429 const std::string& resource_id, |
| 430 const std::string& md5, | 430 const std::string& md5, |
| 431 const CacheOperationCallback& callback); | 431 const CacheOperationCallback& callback); |
| 432 | 432 |
| 433 // Helper function to implement GetCacheEntryOnUIThread(). | 433 // Helper function to implement GetCacheEntryOnUIThread(). |
| 434 void GetCacheEntryHelper(const std::string& resource_id, | 434 void GetCacheEntryHelper(const std::string& resource_id, |
| 435 const std::string& md5, | 435 const std::string& md5, |
| 436 bool* success, | 436 bool* success, |
| 437 DriveCacheEntry* cache_entry); | 437 DriveCacheEntry* cache_entry); |
| 438 | 438 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 472 }; | 472 }; |
| 473 | 473 |
| 474 // Sets the free disk space getter for testing. | 474 // Sets the free disk space getter for testing. |
| 475 // The existing getter is deleted. | 475 // The existing getter is deleted. |
| 476 void SetFreeDiskSpaceGetterForTesting( | 476 void SetFreeDiskSpaceGetterForTesting( |
| 477 FreeDiskSpaceGetterInterface* getter); | 477 FreeDiskSpaceGetterInterface* getter); |
| 478 | 478 |
| 479 } // namespace gdata | 479 } // namespace gdata |
| 480 | 480 |
| 481 #endif // CHROME_BROWSER_CHROMEOS_GDATA_DRIVE_CACHE_H_ | 481 #endif // CHROME_BROWSER_CHROMEOS_GDATA_DRIVE_CACHE_H_ |
| OLD | NEW |