OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef CHROME_BROWSER_CHROMEOS_GDATA_STALE_CACHE_FILE_REMOVER_H_ |
| 6 #define CHROME_BROWSER_CHROMEOS_GDATA_STALE_CACHE_FILE_REMOVER_H_ |
| 7 |
| 8 #include <string> |
| 9 #include <vector> |
| 10 |
| 11 #include "base/basictypes.h" |
| 12 #include "chrome/browser/chromeos/gdata/drive_file_system_interface.h" |
| 13 |
| 14 namespace gdata{ |
| 15 |
| 16 class DriveCache; |
| 17 class DriveFileSystem; |
| 18 |
| 19 // This class removes stale cache files, which are present locally, but no |
| 20 // longer present on the server. This can happen if files are removed from the |
| 21 // server from other devices, or from the web interface. |
| 22 class StaleCacheFilesRemover : public DriveFileSystemInterface::Observer { |
| 23 public: |
| 24 StaleCacheFilesRemover(DriveFileSystemInterface* file_system, |
| 25 DriveCache* cache); |
| 26 virtual ~StaleCacheFilesRemover(); |
| 27 |
| 28 private: |
| 29 // Removes stale cache files. |
| 30 // Gets the list of all the resource id and calls OnGetResourceIdsOfAllFiles() |
| 31 // with the list. |
| 32 virtual void OnInitialLoadFinished() OVERRIDE; |
| 33 |
| 34 // Gets the cache entry of each resource id. And passes the cache entry to |
| 35 // GetEntryInfoAndRemoveCacheIfNecessary(). |
| 36 void OnGetResourceIdsOfAllFiles(const std::vector<std::string>& resource_ids); |
| 37 |
| 38 // Gets the file entry and calls RemoveCacheIfNecessary() with the file entry. |
| 39 // This is called from StaleCacheFilesRemover::OnGetResourceIdsOfAllFiles(). |
| 40 void GetEntryInfoAndRemoveCacheIfNecessary( |
| 41 const std::string& resource_id, |
| 42 bool success, |
| 43 const gdata::DriveCacheEntry& cache_entry); |
| 44 |
| 45 // Check the cache file and removes if it is unavailable or invalid (eg. md5 |
| 46 // mismatch). This is called from GetCacheEntryAndRemoveCacheIfNecessary(); |
| 47 void RemoveCacheIfNecessary( |
| 48 const std::string& resource_id, |
| 49 const std::string& cache_md5, |
| 50 DriveFileError error, |
| 51 const FilePath& gdata_file_path, |
| 52 scoped_ptr<gdata::DriveEntryProto> entry_proto); |
| 53 |
| 54 DriveCache* cache_; // Not owned. |
| 55 DriveFileSystemInterface* file_system_; // Not owned. |
| 56 |
| 57 // Note: This should remain the last member so it'll be destroyed and |
| 58 // invalidate its weak pointers before any other members are destroyed. |
| 59 base::WeakPtrFactory<StaleCacheFilesRemover> weak_ptr_factory_; |
| 60 DISALLOW_COPY_AND_ASSIGN(StaleCacheFilesRemover); |
| 61 }; |
| 62 |
| 63 } // namespace gdata |
| 64 |
| 65 #endif // CHROME_BROWSER_CHROMEOS_GDATA_STALE_CACHE_FILE_REMOVER_H_ |
OLD | NEW |