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> |
(...skipping 27 matching lines...) Expand all Loading... |
38 class ResourceEntry; | 38 class ResourceEntry; |
39 | 39 |
40 namespace internal { | 40 namespace internal { |
41 | 41 |
42 class ChangeList; | 42 class ChangeList; |
43 class ChangeListLoaderObserver; | 43 class ChangeListLoaderObserver; |
44 class ChangeListProcessor; | 44 class ChangeListProcessor; |
45 class DirectoryFetchInfo; | 45 class DirectoryFetchInfo; |
46 class ResourceMetadata; | 46 class ResourceMetadata; |
47 | 47 |
48 // Callback run as a response to SearchFromServer. | |
49 typedef base::Callback<void(ScopedVector<ChangeList> change_lists, | |
50 FileError error)> LoadChangeListCallback; | |
51 | |
52 // ChangeListLoader is used to load the change list, the full resource list, | 48 // ChangeListLoader is used to load the change list, the full resource list, |
53 // and directory contents, from WAPI (codename for Documents List API) | 49 // and directory contents, from WAPI (codename for Documents List API) |
54 // or Google Drive API. The class also updates the resource metadata with | 50 // or Google Drive API. The class also updates the resource metadata with |
55 // the change list loaded from the server. | 51 // the change list loaded from the server. |
56 // | 52 // |
57 // Note that the difference between "resource list" and "change list" is | 53 // Note that the difference between "resource list" and "change list" is |
58 // subtle hence the two words are often used interchangeably. To be precise, | 54 // subtle hence the two words are often used interchangeably. To be precise, |
59 // "resource list" refers to metadata from the server when fetching the full | 55 // "resource list" refers to metadata from the server when fetching the full |
60 // resource metadata, or fetching directory contents, whereas "change list" | 56 // resource metadata, or fetching directory contents, whereas "change list" |
61 // refers to metadata from the server when fetching changes (delta). | 57 // refers to metadata from the server when fetching changes (delta). |
(...skipping 16 matching lines...) Expand all Loading... |
78 // Adds and removes the observer. | 74 // Adds and removes the observer. |
79 void AddObserver(ChangeListLoaderObserver* observer); | 75 void AddObserver(ChangeListLoaderObserver* observer); |
80 void RemoveObserver(ChangeListLoaderObserver* observer); | 76 void RemoveObserver(ChangeListLoaderObserver* observer); |
81 | 77 |
82 // Checks for updates on the server. Does nothing if the change list is now | 78 // Checks for updates on the server. Does nothing if the change list is now |
83 // being loaded or refreshed. |callback| must not be null. | 79 // being loaded or refreshed. |callback| must not be null. |
84 // Note: |callback| will be called if the check for updates actually | 80 // Note: |callback| will be called if the check for updates actually |
85 // runs, i.e. it may NOT be called if the checking is ignored. | 81 // runs, i.e. it may NOT be called if the checking is ignored. |
86 void CheckForUpdates(const FileOperationCallback& callback); | 82 void CheckForUpdates(const FileOperationCallback& callback); |
87 | 83 |
88 // Starts the change list loading first from the cache. If loading from the | 84 // Starts the change list loading if needed. If the locally stored metadata is |
89 // cache is successful, runs |callback| immediately and starts checking | 85 // available, runs |callback| immediately and starts checking server for |
90 // server for updates in background. If loading from the cache is | 86 // updates in background. If the locally stored metadata is not available, |
91 // unsuccessful, starts loading from the server, and runs |callback| to tell | 87 // starts loading from the server, and runs |callback| to tell the result to |
92 // the result to the caller when it is finished. | 88 // the caller when it is finished. |
93 // | 89 // |
94 // If |directory_fetch_info| is not empty, the directory will be fetched | 90 // The specified directory will be fetched first from the server, so the UI |
95 // first from the server, so the UI can show the directory contents | 91 // can show the directory contents instantly before the entire change list |
96 // instantly before the entire change list loading is complete. | 92 // loading is complete. |
97 // | 93 // |
98 // |callback| must not be null. | 94 // |callback| must not be null. |
99 void LoadIfNeeded(const DirectoryFetchInfo& directory_fetch_info, | 95 void LoadDirectoryIfNeeded(const base::FilePath& directory_path, |
100 const FileOperationCallback& callback); | 96 const FileOperationCallback& callback); |
| 97 |
| 98 // Calls Load() with an empty DirectoryFetchInfo(). Only for testing purposes. |
| 99 void LoadForTesting(const FileOperationCallback& callback); |
101 | 100 |
102 // Gets the about resource from the cache or the server. If the cache is | 101 // Gets the about resource from the cache or the server. If the cache is |
103 // availlavle, just runs |callback| with the cached about resource. If not, | 102 // availlavle, just runs |callback| with the cached about resource. If not, |
104 // calls |UpdateAboutResource| passing |callback|. | 103 // calls |UpdateAboutResource| passing |callback|. |
105 void GetAboutResource(const google_apis::AboutResourceCallback& callback); | 104 void GetAboutResource(const google_apis::AboutResourceCallback& callback); |
106 | 105 |
107 private: | 106 private: |
| 107 // Part of LoadDirectoryIfNeeded(). |
| 108 void LoadDirectoryIfNeededAfterGetEntry(const base::FilePath& directory_path, |
| 109 const FileOperationCallback& callback, |
| 110 bool should_try_loading_parent, |
| 111 const ResourceEntry* entry, |
| 112 FileError error); |
| 113 void LoadDirectoryIfNeededAfterLoadParent( |
| 114 const base::FilePath& directory_path, |
| 115 const FileOperationCallback& callback, |
| 116 FileError error); |
| 117 |
108 // Starts the resource metadata loading and calls |callback| when it's | 118 // Starts the resource metadata loading and calls |callback| when it's |
109 // done. |directory_fetch_info| is used for fast fetch. If there is already | 119 // done. |directory_fetch_info| is used for fast fetch. If there is already |
110 // a loading job in-flight for |directory_fetch_info|, just append the | 120 // a loading job in-flight for |directory_fetch_info|, just append the |
111 // |callback| to the callback queue of the already running job. | 121 // |callback| to the callback queue of the already running job. |
112 void Load(const DirectoryFetchInfo& directory_fetch_info, | 122 void Load(const DirectoryFetchInfo& directory_fetch_info, |
113 const FileOperationCallback& callback); | 123 const FileOperationCallback& callback); |
114 void LoadAfterGetLargestChangestamp( | 124 void LoadAfterGetLargestChangestamp( |
115 const DirectoryFetchInfo& directory_fetch_info, | 125 const DirectoryFetchInfo& directory_fetch_info, |
116 bool is_initial_load, | 126 bool is_initial_load, |
117 int64 local_changestamp); | 127 int64 local_changestamp); |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
223 // Note: This should remain the last member so it'll be destroyed and | 233 // Note: This should remain the last member so it'll be destroyed and |
224 // invalidate its weak pointers before any other members are destroyed. | 234 // invalidate its weak pointers before any other members are destroyed. |
225 base::WeakPtrFactory<ChangeListLoader> weak_ptr_factory_; | 235 base::WeakPtrFactory<ChangeListLoader> weak_ptr_factory_; |
226 DISALLOW_COPY_AND_ASSIGN(ChangeListLoader); | 236 DISALLOW_COPY_AND_ASSIGN(ChangeListLoader); |
227 }; | 237 }; |
228 | 238 |
229 } // namespace internal | 239 } // namespace internal |
230 } // namespace drive | 240 } // namespace drive |
231 | 241 |
232 #endif // CHROME_BROWSER_CHROMEOS_DRIVE_CHANGE_LIST_LOADER_H_ | 242 #endif // CHROME_BROWSER_CHROMEOS_DRIVE_CHANGE_LIST_LOADER_H_ |
OLD | NEW |