OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef CHROME_BROWSER_CHROMEOS_GDATA_GDATA_WAPI_FEED_LOADER_H_ | |
6 #define CHROME_BROWSER_CHROMEOS_GDATA_GDATA_WAPI_FEED_LOADER_H_ | |
7 | |
8 #include "base/callback.h" | |
9 #include "base/file_path.h" | |
10 #include "base/observer_list.h" | |
11 #include "chrome/browser/chromeos/gdata/gdata_errorcode.h" | |
12 #include "chrome/browser/chromeos/gdata/gdata_files.h" | |
13 | |
14 namespace gdata { | |
15 | |
16 class DriveWebAppsRegistryInterface; | |
17 class DocumentsServiceInterface; | |
18 class GDataCache; | |
19 struct GetDocumentsUiState; | |
20 | |
21 // Set of parameters sent to LoadDocumentFeedCallback callback. | |
22 struct GetDocumentsParams { | |
achuithb
2012/08/04 08:02:35
Any reason why this is in the header file? I think
satorux1
2012/08/04 08:05:28
This has to be here, as this struct is used in gda
| |
23 GetDocumentsParams(int start_changestamp, | |
24 int root_feed_changestamp, | |
25 std::vector<DocumentFeed*>* feed_list, | |
26 bool should_fetch_multiple_feeds, | |
27 const FilePath& search_file_path, | |
28 const std::string& search_query, | |
29 const std::string& directory_resource_id, | |
30 const FindEntryCallback& callback, | |
31 GetDocumentsUiState* ui_state); | |
32 ~GetDocumentsParams(); | |
33 | |
34 // Changestamps are positive numbers in increasing order. The difference | |
35 // between two changestamps is proportional equal to number of items in | |
36 // delta feed between them - bigger the difference, more likely bigger | |
37 // number of items in delta feeds. | |
38 int start_changestamp; | |
39 int root_feed_changestamp; | |
40 scoped_ptr<std::vector<DocumentFeed*> > feed_list; | |
41 // Should we stop after getting first feed chunk, even if there is more | |
42 // data. | |
43 bool should_fetch_multiple_feeds; | |
44 FilePath search_file_path; | |
45 std::string search_query; | |
46 std::string directory_resource_id; | |
47 FindEntryCallback callback; | |
48 scoped_ptr<GetDocumentsUiState> ui_state; | |
49 }; | |
50 | |
51 // Callback run as a response to LoadFromServer. | |
52 typedef base::Callback<void(GetDocumentsParams* params, | |
achuithb
2012/08/04 08:02:35
Don't have to do it in this patch, but I feel like
satorux1
2012/08/04 08:05:28
Not sure if it's better. Nested types result in ve
| |
53 GDataFileError error)> | |
54 LoadDocumentFeedCallback; | |
55 | |
56 // GDataWapiFeedLoader is used to load feeds from WAPI (codename for | |
57 // Documents List API) and load the cached proto file. | |
58 class GDataWapiFeedLoader { | |
59 public: | |
60 // Used to notify events from the loader. | |
61 // All events are notified on UI thread. | |
62 class Observer { | |
63 public: | |
64 // Triggered when a content of a directory has been changed. | |
65 // |directory_path| is a virtual directory path representing the | |
66 // changed directory. | |
67 virtual void OnDirectoryChanged(const FilePath& directory_path) {} | |
68 | |
69 // Triggered when a document feed is fetched. |num_accumulated_entries| | |
70 // tells the number of entries fetched so far. | |
71 virtual void OnDocumentFeedFetched(int num_accumulated_entries) {} | |
72 | |
73 // Triggered when the feed from the server is loaded. | |
74 virtual void OnFeedFromServerLoaded() {} | |
75 | |
76 protected: | |
77 virtual ~Observer() {} | |
78 }; | |
79 | |
80 GDataWapiFeedLoader( | |
81 GDataDirectoryService* directory_service, | |
82 DocumentsServiceInterface* documents_service, | |
83 DriveWebAppsRegistryInterface* webapps_registry, | |
84 GDataCache* cache, | |
85 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_); | |
86 ~GDataWapiFeedLoader(); | |
87 | |
88 // Adds and removes the observer. | |
89 void AddObserver(Observer* observer); | |
90 void RemoveObserver(Observer* observer); | |
91 | |
92 // Starts root feed load from the cache. If successful, it will try to find | |
93 // the file upon retrieval completion. In addition to that, it will | |
94 // initiate retrieval of the root feed from the server unless | |
95 // |should_load_from_server| is set to false. |should_load_from_server| is | |
96 // false only for testing. | |
97 void LoadFromCache(bool should_load_from_server, | |
98 const FilePath& search_file_path, | |
99 const FindEntryCallback& callback); | |
100 | |
101 // Starts root feed load from the server. Value of |start_changestamp| | |
102 // determines the type of feed to load - 0 means root feed, every other | |
103 // value would trigger delta feed. | |
104 // In the case of loading the root feed we use |root_feed_changestamp| as its | |
105 // initial changestamp value since it does not come with that info. | |
106 // When done |load_feed_callback| is invoked. | |
107 // |entry_found_callback| is used only when this is invoked while searching | |
108 // for file info, and is used in |load_feed_callback|. If successful, it will | |
109 // try to find the file upon retrieval completion. | |
110 // |should_fetch_multiple_feeds| is true iff don't want to stop feed loading | |
111 // after we retrieve first feed chunk. | |
112 // If invoked as a part of content search, query will be set in | |
113 // |search_query|. | |
114 // If |feed_to_load| is set, this is feed url that will be used to load feed. | |
115 void LoadFromServer( | |
116 ContentOrigin initial_origin, | |
117 int start_changestamp, | |
118 int root_feed_changestamp, | |
119 bool should_fetch_multiple_feeds, | |
120 const FilePath& search_file_path, | |
121 const std::string& search_query, | |
122 const GURL& feed_to_load, | |
123 const std::string& directory_resource_id, | |
124 const FindEntryCallback& entry_found_callback, | |
125 const LoadDocumentFeedCallback& feed_load_callback); | |
126 | |
127 // Retrieves account metadata and determines from the last change timestamp | |
128 // if the feed content loading from the server needs to be initiated. | |
129 void ReloadFromServerIfNeeded( | |
130 ContentOrigin initial_origin, | |
131 int local_changestamp, | |
132 const FilePath& search_file_path, | |
133 const FindEntryCallback& callback); | |
134 | |
135 // Updates whole directory structure feeds collected in |feed_list|. | |
136 // On success, returns PLATFORM_FILE_OK. Record file statistics as UMA | |
137 // histograms. | |
138 // | |
139 // See comments at GDataWapiFeedProcessor::ApplyFeeds() for | |
140 // |start_changestamp| and |root_feed_changestamp|. | |
141 GDataFileError UpdateFromFeed( | |
142 const std::vector<DocumentFeed*>& feed_list, | |
143 int start_changestamp, | |
144 int root_feed_changestamp); | |
145 | |
146 private: | |
147 // Callback for handling root directory refresh from the cache. | |
148 void OnProtoLoaded(LoadRootFeedParams* params); | |
149 | |
150 // Continues handling root directory refresh after the directory service | |
151 // is fully loaded. | |
152 void ContinueWithInitializedDirectoryService(LoadRootFeedParams* params, | |
153 GDataFileError error); | |
154 | |
155 // Helper callback for handling results of metadata retrieval initiated from | |
156 // ReloadFeedFromServerIfNeeded(). This method makes a decision about fetching | |
157 // the content of the root feed during the root directory refresh process. | |
158 void OnGetAccountMetadata( | |
159 ContentOrigin initial_origin, | |
160 int local_changestamp, | |
161 const FilePath& search_file_path, | |
162 const FindEntryCallback& callback, | |
163 GDataErrorCode status, | |
164 scoped_ptr<base::Value> feed_data); | |
165 | |
166 // Callback for handling feed content fetching while searching for file info. | |
167 // This callback is invoked after async feed fetch operation that was | |
168 // invoked by StartDirectoryRefresh() completes. This callback will update | |
169 // the content of the refreshed directory object and continue initially | |
170 // started FindEntryByPath() request. | |
171 void OnFeedFromServerLoaded(GetDocumentsParams* params, | |
172 GDataFileError error); | |
173 | |
174 // Callback for handling response from |GDataDocumentsService::GetDocuments|. | |
175 // Invokes |callback| when done. | |
176 void OnGetDocuments( | |
177 ContentOrigin initial_origin, | |
178 const LoadDocumentFeedCallback& callback, | |
179 GetDocumentsParams* params, | |
180 base::TimeTicks start_time, | |
181 GDataErrorCode status, | |
182 scoped_ptr<base::Value> data); | |
183 | |
184 // Save filesystem to disk. | |
185 void SaveFileSystem(); | |
186 | |
187 // Callback for handling UI updates caused by document fetching. | |
188 void OnNotifyDocumentFeedFetched( | |
189 base::WeakPtr<GetDocumentsUiState> ui_state); | |
190 | |
191 GDataDirectoryService* directory_service_; // Not owned. | |
192 DocumentsServiceInterface* documents_service_; // Not owned. | |
193 DriveWebAppsRegistryInterface* webapps_registry_; // Not owned. | |
194 GDataCache* cache_; // Not owned. | |
195 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_; | |
196 ObserverList<Observer> observers_; | |
197 | |
198 // Note: This should remain the last member so it'll be destroyed and | |
199 // invalidate its weak pointers before any other members are destroyed. | |
200 base::WeakPtrFactory<GDataWapiFeedLoader> weak_ptr_factory_; | |
201 DISALLOW_COPY_AND_ASSIGN(GDataWapiFeedLoader); | |
202 }; | |
203 | |
204 } // namespace gdata | |
205 | |
206 #endif // CHROME_BROWSER_CHROMEOS_GDATA_GDATA_WAPI_FEED_LOADER_H_ | |
OLD | NEW |