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