| 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_GDATA_WAPI_FEED_LOADER_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_DRIVE_GDATA_WAPI_FEED_LOADER_H_ |
| 6 #define CHROME_BROWSER_CHROMEOS_DRIVE_GDATA_WAPI_FEED_LOADER_H_ | 6 #define CHROME_BROWSER_CHROMEOS_DRIVE_GDATA_WAPI_FEED_LOADER_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/callback.h" | 11 #include "base/callback.h" |
| 12 #include "base/memory/scoped_vector.h" | 12 #include "base/memory/scoped_vector.h" |
| 13 #include "base/observer_list.h" | 13 #include "base/observer_list.h" |
| 14 #include "chrome/browser/chromeos/drive/drive_resource_metadata.h" | 14 #include "chrome/browser/chromeos/drive/drive_resource_metadata.h" |
| 15 #include "chrome/browser/google_apis/gdata_errorcode.h" | 15 #include "chrome/browser/google_apis/gdata_errorcode.h" |
| 16 #include "googleurl/src/gurl.h" | 16 #include "googleurl/src/gurl.h" |
| 17 | 17 |
| 18 class FilePath; | 18 class FilePath; |
| 19 | 19 |
| 20 namespace base { | 20 namespace base { |
| 21 class Value; | 21 class Value; |
| 22 } | 22 } |
| 23 | 23 |
| 24 namespace gdata { | 24 namespace gdata { |
| 25 class DocumentFeed; |
| 26 } |
| 25 | 27 |
| 26 class DocumentFeed; | 28 namespace drive { |
| 29 |
| 27 class DriveCache; | 30 class DriveCache; |
| 28 class DriveServiceInterface; | 31 class DriveServiceInterface; |
| 29 class DriveWebAppsRegistryInterface; | 32 class DriveWebAppsRegistryInterface; |
| 30 class GDataWapiFeedLoaderObserver; | 33 class GDataWapiFeedLoaderObserver; |
| 31 struct GetDocumentsUiState; | 34 struct GetDocumentsUiState; |
| 32 struct LoadFeedParams; | 35 struct LoadFeedParams; |
| 33 | 36 |
| 34 // Callback run as a response to LoadFromServer. | 37 // Callback run as a response to LoadFromServer. |
| 35 typedef base::Callback<void(scoped_ptr<LoadFeedParams> params, | 38 typedef base::Callback<void(scoped_ptr<LoadFeedParams> params, |
| 36 DriveFileError error)> | 39 DriveFileError error)> |
| (...skipping 24 matching lines...) Expand all Loading... |
| 61 // delta feed between them - bigger the difference, more likely bigger | 64 // delta feed between them - bigger the difference, more likely bigger |
| 62 // number of items in delta feeds. | 65 // number of items in delta feeds. |
| 63 ContentOrigin initial_origin; | 66 ContentOrigin initial_origin; |
| 64 int64 start_changestamp; | 67 int64 start_changestamp; |
| 65 int64 root_feed_changestamp; | 68 int64 root_feed_changestamp; |
| 66 std::string search_query; | 69 std::string search_query; |
| 67 std::string directory_resource_id; | 70 std::string directory_resource_id; |
| 68 GURL feed_to_load; | 71 GURL feed_to_load; |
| 69 const LoadDocumentFeedCallback feed_load_callback; | 72 const LoadDocumentFeedCallback feed_load_callback; |
| 70 FileOperationCallback load_finished_callback; | 73 FileOperationCallback load_finished_callback; |
| 71 ScopedVector<DocumentFeed> feed_list; | 74 ScopedVector<gdata::DocumentFeed> feed_list; |
| 72 scoped_ptr<GetDocumentsUiState> ui_state; | 75 scoped_ptr<GetDocumentsUiState> ui_state; |
| 73 }; | 76 }; |
| 74 | 77 |
| 75 // Defines set of parameters sent to callback OnProtoLoaded(). | 78 // Defines set of parameters sent to callback OnProtoLoaded(). |
| 76 struct LoadRootFeedParams { | 79 struct LoadRootFeedParams { |
| 77 LoadRootFeedParams( | 80 LoadRootFeedParams( |
| 78 bool should_load_from_server, | 81 bool should_load_from_server, |
| 79 const FileOperationCallback& callback); | 82 const FileOperationCallback& callback); |
| 80 ~LoadRootFeedParams(); | 83 ~LoadRootFeedParams(); |
| 81 | 84 |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 int64 local_changestamp, | 145 int64 local_changestamp, |
| 143 const FileOperationCallback& callback); | 146 const FileOperationCallback& callback); |
| 144 | 147 |
| 145 // Updates whole directory structure feeds collected in |feed_list|. | 148 // Updates whole directory structure feeds collected in |feed_list|. |
| 146 // On success, returns PLATFORM_FILE_OK. Record file statistics as UMA | 149 // On success, returns PLATFORM_FILE_OK. Record file statistics as UMA |
| 147 // histograms. | 150 // histograms. |
| 148 // | 151 // |
| 149 // See comments at GDataWapiFeedProcessor::ApplyFeeds() for | 152 // See comments at GDataWapiFeedProcessor::ApplyFeeds() for |
| 150 // |start_changestamp| and |root_feed_changestamp|. | 153 // |start_changestamp| and |root_feed_changestamp|. |
| 151 DriveFileError UpdateFromFeed( | 154 DriveFileError UpdateFromFeed( |
| 152 const ScopedVector<DocumentFeed>& feed_list, | 155 const ScopedVector<gdata::DocumentFeed>& feed_list, |
| 153 int64 start_changestamp, | 156 int64 start_changestamp, |
| 154 int64 root_feed_changestamp); | 157 int64 root_feed_changestamp); |
| 155 | 158 |
| 156 private: | 159 private: |
| 157 // Starts root feed load from the server, with details specified in |params|. | 160 // Starts root feed load from the server, with details specified in |params|. |
| 158 void LoadFromServer(scoped_ptr<LoadFeedParams> params); | 161 void LoadFromServer(scoped_ptr<LoadFeedParams> params); |
| 159 | 162 |
| 160 // Callback for handling root directory refresh from the cache. | 163 // Callback for handling root directory refresh from the cache. |
| 161 void OnProtoLoaded(LoadRootFeedParams* params); | 164 void OnProtoLoaded(LoadRootFeedParams* params); |
| 162 | 165 |
| 163 // Continues handling root directory refresh after the directory service | 166 // Continues handling root directory refresh after the directory service |
| 164 // is fully loaded. | 167 // is fully loaded. |
| 165 void ContinueWithInitializedDirectoryService(LoadRootFeedParams* params, | 168 void ContinueWithInitializedDirectoryService(LoadRootFeedParams* params, |
| 166 DriveFileError error); | 169 DriveFileError error); |
| 167 | 170 |
| 168 // Helper callback for handling results of metadata retrieval initiated from | 171 // Helper callback for handling results of metadata retrieval initiated from |
| 169 // ReloadFeedFromServerIfNeeded(). This method makes a decision about fetching | 172 // ReloadFeedFromServerIfNeeded(). This method makes a decision about fetching |
| 170 // the content of the root feed during the root directory refresh process. | 173 // the content of the root feed during the root directory refresh process. |
| 171 void OnGetAccountMetadata( | 174 void OnGetAccountMetadata( |
| 172 ContentOrigin initial_origin, | 175 ContentOrigin initial_origin, |
| 173 int64 local_changestamp, | 176 int64 local_changestamp, |
| 174 const FileOperationCallback& callback, | 177 const FileOperationCallback& callback, |
| 175 GDataErrorCode status, | 178 gdata::GDataErrorCode status, |
| 176 scoped_ptr<base::Value> feed_data); | 179 scoped_ptr<base::Value> feed_data); |
| 177 | 180 |
| 178 // Helper callback for handling results of account data retrieval initiated | 181 // Helper callback for handling results of account data retrieval initiated |
| 179 // from ReloadFeedFromServerIfNeeded() for Drive V2 API. | 182 // from ReloadFeedFromServerIfNeeded() for Drive V2 API. |
| 180 // This method makes a decision about fetching the content of the root feed | 183 // This method makes a decision about fetching the content of the root feed |
| 181 // during the root directory refresh process. | 184 // during the root directory refresh process. |
| 182 void OnGetAboutResource( | 185 void OnGetAboutResource( |
| 183 ContentOrigin initial_origin, | 186 ContentOrigin initial_origin, |
| 184 int64 local_changestamp, | 187 int64 local_changestamp, |
| 185 const FileOperationCallback& callback, | 188 const FileOperationCallback& callback, |
| 186 GDataErrorCode status, | 189 gdata::GDataErrorCode status, |
| 187 scoped_ptr<base::Value> feed_data); | 190 scoped_ptr<base::Value> feed_data); |
| 188 | 191 |
| 189 // Callback for handling response from |DriveAPIService::GetApplicationInfo|. | 192 // Callback for handling response from |DriveAPIService::GetApplicationInfo|. |
| 190 // If the application list is successfully parsed, passes the list to | 193 // If the application list is successfully parsed, passes the list to |
| 191 // Drive webapps registry. | 194 // Drive webapps registry. |
| 192 void OnGetApplicationList(GDataErrorCode status, | 195 void OnGetApplicationList(gdata::GDataErrorCode status, |
| 193 scoped_ptr<base::Value> json); | 196 scoped_ptr<base::Value> json); |
| 194 | 197 |
| 195 // Callback for handling feed content fetching while searching for file info. | 198 // Callback for handling feed content fetching while searching for file info. |
| 196 // This callback is invoked after async feed fetch operation that was | 199 // This callback is invoked after async feed fetch operation that was |
| 197 // invoked by StartDirectoryRefresh() completes. This callback will update | 200 // invoked by StartDirectoryRefresh() completes. This callback will update |
| 198 // the content of the refreshed directory object and continue initially | 201 // the content of the refreshed directory object and continue initially |
| 199 // started FindEntryByPath() request. | 202 // started FindEntryByPath() request. |
| 200 void OnFeedFromServerLoaded(scoped_ptr<LoadFeedParams> params, | 203 void OnFeedFromServerLoaded(scoped_ptr<LoadFeedParams> params, |
| 201 DriveFileError error); | 204 DriveFileError error); |
| 202 | 205 |
| 203 // Callback for handling response from |GDataWapiService::GetDocuments|. | 206 // Callback for handling response from |GDataWapiService::GetDocuments|. |
| 204 // Invokes |callback| when done. | 207 // Invokes |callback| when done. |
| 205 // |callback| must not be null. | 208 // |callback| must not be null. |
| 206 void OnGetDocuments( | 209 void OnGetDocuments( |
| 207 scoped_ptr<LoadFeedParams> params, | 210 scoped_ptr<LoadFeedParams> params, |
| 208 base::TimeTicks start_time, | 211 base::TimeTicks start_time, |
| 209 GDataErrorCode status, | 212 gdata::GDataErrorCode status, |
| 210 scoped_ptr<base::Value> data); | 213 scoped_ptr<base::Value> data); |
| 211 | 214 |
| 212 // Callback for handling results of feed parse. | 215 // Callback for handling results of feed parse. |
| 213 void OnParseFeed(scoped_ptr<LoadFeedParams> params, | 216 void OnParseFeed(scoped_ptr<LoadFeedParams> params, |
| 214 base::TimeTicks start_time, | 217 base::TimeTicks start_time, |
| 215 scoped_ptr<DocumentFeed>* current_feed); | 218 scoped_ptr<gdata::DocumentFeed>* current_feed); |
| 216 | 219 |
| 217 // Callback for handling response from |DriveAPIService::GetChanglist|. | 220 // Callback for handling response from |DriveAPIService::GetChanglist|. |
| 218 // Invokes |callback| when done. | 221 // Invokes |callback| when done. |
| 219 // |callback| must not be null. | 222 // |callback| must not be null. |
| 220 void OnGetChangelist(scoped_ptr<LoadFeedParams> params, | 223 void OnGetChangelist(scoped_ptr<LoadFeedParams> params, |
| 221 base::TimeTicks start_time, | 224 base::TimeTicks start_time, |
| 222 GDataErrorCode status, | 225 gdata::GDataErrorCode status, |
| 223 scoped_ptr<base::Value> data); | 226 scoped_ptr<base::Value> data); |
| 224 | 227 |
| 225 // Save filesystem to disk. | 228 // Save filesystem to disk. |
| 226 void SaveFileSystem(); | 229 void SaveFileSystem(); |
| 227 | 230 |
| 228 // Callback for handling UI updates caused by document fetching. | 231 // Callback for handling UI updates caused by document fetching. |
| 229 void OnNotifyDocumentFeedFetched( | 232 void OnNotifyDocumentFeedFetched( |
| 230 base::WeakPtr<GetDocumentsUiState> ui_state); | 233 base::WeakPtr<GetDocumentsUiState> ui_state); |
| 231 | 234 |
| 232 DriveResourceMetadata* resource_metadata_; // Not owned. | 235 DriveResourceMetadata* resource_metadata_; // Not owned. |
| 233 DriveServiceInterface* drive_service_; // Not owned. | 236 DriveServiceInterface* drive_service_; // Not owned. |
| 234 DriveWebAppsRegistryInterface* webapps_registry_; // Not owned. | 237 DriveWebAppsRegistryInterface* webapps_registry_; // Not owned. |
| 235 DriveCache* cache_; // Not owned. | 238 DriveCache* cache_; // Not owned. |
| 236 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_; | 239 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_; |
| 237 ObserverList<GDataWapiFeedLoaderObserver> observers_; | 240 ObserverList<GDataWapiFeedLoaderObserver> observers_; |
| 238 | 241 |
| 239 // Note: This should remain the last member so it'll be destroyed and | 242 // Note: This should remain the last member so it'll be destroyed and |
| 240 // invalidate its weak pointers before any other members are destroyed. | 243 // invalidate its weak pointers before any other members are destroyed. |
| 241 base::WeakPtrFactory<GDataWapiFeedLoader> weak_ptr_factory_; | 244 base::WeakPtrFactory<GDataWapiFeedLoader> weak_ptr_factory_; |
| 242 DISALLOW_COPY_AND_ASSIGN(GDataWapiFeedLoader); | 245 DISALLOW_COPY_AND_ASSIGN(GDataWapiFeedLoader); |
| 243 }; | 246 }; |
| 244 | 247 |
| 245 } // namespace gdata | 248 } // namespace drive |
| 246 | 249 |
| 247 #endif // CHROME_BROWSER_CHROMEOS_DRIVE_GDATA_WAPI_FEED_LOADER_H_ | 250 #endif // CHROME_BROWSER_CHROMEOS_DRIVE_GDATA_WAPI_FEED_LOADER_H_ |
| OLD | NEW |