| 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_CHANGE_LIST_LOADER_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_DRIVE_CHANGE_LIST_LOADER_H_ |
| 6 #define CHROME_BROWSER_CHROMEOS_DRIVE_CHANGE_LIST_LOADER_H_ | 6 #define CHROME_BROWSER_CHROMEOS_DRIVE_CHANGE_LIST_LOADER_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <set> | 9 #include <set> |
| 10 #include <string> | 10 #include <string> |
| 11 #include <vector> | 11 #include <vector> |
| 12 | 12 |
| 13 #include "base/callback.h" | 13 #include "base/callback.h" |
| 14 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
| 15 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
| 16 #include "base/memory/scoped_vector.h" | 16 #include "base/memory/scoped_vector.h" |
| 17 #include "base/observer_list.h" | 17 #include "base/observer_list.h" |
| 18 #include "chrome/browser/chromeos/drive/file_errors.h" | 18 #include "chrome/browser/chromeos/drive/file_errors.h" |
| 19 #include "google_apis/drive/drive_common_callbacks.h" | 19 #include "google_apis/drive/drive_common_callbacks.h" |
| 20 #include "google_apis/drive/gdata_errorcode.h" | 20 #include "google_apis/drive/gdata_errorcode.h" |
| 21 | 21 |
| 22 class GURL; | 22 class GURL; |
| 23 | 23 |
| 24 namespace base { | 24 namespace base { |
| 25 class ScopedClosureRunner; |
| 25 class SequencedTaskRunner; | 26 class SequencedTaskRunner; |
| 26 class Time; | 27 class Time; |
| 27 } // namespace base | 28 } // namespace base |
| 28 | 29 |
| 29 namespace google_apis { | 30 namespace google_apis { |
| 30 class AboutResource; | 31 class AboutResource; |
| 31 class ResourceList; | 32 class ResourceList; |
| 32 } // namespace google_apis | 33 } // namespace google_apis |
| 33 | 34 |
| 34 namespace drive { | 35 namespace drive { |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 const FileOperationCallback& callback); | 97 const FileOperationCallback& callback); |
| 97 | 98 |
| 98 // Calls Load() with an empty DirectoryFetchInfo(). Only for testing purposes. | 99 // Calls Load() with an empty DirectoryFetchInfo(). Only for testing purposes. |
| 99 void LoadForTesting(const FileOperationCallback& callback); | 100 void LoadForTesting(const FileOperationCallback& callback); |
| 100 | 101 |
| 101 // Gets the about resource from the cache or the server. If the cache is | 102 // Gets the about resource from the cache or the server. If the cache is |
| 102 // availlavle, just runs |callback| with the cached about resource. If not, | 103 // availlavle, just runs |callback| with the cached about resource. If not, |
| 103 // calls |UpdateAboutResource| passing |callback|. | 104 // calls |UpdateAboutResource| passing |callback|. |
| 104 void GetAboutResource(const google_apis::AboutResourceCallback& callback); | 105 void GetAboutResource(const google_apis::AboutResourceCallback& callback); |
| 105 | 106 |
| 107 // Increments the lock count and returns an object which decrements the count |
| 108 // on its destruction. |
| 109 // While the lock count is positive, ChangeListLoader does not add any entries |
| 110 // to the local metadata. |
| 111 scoped_ptr<base::ScopedClosureRunner> GetLock(); |
| 112 |
| 106 private: | 113 private: |
| 107 // Part of LoadDirectoryIfNeeded(). | 114 // Part of LoadDirectoryIfNeeded(). |
| 108 void LoadDirectoryIfNeededAfterGetEntry(const base::FilePath& directory_path, | 115 void LoadDirectoryIfNeededAfterGetEntry(const base::FilePath& directory_path, |
| 109 const FileOperationCallback& callback, | 116 const FileOperationCallback& callback, |
| 110 bool should_try_loading_parent, | 117 bool should_try_loading_parent, |
| 111 const ResourceEntry* entry, | 118 const ResourceEntry* entry, |
| 112 FileError error); | 119 FileError error); |
| 113 void LoadDirectoryIfNeededAfterLoadParent( | 120 void LoadDirectoryIfNeededAfterLoadParent( |
| 114 const base::FilePath& directory_path, | 121 const base::FilePath& directory_path, |
| 115 const FileOperationCallback& callback, | 122 const FileOperationCallback& callback, |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 184 FileError error, | 191 FileError error, |
| 185 ScopedVector<ChangeList> change_lists); | 192 ScopedVector<ChangeList> change_lists); |
| 186 | 193 |
| 187 // Part of LoadDirectoryFromServer(). | 194 // Part of LoadDirectoryFromServer(). |
| 188 void LoadDirectoryFromServerAfterRefresh( | 195 void LoadDirectoryFromServerAfterRefresh( |
| 189 const DirectoryFetchInfo& directory_fetch_info, | 196 const DirectoryFetchInfo& directory_fetch_info, |
| 190 const FileOperationCallback& callback, | 197 const FileOperationCallback& callback, |
| 191 const base::FilePath* directory_path, | 198 const base::FilePath* directory_path, |
| 192 FileError error); | 199 FileError error); |
| 193 | 200 |
| 201 // ================= Implementation for lock mechanism ==================== |
| 202 // Runs the closure if the lock count is 0, otherwise it will be pending. |
| 203 // All tasks which may add entries should be run via this method. |
| 204 void ApplyChange(const base::Closure& closure); |
| 205 |
| 206 // Decrements the lock count. |
| 207 void Unlock(); |
| 208 |
| 194 // ================= Implementation for other stuff ================= | 209 // ================= Implementation for other stuff ================= |
| 195 | 210 |
| 196 // Gets the about resource from the server, and caches it if successful. This | 211 // Gets the about resource from the server, and caches it if successful. This |
| 197 // function calls JobScheduler::GetAboutResource internally. The cache will be | 212 // function calls JobScheduler::GetAboutResource internally. The cache will be |
| 198 // used in |GetAboutResource|. | 213 // used in |GetAboutResource|. |
| 199 void UpdateAboutResource( | 214 void UpdateAboutResource( |
| 200 const google_apis::AboutResourceCallback& callback); | 215 const google_apis::AboutResourceCallback& callback); |
| 201 // Part of UpdateAboutResource(). | 216 // Part of UpdateAboutResource(). |
| 202 // This function should be called when the latest about resource is being | 217 // This function should be called when the latest about resource is being |
| 203 // fetched from the server. The retrieved about resoure is cloned, and one is | 218 // fetched from the server. The retrieved about resoure is cloned, and one is |
| 204 // cached and the other is passed to |callback|. | 219 // cached and the other is passed to |callback|. |
| 205 void UpdateAboutResourceAfterGetAbout( | 220 void UpdateAboutResourceAfterGetAbout( |
| 206 const google_apis::AboutResourceCallback& callback, | 221 const google_apis::AboutResourceCallback& callback, |
| 207 google_apis::GDataErrorCode status, | 222 google_apis::GDataErrorCode status, |
| 208 scoped_ptr<google_apis::AboutResource> about_resource); | 223 scoped_ptr<google_apis::AboutResource> about_resource); |
| 209 | 224 |
| 210 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_; | 225 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_; |
| 211 ResourceMetadata* resource_metadata_; // Not owned. | 226 ResourceMetadata* resource_metadata_; // Not owned. |
| 212 JobScheduler* scheduler_; // Not owned. | 227 JobScheduler* scheduler_; // Not owned. |
| 213 DriveServiceInterface* drive_service_; // Not owned. | 228 DriveServiceInterface* drive_service_; // Not owned. |
| 214 ObserverList<ChangeListLoaderObserver> observers_; | 229 ObserverList<ChangeListLoaderObserver> observers_; |
| 215 typedef std::map<std::string, std::vector<FileOperationCallback> > | 230 typedef std::map<std::string, std::vector<FileOperationCallback> > |
| 216 LoadCallbackMap; | 231 LoadCallbackMap; |
| 217 LoadCallbackMap pending_load_callback_; | 232 LoadCallbackMap pending_load_callback_; |
| 218 FileOperationCallback pending_update_check_callback_; | 233 FileOperationCallback pending_update_check_callback_; |
| 219 | 234 |
| 235 int lock_count_; |
| 236 std::vector<base::Closure> pending_apply_closures_; |
| 237 |
| 220 // Running feed fetcher. | 238 // Running feed fetcher. |
| 221 scoped_ptr<FeedFetcher> change_feed_fetcher_; | 239 scoped_ptr<FeedFetcher> change_feed_fetcher_; |
| 222 | 240 |
| 223 // Set of the running feed fetcher for the fast fetch. | 241 // Set of the running feed fetcher for the fast fetch. |
| 224 std::set<FeedFetcher*> fast_fetch_feed_fetcher_set_; | 242 std::set<FeedFetcher*> fast_fetch_feed_fetcher_set_; |
| 225 | 243 |
| 226 // The cache of the about resource. | 244 // The cache of the about resource. |
| 227 scoped_ptr<google_apis::AboutResource> cached_about_resource_; | 245 scoped_ptr<google_apis::AboutResource> cached_about_resource_; |
| 228 | 246 |
| 229 // True if the full resource list is loaded (i.e. the resource metadata is | 247 // True if the full resource list is loaded (i.e. the resource metadata is |
| 230 // stored locally). | 248 // stored locally). |
| 231 bool loaded_; | 249 bool loaded_; |
| 232 | 250 |
| 233 // Note: This should remain the last member so it'll be destroyed and | 251 // Note: This should remain the last member so it'll be destroyed and |
| 234 // invalidate its weak pointers before any other members are destroyed. | 252 // invalidate its weak pointers before any other members are destroyed. |
| 235 base::WeakPtrFactory<ChangeListLoader> weak_ptr_factory_; | 253 base::WeakPtrFactory<ChangeListLoader> weak_ptr_factory_; |
| 236 DISALLOW_COPY_AND_ASSIGN(ChangeListLoader); | 254 DISALLOW_COPY_AND_ASSIGN(ChangeListLoader); |
| 237 }; | 255 }; |
| 238 | 256 |
| 239 } // namespace internal | 257 } // namespace internal |
| 240 } // namespace drive | 258 } // namespace drive |
| 241 | 259 |
| 242 #endif // CHROME_BROWSER_CHROMEOS_DRIVE_CHANGE_LIST_LOADER_H_ | 260 #endif // CHROME_BROWSER_CHROMEOS_DRIVE_CHANGE_LIST_LOADER_H_ |
| OLD | NEW |