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_directory_service.h" | 11 #include "chrome/browser/chromeos/gdata/gdata_directory_service.h" |
| 12 #include "chrome/browser/chromeos/gdata/gdata_errorcode.h" | 12 #include "chrome/browser/chromeos/gdata/gdata_errorcode.h" |
| 13 | 13 #include "googleurl/src/gurl.h" |
| 14 class GURL; | |
| 15 | 14 |
| 16 namespace base { | 15 namespace base { |
| 17 class Value; | 16 class Value; |
| 18 } | 17 } |
| 19 | 18 |
| 20 namespace gdata { | 19 namespace gdata { |
| 21 | 20 |
| 22 class DriveWebAppsRegistryInterface; | 21 class DriveWebAppsRegistryInterface; |
| 23 class DocumentFeed; | 22 class DocumentFeed; |
| 24 class DocumentsServiceInterface; | 23 class DocumentsServiceInterface; |
| 25 class GDataCache; | 24 class GDataCache; |
| 26 struct GetDocumentsUiState; | 25 struct GetDocumentsUiState; |
| 27 | 26 |
| 28 // Set of parameters sent to LoadDocumentFeedCallback callback. | 27 // Set of parameters sent to LoadDocumentFeedCallback callback. |
| 29 struct GetDocumentsParams { | 28 struct GetDocumentsParams { |
| 30 GetDocumentsParams(int64 start_changestamp, | 29 GetDocumentsParams(int64 start_changestamp, |
| 31 int64 root_feed_changestamp, | 30 int64 root_feed_changestamp, |
| 32 std::vector<DocumentFeed*>* feed_list, | 31 std::vector<DocumentFeed*>* feed_list, |
| 33 bool should_fetch_multiple_feeds, | |
| 34 const std::string& search_query, | 32 const std::string& search_query, |
| 35 const std::string& directory_resource_id, | 33 const std::string& directory_resource_id, |
| 36 const FileOperationCallback& callback, | 34 const FileOperationCallback& callback, |
| 37 GetDocumentsUiState* ui_state); | 35 GetDocumentsUiState* ui_state); |
| 38 ~GetDocumentsParams(); | 36 ~GetDocumentsParams(); |
| 39 | 37 |
| 40 // Changestamps are positive numbers in increasing order. The difference | 38 // Changestamps are positive numbers in increasing order. The difference |
| 41 // between two changestamps is proportional equal to number of items in | 39 // between two changestamps is proportional equal to number of items in |
| 42 // delta feed between them - bigger the difference, more likely bigger | 40 // delta feed between them - bigger the difference, more likely bigger |
| 43 // number of items in delta feeds. | 41 // number of items in delta feeds. |
| 44 int64 start_changestamp; | 42 int64 start_changestamp; |
| 45 int64 root_feed_changestamp; | 43 int64 root_feed_changestamp; |
| 46 scoped_ptr<std::vector<DocumentFeed*> > feed_list; | 44 scoped_ptr<std::vector<DocumentFeed*> > feed_list; |
| 47 // Should we stop after getting first feed chunk, even if there is more | |
| 48 // data. | |
| 49 bool should_fetch_multiple_feeds; | |
| 50 std::string search_query; | 45 std::string search_query; |
| 51 std::string directory_resource_id; | 46 std::string directory_resource_id; |
| 52 FileOperationCallback callback; | 47 FileOperationCallback callback; |
| 53 scoped_ptr<GetDocumentsUiState> ui_state; | 48 scoped_ptr<GetDocumentsUiState> ui_state; |
| 54 }; | 49 }; |
| 55 | 50 |
| 56 // Defines set of parameters sent to callback OnProtoLoaded(). | 51 // Defines set of parameters sent to callback OnProtoLoaded(). |
| 57 struct LoadRootFeedParams { | 52 struct LoadRootFeedParams { |
| 58 LoadRootFeedParams( | 53 LoadRootFeedParams( |
| 59 bool should_load_from_server, | 54 bool should_load_from_server, |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 116 // Then, it will initiate retrieval of the root feed from the server unless | 111 // Then, it will initiate retrieval of the root feed from the server unless |
| 117 // |should_load_from_server| is set to false. |should_load_from_server| is | 112 // |should_load_from_server| is set to false. |should_load_from_server| is |
| 118 // false only for testing. If loading from the server is successful, runs | 113 // false only for testing. If loading from the server is successful, runs |
| 119 // |callback| if it was not previously run (i.e. loading from the cache was | 114 // |callback| if it was not previously run (i.e. loading from the cache was |
| 120 // successful). | 115 // successful). |
| 121 // | 116 // |
| 122 // |callback| may be null. | 117 // |callback| may be null. |
| 123 void LoadFromCache(bool should_load_from_server, | 118 void LoadFromCache(bool should_load_from_server, |
| 124 const FileOperationCallback& callback); | 119 const FileOperationCallback& callback); |
| 125 | 120 |
| 126 // Starts root feed load from the server. Value of |start_changestamp| | 121 // Starts retrieving feed for a specific directory from the server. |
|
satorux1
2012/08/17 11:01:31
please write more function comments. please descri
kochi
2012/08/17 15:56:37
Done.
| |
| 127 // determines the type of feed to load - 0 means root feed, every other | 122 void LoadDirectoryFromServer( |
| 128 // value would trigger delta feed. | |
| 129 // In the case of loading the root feed we use |root_feed_changestamp| as its | |
| 130 // initial changestamp value since it does not come with that info. | |
| 131 // | |
| 132 // When all feeds are loaded, |feed_load_callback| is invoked with the | |
| 133 // retrieved feeds. Then |load_finished_callback| is invoked with the error | |
| 134 // code. | |
| 135 // | |
| 136 // |should_fetch_multiple_feeds| is true iff don't want to stop feed loading | |
| 137 // after we retrieve first feed chunk. | |
| 138 // If invoked as a part of content search, query will be set in | |
| 139 // |search_query|. | |
| 140 // If |feed_to_load| is set, this is feed url that will be used to load feed. | |
| 141 // | |
| 142 // |load_finished_callback| may be null. | |
| 143 // |feed_load_callback| must not be null. | |
| 144 void LoadFromServer( | |
| 145 ContentOrigin initial_origin, | 123 ContentOrigin initial_origin, |
| 146 int64 start_changestamp, | |
| 147 int64 root_feed_changestamp, | |
| 148 bool should_fetch_multiple_feeds, | |
| 149 const std::string& search_query, | |
| 150 const GURL& feed_to_load, | |
| 151 const std::string& directory_resource_id, | 124 const std::string& directory_resource_id, |
| 152 const FileOperationCallback& load_finished_callback, | |
| 153 const LoadDocumentFeedCallback& feed_load_callback); | 125 const LoadDocumentFeedCallback& feed_load_callback); |
| 154 | 126 |
| 127 // Starts retrieving search results from the server. | |
|
satorux1
2012/08/17 11:01:31
more function comment.
kochi
2012/08/17 15:56:37
Done.
| |
| 128 void SearchFromServer(ContentOrigin initial_origin, | |
| 129 const std::string& search_query, | |
| 130 const GURL& next_feed, | |
| 131 const LoadDocumentFeedCallback& feed_load_callback); | |
| 132 | |
| 155 // Retrieves account metadata and determines from the last change timestamp | 133 // Retrieves account metadata and determines from the last change timestamp |
| 156 // if the feed content loading from the server needs to be initiated. | 134 // if the feed content loading from the server needs to be initiated. |
| 157 void ReloadFromServerIfNeeded( | 135 void ReloadFromServerIfNeeded( |
| 158 ContentOrigin initial_origin, | 136 ContentOrigin initial_origin, |
| 159 int64 local_changestamp, | 137 int64 local_changestamp, |
| 160 const FileOperationCallback& callback); | 138 const FileOperationCallback& callback); |
| 161 | 139 |
| 162 // Updates whole directory structure feeds collected in |feed_list|. | 140 // Updates whole directory structure feeds collected in |feed_list|. |
| 163 // On success, returns PLATFORM_FILE_OK. Record file statistics as UMA | 141 // On success, returns PLATFORM_FILE_OK. Record file statistics as UMA |
| 164 // histograms. | 142 // histograms. |
| 165 // | 143 // |
| 166 // See comments at GDataWapiFeedProcessor::ApplyFeeds() for | 144 // See comments at GDataWapiFeedProcessor::ApplyFeeds() for |
| 167 // |start_changestamp| and |root_feed_changestamp|. | 145 // |start_changestamp| and |root_feed_changestamp|. |
| 168 GDataFileError UpdateFromFeed( | 146 GDataFileError UpdateFromFeed( |
| 169 const std::vector<DocumentFeed*>& feed_list, | 147 const std::vector<DocumentFeed*>& feed_list, |
| 170 int64 start_changestamp, | 148 int64 start_changestamp, |
| 171 int64 root_feed_changestamp); | 149 int64 root_feed_changestamp); |
| 172 | 150 |
| 173 private: | 151 private: |
| 152 struct LoadFeedParams; | |
| 153 | |
| 154 // Starts root feed load from the server, with detail specified in |param|. | |
| 155 void LoadFromServer(const LoadFeedParams& param); | |
| 156 | |
| 174 // Callback for handling root directory refresh from the cache. | 157 // Callback for handling root directory refresh from the cache. |
| 175 void OnProtoLoaded(LoadRootFeedParams* params); | 158 void OnProtoLoaded(LoadRootFeedParams* params); |
| 176 | 159 |
| 177 // Continues handling root directory refresh after the directory service | 160 // Continues handling root directory refresh after the directory service |
| 178 // is fully loaded. | 161 // is fully loaded. |
| 179 void ContinueWithInitializedDirectoryService(LoadRootFeedParams* params, | 162 void ContinueWithInitializedDirectoryService(LoadRootFeedParams* params, |
| 180 GDataFileError error); | 163 GDataFileError error); |
| 181 | 164 |
| 182 // Helper callback for handling results of metadata retrieval initiated from | 165 // Helper callback for handling results of metadata retrieval initiated from |
| 183 // ReloadFeedFromServerIfNeeded(). This method makes a decision about fetching | 166 // ReloadFeedFromServerIfNeeded(). This method makes a decision about fetching |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 252 | 235 |
| 253 // Note: This should remain the last member so it'll be destroyed and | 236 // Note: This should remain the last member so it'll be destroyed and |
| 254 // invalidate its weak pointers before any other members are destroyed. | 237 // invalidate its weak pointers before any other members are destroyed. |
| 255 base::WeakPtrFactory<GDataWapiFeedLoader> weak_ptr_factory_; | 238 base::WeakPtrFactory<GDataWapiFeedLoader> weak_ptr_factory_; |
| 256 DISALLOW_COPY_AND_ASSIGN(GDataWapiFeedLoader); | 239 DISALLOW_COPY_AND_ASSIGN(GDataWapiFeedLoader); |
| 257 }; | 240 }; |
| 258 | 241 |
| 259 } // namespace gdata | 242 } // namespace gdata |
| 260 | 243 |
| 261 #endif // CHROME_BROWSER_CHROMEOS_GDATA_GDATA_WAPI_FEED_LOADER_H_ | 244 #endif // CHROME_BROWSER_CHROMEOS_GDATA_GDATA_WAPI_FEED_LOADER_H_ |
| OLD | NEW |