Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(162)

Side by Side Diff: chrome/browser/chromeos/drive/drive_sync_client.h

Issue 11620007: Switch from OnIPAddressChanged and OnConnectionTypeChange to OnNetworkChanged Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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_DRIVE_SYNC_CLIENT_H_ 5 #ifndef CHROME_BROWSER_CHROMEOS_DRIVE_DRIVE_SYNC_CLIENT_H_
6 #define CHROME_BROWSER_CHROMEOS_DRIVE_DRIVE_SYNC_CLIENT_H_ 6 #define CHROME_BROWSER_CHROMEOS_DRIVE_DRIVE_SYNC_CLIENT_H_
7 7
8 #include <deque> 8 #include <deque>
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
(...skipping 26 matching lines...) Expand all
37 // 37 //
38 // When the user unpins files on Drive, this client is notified about the 38 // When the user unpins files on Drive, this client is notified about the
39 // files that get unpinned, cancels tasks if these are still in the queue. 39 // files that get unpinned, cancels tasks if these are still in the queue.
40 // 40 //
41 // If the user logs out before fetching of the pinned files is complete, this 41 // If the user logs out before fetching of the pinned files is complete, this
42 // client resumes fetching operations next time the user logs in, based on 42 // client resumes fetching operations next time the user logs in, based on
43 // the states left in the cache. 43 // the states left in the cache.
44 class DriveSyncClient 44 class DriveSyncClient
45 : public DriveFileSystemObserver, 45 : public DriveFileSystemObserver,
46 public DriveCacheObserver, 46 public DriveCacheObserver,
47 public net::NetworkChangeNotifier::ConnectionTypeObserver { 47 public net::NetworkChangeNotifier::NetworkChangeObserver {
48 public: 48 public:
49 // Types of sync tasks. 49 // Types of sync tasks.
50 enum SyncType { 50 enum SyncType {
51 FETCH, // Fetch a file from the Drive server. 51 FETCH, // Fetch a file from the Drive server.
52 UPLOAD, // Upload a file to the Drive server. 52 UPLOAD, // Upload a file to the Drive server.
53 }; 53 };
54 54
55 // The struct is used to queue tasks for fetching and uploading. 55 // The struct is used to queue tasks for fetching and uploading.
56 struct SyncTask { 56 struct SyncTask {
57 SyncTask(SyncType in_sync_type, 57 SyncTask(SyncType in_sync_type,
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 void AddResourceIdForTesting(SyncType sync_type, 107 void AddResourceIdForTesting(SyncType sync_type,
108 const std::string& resource_id) { 108 const std::string& resource_id) {
109 queue_.push_back(SyncTask(sync_type, resource_id, base::Time::Now())); 109 queue_.push_back(SyncTask(sync_type, resource_id, base::Time::Now()));
110 } 110 }
111 111
112 // Sets a delay for testing. 112 // Sets a delay for testing.
113 void set_delay_for_testing(const base::TimeDelta& delay) { 113 void set_delay_for_testing(const base::TimeDelta& delay) {
114 delay_ = delay; 114 delay_ = delay;
115 } 115 }
116 116
117 // Starts the sync loop if it's not running. 117 // Starts the sync loop if it's not running. |force_offline| implies there
118 void StartSyncLoop(); 118 // is no usable network connection.
119 void StartSyncLoop(bool force_offline);
119 120
120 private: 121 private:
121 friend class DriveSyncClientTest; 122 friend class DriveSyncClientTest;
122 123
123 // Adds the given task to the queue. If the same task is queued, remove the 124 // Adds the given task to the queue. If the same task is queued, remove the
124 // existing one, and adds a new one to the end of the queue. 125 // existing one, and adds a new one to the end of the queue.
125 void AddTaskToQueue(const SyncTask& sync_task); 126 void AddTaskToQueue(const SyncTask& sync_task);
126 127
127 // Runs the sync loop that fetches/uploads files in |queue_|. One file is 128 // Runs the sync loop that fetches/uploads files in |queue_|. One file is
128 // fetched/uploaded at a time, rather than in parallel. The loop ends when 129 // fetched/uploaded at a time, rather than in parallel. The loop ends when
129 // the queue becomes empty. 130 // the queue becomes empty. |force_offline| implies there is no usable network
130 void DoSyncLoop(); 131 // connection.
132 void DoSyncLoop(bool force_offline);
131 133
132 // Returns true if we should stop the sync loop. 134 // Returns true if we should stop the sync loop. |force_offline| implies there
133 bool ShouldStopSyncLoop(); 135 // is no usable network connection.
136 bool ShouldStopSyncLoop(bool force_offline);
134 137
135 // Called when the resource IDs of files in the backlog are obtained. 138 // Called when the resource IDs of files in the backlog are obtained.
136 void OnGetResourceIdsOfBacklog(const std::vector<std::string>* to_fetch, 139 void OnGetResourceIdsOfBacklog(const std::vector<std::string>* to_fetch,
137 const std::vector<std::string>* to_upload); 140 const std::vector<std::string>* to_upload);
138 141
139 // Called when the resource ID of a pinned file is obtained. 142 // Called when the resource ID of a pinned file is obtained.
140 void OnGetResourceIdOfExistingPinnedFile(const std::string& resource_id, 143 void OnGetResourceIdOfExistingPinnedFile(const std::string& resource_id,
141 const DriveCacheEntry& cache_entry); 144 const DriveCacheEntry& cache_entry);
142 145
143 // Called when a file entry is obtained. 146 // Called when a file entry is obtained.
(...skipping 24 matching lines...) Expand all
168 DriveFileType file_type); 171 DriveFileType file_type);
169 172
170 // Called when the file for |resource_id| is uploaded. 173 // Called when the file for |resource_id| is uploaded.
171 // Calls DoSyncLoop() to go back to the sync loop. 174 // Calls DoSyncLoop() to go back to the sync loop.
172 void OnUploadFileComplete(const std::string& resource_id, 175 void OnUploadFileComplete(const std::string& resource_id,
173 DriveFileError error); 176 DriveFileError error);
174 177
175 // Called on prefs changes. 178 // Called on prefs changes.
176 void OnDriveSyncPreferenceChanged(); 179 void OnDriveSyncPreferenceChanged();
177 180
178 // net::NetworkChangeNotifier::ConnectionTypeObserver override. 181 // net::NetworkChangeNotifier::NetworkChangeObserver override.
179 virtual void OnConnectionTypeChanged( 182 virtual void OnNetworkChanged(
180 net::NetworkChangeNotifier::ConnectionType type) OVERRIDE; 183 net::NetworkChangeNotifier::ConnectionType type) OVERRIDE;
181 184
182 Profile* profile_; 185 Profile* profile_;
183 DriveFileSystemInterface* file_system_; // Owned by DriveSystemService. 186 DriveFileSystemInterface* file_system_; // Owned by DriveSystemService.
184 DriveCache* cache_; // Owned by DriveSystemService. 187 DriveCache* cache_; // Owned by DriveSystemService.
185 scoped_ptr<PrefChangeRegistrar> registrar_; 188 scoped_ptr<PrefChangeRegistrar> registrar_;
186 ObserverList<DriveSyncClientObserver> observers_; 189 ObserverList<DriveSyncClientObserver> observers_;
187 190
188 // The queue of tasks used to fetch/upload files in the background 191 // The queue of tasks used to fetch/upload files in the background
189 // thread. Note that this class does not use a lock to protect |queue_| as 192 // thread. Note that this class does not use a lock to protect |queue_| as
190 // all methods touching |queue_| run on the UI thread. 193 // all methods touching |queue_| run on the UI thread.
191 std::deque<SyncTask> queue_; 194 std::deque<SyncTask> queue_;
192 195
193 // The delay is used for delaying processing SyncTasks in DoSyncLoop(). 196 // The delay is used for delaying processing SyncTasks in DoSyncLoop().
194 base::TimeDelta delay_; 197 base::TimeDelta delay_;
195 198
196 // True if the sync loop is running. 199 // True if the sync loop is running.
197 bool sync_loop_is_running_; 200 bool sync_loop_is_running_;
198 201
199 // Note: This should remain the last member so it'll be destroyed and 202 // Note: This should remain the last member so it'll be destroyed and
200 // invalidate its weak pointers before any other members are destroyed. 203 // invalidate its weak pointers before any other members are destroyed.
201 base::WeakPtrFactory<DriveSyncClient> weak_ptr_factory_; 204 base::WeakPtrFactory<DriveSyncClient> weak_ptr_factory_;
202 205
203 DISALLOW_COPY_AND_ASSIGN(DriveSyncClient); 206 DISALLOW_COPY_AND_ASSIGN(DriveSyncClient);
204 }; 207 };
205 208
206 } // namespace drive 209 } // namespace drive
207 210
208 #endif // CHROME_BROWSER_CHROMEOS_DRIVE_DRIVE_SYNC_CLIENT_H_ 211 #endif // CHROME_BROWSER_CHROMEOS_DRIVE_DRIVE_SYNC_CLIENT_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698