| 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_GDATA_GDATA_WAPI_FEED_LOADER_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_GDATA_GDATA_WAPI_FEED_LOADER_H_ |
| 6 #define CHROME_BROWSER_CHROMEOS_GDATA_GDATA_WAPI_FEED_LOADER_H_ | 6 #define CHROME_BROWSER_CHROMEOS_GDATA_GDATA_WAPI_FEED_LOADER_H_ |
| 7 | 7 |
| 8 #include "base/callback.h" | 8 #include "base/callback.h" |
| 9 #include "base/file_path.h" | 9 #include "base/file_path.h" |
| 10 #include "base/observer_list.h" | 10 #include "base/observer_list.h" |
| 11 #include "chrome/browser/chromeos/gdata/gdata_errorcode.h" | 11 #include "chrome/browser/chromeos/gdata/gdata_errorcode.h" |
| 12 #include "chrome/browser/chromeos/gdata/gdata_files.h" | 12 #include "chrome/browser/chromeos/gdata/gdata_files.h" |
| 13 | 13 |
| 14 namespace gdata { | 14 namespace gdata { |
| 15 | 15 |
| 16 class DriveWebAppsRegistryInterface; | 16 class DriveWebAppsRegistryInterface; |
| 17 class DocumentsServiceInterface; | 17 class DocumentsServiceInterface; |
| 18 class GDataCache; | 18 class GDataCache; |
| 19 struct GetDocumentsUiState; | 19 struct GetDocumentsUiState; |
| 20 | 20 |
| 21 // Set of parameters sent to LoadDocumentFeedCallback callback. | 21 // Set of parameters sent to LoadDocumentFeedCallback callback. |
| 22 struct GetDocumentsParams { | 22 struct GetDocumentsParams { |
| 23 GetDocumentsParams(int64 start_changestamp, | 23 GetDocumentsParams(int64 start_changestamp, |
| 24 int64 root_feed_changestamp, | 24 int64 root_feed_changestamp, |
| 25 std::vector<DocumentFeed*>* feed_list, | 25 std::vector<DocumentFeed*>* feed_list, |
| 26 bool should_fetch_multiple_feeds, | 26 bool should_fetch_multiple_feeds, |
| 27 const FilePath& search_file_path, | |
| 28 const std::string& search_query, | 27 const std::string& search_query, |
| 29 const std::string& directory_resource_id, | 28 const std::string& directory_resource_id, |
| 30 const FindEntryCallback& callback, | 29 const FileOperationCallback& callback, |
| 31 GetDocumentsUiState* ui_state); | 30 GetDocumentsUiState* ui_state); |
| 32 ~GetDocumentsParams(); | 31 ~GetDocumentsParams(); |
| 33 | 32 |
| 34 // Changestamps are positive numbers in increasing order. The difference | 33 // Changestamps are positive numbers in increasing order. The difference |
| 35 // between two changestamps is proportional equal to number of items in | 34 // between two changestamps is proportional equal to number of items in |
| 36 // delta feed between them - bigger the difference, more likely bigger | 35 // delta feed between them - bigger the difference, more likely bigger |
| 37 // number of items in delta feeds. | 36 // number of items in delta feeds. |
| 38 int64 start_changestamp; | 37 int64 start_changestamp; |
| 39 int64 root_feed_changestamp; | 38 int64 root_feed_changestamp; |
| 40 scoped_ptr<std::vector<DocumentFeed*> > feed_list; | 39 scoped_ptr<std::vector<DocumentFeed*> > feed_list; |
| 41 // Should we stop after getting first feed chunk, even if there is more | 40 // Should we stop after getting first feed chunk, even if there is more |
| 42 // data. | 41 // data. |
| 43 bool should_fetch_multiple_feeds; | 42 bool should_fetch_multiple_feeds; |
| 44 FilePath search_file_path; | |
| 45 std::string search_query; | 43 std::string search_query; |
| 46 std::string directory_resource_id; | 44 std::string directory_resource_id; |
| 47 FindEntryCallback callback; | 45 FileOperationCallback callback; |
| 48 scoped_ptr<GetDocumentsUiState> ui_state; | 46 scoped_ptr<GetDocumentsUiState> ui_state; |
| 49 }; | 47 }; |
| 50 | 48 |
| 51 // Defines set of parameters sent to callback OnProtoLoaded(). | 49 // Defines set of parameters sent to callback OnProtoLoaded(). |
| 52 struct LoadRootFeedParams { | 50 struct LoadRootFeedParams { |
| 53 LoadRootFeedParams( | 51 LoadRootFeedParams( |
| 54 FilePath search_file_path, | |
| 55 bool should_load_from_server, | 52 bool should_load_from_server, |
| 56 const FindEntryCallback& callback); | 53 const FileOperationCallback& callback); |
| 57 ~LoadRootFeedParams(); | 54 ~LoadRootFeedParams(); |
| 58 | 55 |
| 59 FilePath search_file_path; | |
| 60 bool should_load_from_server; | 56 bool should_load_from_server; |
| 61 std::string proto; | 57 std::string proto; |
| 62 GDataFileError load_error; | 58 GDataFileError load_error; |
| 63 base::Time last_modified; | 59 base::Time last_modified; |
| 64 // Time when filesystem began to be loaded from disk. | 60 // Time when filesystem began to be loaded from disk. |
| 65 base::Time load_start_time; | 61 base::Time load_start_time; |
| 66 const FindEntryCallback callback; | 62 const FileOperationCallback callback; |
| 67 }; | 63 }; |
| 68 | 64 |
| 69 // Callback run as a response to LoadFromServer. | 65 // Callback run as a response to LoadFromServer. |
| 70 typedef base::Callback<void(GetDocumentsParams* params, | 66 typedef base::Callback<void(GetDocumentsParams* params, |
| 71 GDataFileError error)> | 67 GDataFileError error)> |
| 72 LoadDocumentFeedCallback; | 68 LoadDocumentFeedCallback; |
| 73 | 69 |
| 74 // GDataWapiFeedLoader is used to load feeds from WAPI (codename for | 70 // GDataWapiFeedLoader is used to load feeds from WAPI (codename for |
| 75 // Documents List API) and load the cached proto file. | 71 // Documents List API) and load the cached proto file. |
| 76 class GDataWapiFeedLoader { | 72 class GDataWapiFeedLoader { |
| (...skipping 23 matching lines...) Expand all Loading... |
| 100 DocumentsServiceInterface* documents_service, | 96 DocumentsServiceInterface* documents_service, |
| 101 DriveWebAppsRegistryInterface* webapps_registry, | 97 DriveWebAppsRegistryInterface* webapps_registry, |
| 102 GDataCache* cache, | 98 GDataCache* cache, |
| 103 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_); | 99 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_); |
| 104 ~GDataWapiFeedLoader(); | 100 ~GDataWapiFeedLoader(); |
| 105 | 101 |
| 106 // Adds and removes the observer. | 102 // Adds and removes the observer. |
| 107 void AddObserver(Observer* observer); | 103 void AddObserver(Observer* observer); |
| 108 void RemoveObserver(Observer* observer); | 104 void RemoveObserver(Observer* observer); |
| 109 | 105 |
| 110 // Starts root feed load from the cache. If successful, it will try to find | 106 // Starts root feed load from the cache. If successful, runs |callback| to |
| 111 // the file upon retrieval completion. In addition to that, it will | 107 // tell the caller that the loading was successful. |
| 112 // initiate retrieval of the root feed from the server unless | 108 // |
| 109 // Then, it will initiate retrieval of the root feed from the server unless |
| 113 // |should_load_from_server| is set to false. |should_load_from_server| is | 110 // |should_load_from_server| is set to false. |should_load_from_server| is |
| 114 // false only for testing. | 111 // false only for testing. If loading from the server is successful, runs |
| 112 // |callback| if it was not previously run (i.e. loading from the cache was |
| 113 // successful). |
| 114 // |
| 115 // |callback| may be null. |
| 115 void LoadFromCache(bool should_load_from_server, | 116 void LoadFromCache(bool should_load_from_server, |
| 116 const FilePath& search_file_path, | 117 const FileOperationCallback& callback); |
| 117 const FindEntryCallback& callback); | |
| 118 | 118 |
| 119 // Starts root feed load from the server. Value of |start_changestamp| | 119 // Starts root feed load from the server. Value of |start_changestamp| |
| 120 // determines the type of feed to load - 0 means root feed, every other | 120 // determines the type of feed to load - 0 means root feed, every other |
| 121 // value would trigger delta feed. | 121 // value would trigger delta feed. |
| 122 // In the case of loading the root feed we use |root_feed_changestamp| as its | 122 // In the case of loading the root feed we use |root_feed_changestamp| as its |
| 123 // initial changestamp value since it does not come with that info. | 123 // initial changestamp value since it does not come with that info. |
| 124 // When done |load_feed_callback| is invoked. | 124 // |
| 125 // |entry_found_callback| is used only when this is invoked while searching | 125 // When all feeds are loaded, |feed_load_callback| is invoked with the |
| 126 // for file info, and is used in |load_feed_callback|. If successful, it will | 126 // retrieved feeds. Then |load_finished_callback| is invoked with the error |
| 127 // try to find the file upon retrieval completion. | 127 // code. |
| 128 // |
| 128 // |should_fetch_multiple_feeds| is true iff don't want to stop feed loading | 129 // |should_fetch_multiple_feeds| is true iff don't want to stop feed loading |
| 129 // after we retrieve first feed chunk. | 130 // after we retrieve first feed chunk. |
| 130 // If invoked as a part of content search, query will be set in | 131 // If invoked as a part of content search, query will be set in |
| 131 // |search_query|. | 132 // |search_query|. |
| 132 // If |feed_to_load| is set, this is feed url that will be used to load feed. | 133 // If |feed_to_load| is set, this is feed url that will be used to load feed. |
| 134 // |
| 135 // |load_finished_callback| may be null. |
| 136 // |feed_load_callback| must not be null. |
| 133 void LoadFromServer( | 137 void LoadFromServer( |
| 134 ContentOrigin initial_origin, | 138 ContentOrigin initial_origin, |
| 135 int64 start_changestamp, | 139 int64 start_changestamp, |
| 136 int64 root_feed_changestamp, | 140 int64 root_feed_changestamp, |
| 137 bool should_fetch_multiple_feeds, | 141 bool should_fetch_multiple_feeds, |
| 138 const FilePath& search_file_path, | |
| 139 const std::string& search_query, | 142 const std::string& search_query, |
| 140 const GURL& feed_to_load, | 143 const GURL& feed_to_load, |
| 141 const std::string& directory_resource_id, | 144 const std::string& directory_resource_id, |
| 142 const FindEntryCallback& entry_found_callback, | 145 const FileOperationCallback& load_finished_callback, |
| 143 const LoadDocumentFeedCallback& feed_load_callback); | 146 const LoadDocumentFeedCallback& feed_load_callback); |
| 144 | 147 |
| 145 // Retrieves account metadata and determines from the last change timestamp | 148 // Retrieves account metadata and determines from the last change timestamp |
| 146 // if the feed content loading from the server needs to be initiated. | 149 // if the feed content loading from the server needs to be initiated. |
| 147 void ReloadFromServerIfNeeded( | 150 void ReloadFromServerIfNeeded( |
| 148 ContentOrigin initial_origin, | 151 ContentOrigin initial_origin, |
| 149 int64 local_changestamp, | 152 int64 local_changestamp, |
| 150 const FilePath& search_file_path, | 153 const FileOperationCallback& callback); |
| 151 const FindEntryCallback& callback); | |
| 152 | 154 |
| 153 // Updates whole directory structure feeds collected in |feed_list|. | 155 // Updates whole directory structure feeds collected in |feed_list|. |
| 154 // On success, returns PLATFORM_FILE_OK. Record file statistics as UMA | 156 // On success, returns PLATFORM_FILE_OK. Record file statistics as UMA |
| 155 // histograms. | 157 // histograms. |
| 156 // | 158 // |
| 157 // See comments at GDataWapiFeedProcessor::ApplyFeeds() for | 159 // See comments at GDataWapiFeedProcessor::ApplyFeeds() for |
| 158 // |start_changestamp| and |root_feed_changestamp|. | 160 // |start_changestamp| and |root_feed_changestamp|. |
| 159 GDataFileError UpdateFromFeed( | 161 GDataFileError UpdateFromFeed( |
| 160 const std::vector<DocumentFeed*>& feed_list, | 162 const std::vector<DocumentFeed*>& feed_list, |
| 161 int64 start_changestamp, | 163 int64 start_changestamp, |
| 162 int64 root_feed_changestamp); | 164 int64 root_feed_changestamp); |
| 163 | 165 |
| 164 private: | 166 private: |
| 165 // Callback for handling root directory refresh from the cache. | 167 // Callback for handling root directory refresh from the cache. |
| 166 void OnProtoLoaded(LoadRootFeedParams* params); | 168 void OnProtoLoaded(LoadRootFeedParams* params); |
| 167 | 169 |
| 168 // Continues handling root directory refresh after the directory service | 170 // Continues handling root directory refresh after the directory service |
| 169 // is fully loaded. | 171 // is fully loaded. |
| 170 void ContinueWithInitializedDirectoryService(LoadRootFeedParams* params, | 172 void ContinueWithInitializedDirectoryService(LoadRootFeedParams* params, |
| 171 GDataFileError error); | 173 GDataFileError error); |
| 172 | 174 |
| 173 // Helper callback for handling results of metadata retrieval initiated from | 175 // Helper callback for handling results of metadata retrieval initiated from |
| 174 // ReloadFeedFromServerIfNeeded(). This method makes a decision about fetching | 176 // ReloadFeedFromServerIfNeeded(). This method makes a decision about fetching |
| 175 // the content of the root feed during the root directory refresh process. | 177 // the content of the root feed during the root directory refresh process. |
| 176 void OnGetAccountMetadata( | 178 void OnGetAccountMetadata( |
| 177 ContentOrigin initial_origin, | 179 ContentOrigin initial_origin, |
| 178 int64 local_changestamp, | 180 int64 local_changestamp, |
| 179 const FilePath& search_file_path, | 181 const FileOperationCallback& callback, |
| 180 const FindEntryCallback& callback, | |
| 181 GDataErrorCode status, | 182 GDataErrorCode status, |
| 182 scoped_ptr<base::Value> feed_data); | 183 scoped_ptr<base::Value> feed_data); |
| 183 | 184 |
| 184 // Helper callback for handling results of account data retrieval initiated | 185 // Helper callback for handling results of account data retrieval initiated |
| 185 // from ReloadFeedFromServerIfNeeded() for Drive V2 API. | 186 // from ReloadFeedFromServerIfNeeded() for Drive V2 API. |
| 186 // This method makes a decision about fetching the content of the root feed | 187 // This method makes a decision about fetching the content of the root feed |
| 187 // during the root directory refresh process. | 188 // during the root directory refresh process. |
| 188 void OnGetAboutResource( | 189 void OnGetAboutResource( |
| 189 ContentOrigin initial_origin, | 190 ContentOrigin initial_origin, |
| 190 int64 local_changestamp, | 191 int64 local_changestamp, |
| 191 const FilePath& search_file_path, | 192 const FileOperationCallback& callback, |
| 192 const FindEntryCallback& callback, | |
| 193 GDataErrorCode status, | 193 GDataErrorCode status, |
| 194 scoped_ptr<base::Value> feed_data); | 194 scoped_ptr<base::Value> feed_data); |
| 195 | 195 |
| 196 // Callback for handling feed content fetching while searching for file info. | 196 // Callback for handling feed content fetching while searching for file info. |
| 197 // This callback is invoked after async feed fetch operation that was | 197 // This callback is invoked after async feed fetch operation that was |
| 198 // invoked by StartDirectoryRefresh() completes. This callback will update | 198 // invoked by StartDirectoryRefresh() completes. This callback will update |
| 199 // the content of the refreshed directory object and continue initially | 199 // the content of the refreshed directory object and continue initially |
| 200 // started FindEntryByPath() request. | 200 // started FindEntryByPath() request. |
| 201 void OnFeedFromServerLoaded(GetDocumentsParams* params, | 201 void OnFeedFromServerLoaded(GetDocumentsParams* params, |
| 202 GDataFileError error); | 202 GDataFileError error); |
| 203 | 203 |
| 204 // Callback for handling response from |GDataDocumentsService::GetDocuments|. | 204 // Callback for handling response from |GDataDocumentsService::GetDocuments|. |
| 205 // Invokes |callback| when done. | 205 // Invokes |callback| when done. |
| 206 // |callback| must not be null. |
| 206 void OnGetDocuments( | 207 void OnGetDocuments( |
| 207 ContentOrigin initial_origin, | 208 ContentOrigin initial_origin, |
| 208 const LoadDocumentFeedCallback& callback, | 209 const LoadDocumentFeedCallback& callback, |
| 209 GetDocumentsParams* params, | 210 GetDocumentsParams* params, |
| 210 base::TimeTicks start_time, | 211 base::TimeTicks start_time, |
| 211 GDataErrorCode status, | 212 GDataErrorCode status, |
| 212 scoped_ptr<base::Value> data); | 213 scoped_ptr<base::Value> data); |
| 213 | 214 |
| 214 // Callback for handling response from |GDataDocumentsService::GetChanglist|. | 215 // Callback for handling response from |GDataDocumentsService::GetChanglist|. |
| 215 // Invokes |callback| when done. | 216 // Invokes |callback| when done. |
| 217 // |callback| must not be null. |
| 216 void OnGetChangelist(ContentOrigin initial_origin, | 218 void OnGetChangelist(ContentOrigin initial_origin, |
| 217 const LoadDocumentFeedCallback& callback, | 219 const LoadDocumentFeedCallback& callback, |
| 218 GetDocumentsParams* params, | 220 GetDocumentsParams* params, |
| 219 base::TimeTicks start_time, | 221 base::TimeTicks start_time, |
| 220 GDataErrorCode status, | 222 GDataErrorCode status, |
| 221 scoped_ptr<base::Value> data); | 223 scoped_ptr<base::Value> data); |
| 222 | 224 |
| 223 // Save filesystem to disk. | 225 // Save filesystem to disk. |
| 224 void SaveFileSystem(); | 226 void SaveFileSystem(); |
| 225 | 227 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 236 | 238 |
| 237 // Note: This should remain the last member so it'll be destroyed and | 239 // Note: This should remain the last member so it'll be destroyed and |
| 238 // invalidate its weak pointers before any other members are destroyed. | 240 // invalidate its weak pointers before any other members are destroyed. |
| 239 base::WeakPtrFactory<GDataWapiFeedLoader> weak_ptr_factory_; | 241 base::WeakPtrFactory<GDataWapiFeedLoader> weak_ptr_factory_; |
| 240 DISALLOW_COPY_AND_ASSIGN(GDataWapiFeedLoader); | 242 DISALLOW_COPY_AND_ASSIGN(GDataWapiFeedLoader); |
| 241 }; | 243 }; |
| 242 | 244 |
| 243 } // namespace gdata | 245 } // namespace gdata |
| 244 | 246 |
| 245 #endif // CHROME_BROWSER_CHROMEOS_GDATA_GDATA_WAPI_FEED_LOADER_H_ | 247 #endif // CHROME_BROWSER_CHROMEOS_GDATA_GDATA_WAPI_FEED_LOADER_H_ |
| OLD | NEW |