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