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_SYNC_FILE_SYSTEM_DRIVE_FILE_SYNC_SERVICE_H_ | 5 #ifndef CHROME_BROWSER_SYNC_FILE_SYSTEM_DRIVE_FILE_SYNC_SERVICE_H_ |
6 #define CHROME_BROWSER_SYNC_FILE_SYSTEM_DRIVE_FILE_SYNC_SERVICE_H_ | 6 #define CHROME_BROWSER_SYNC_FILE_SYSTEM_DRIVE_FILE_SYNC_SERVICE_H_ |
7 | 7 |
8 #include <deque> | 8 #include <deque> |
9 #include <map> | 9 #include <map> |
10 #include <queue> | 10 #include <queue> |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 | 101 |
102 struct RemoteChangeComparator { | 102 struct RemoteChangeComparator { |
103 bool operator()(const RemoteChange& left, const RemoteChange& right); | 103 bool operator()(const RemoteChange& left, const RemoteChange& right); |
104 }; | 104 }; |
105 | 105 |
106 typedef std::priority_queue<RemoteChange, std::vector<RemoteChange>, | 106 typedef std::priority_queue<RemoteChange, std::vector<RemoteChange>, |
107 RemoteChangeComparator> ChangeQueue; | 107 RemoteChangeComparator> ChangeQueue; |
108 typedef std::map<FilePath, int64> PathToChangeStamp; | 108 typedef std::map<FilePath, int64> PathToChangeStamp; |
109 typedef std::map<GURL, PathToChangeStamp> ChangeStampMap; | 109 typedef std::map<GURL, PathToChangeStamp> ChangeStampMap; |
110 | 110 |
| 111 // Task types; used for task token handling. |
| 112 enum TaskType { |
| 113 // No task is holding this token. |
| 114 TASK_TYPE_NONE, |
| 115 |
| 116 // Token is granted for drive-related async task. |
| 117 TASK_TYPE_DRIVE, |
| 118 |
| 119 // Token is granted for async database task. |
| 120 TASK_TYPE_DATABASE, |
| 121 }; |
| 122 |
111 DriveFileSyncService(scoped_ptr<DriveFileSyncClient> sync_client, | 123 DriveFileSyncService(scoped_ptr<DriveFileSyncClient> sync_client, |
112 scoped_ptr<DriveMetadataStore> metadata_store); | 124 scoped_ptr<DriveMetadataStore> metadata_store); |
113 | 125 |
114 scoped_ptr<TaskToken> GetToken(const tracked_objects::Location& from_here); | 126 // This should be called when an async task needs to get a task token. |
| 127 // |task_description| is optional but should give human-readable |
| 128 // messages that describe the task that is acquiring the token. |
| 129 scoped_ptr<TaskToken> GetToken(const tracked_objects::Location& from_here, |
| 130 TaskType task_type, |
| 131 const std::string& task_description); |
115 void NotifyTaskDone(fileapi::SyncStatusCode status, | 132 void NotifyTaskDone(fileapi::SyncStatusCode status, |
116 scoped_ptr<TaskToken> token); | 133 scoped_ptr<TaskToken> token); |
| 134 void UpdateServiceState(); |
117 | 135 |
118 void DidInitializeMetadataStore(scoped_ptr<TaskToken> token, | 136 void DidInitializeMetadataStore(scoped_ptr<TaskToken> token, |
119 fileapi::SyncStatusCode status, | 137 fileapi::SyncStatusCode status, |
120 bool created); | 138 bool created); |
121 void DidGetSyncRootDirectory(scoped_ptr<TaskToken> token, | 139 void DidGetSyncRootDirectory(scoped_ptr<TaskToken> token, |
122 google_apis::GDataErrorCode error, | 140 google_apis::GDataErrorCode error, |
123 const std::string& resource_id); | 141 const std::string& resource_id); |
124 void StartBatchSyncForOrigin(const GURL& origin, | 142 void StartBatchSyncForOrigin(const GURL& origin, |
125 const std::string& resource_id); | 143 const std::string& resource_id); |
126 void DidGetDirectoryForOrigin(scoped_ptr<TaskToken> token, | 144 void DidGetDirectoryForOrigin(scoped_ptr<TaskToken> token, |
(...skipping 22 matching lines...) Expand all Loading... |
149 google_apis::DocumentEntry* entry, | 167 google_apis::DocumentEntry* entry, |
150 int64 changestamp); | 168 int64 changestamp); |
151 void DidGetBatchSyncListData(scoped_ptr<TaskToken> token, | 169 void DidGetBatchSyncListData(scoped_ptr<TaskToken> token, |
152 const GURL& origin, | 170 const GURL& origin, |
153 google_apis::GDataErrorCode error, | 171 google_apis::GDataErrorCode error, |
154 scoped_ptr<base::Value> data); | 172 scoped_ptr<base::Value> data); |
155 | 173 |
156 scoped_ptr<DriveMetadataStore> metadata_store_; | 174 scoped_ptr<DriveMetadataStore> metadata_store_; |
157 scoped_ptr<DriveFileSyncClient> sync_client_; | 175 scoped_ptr<DriveFileSyncClient> sync_client_; |
158 | 176 |
159 fileapi::SyncStatusCode status_; | 177 fileapi::SyncStatusCode last_operation_status_; |
| 178 RemoteServiceState state_; |
160 std::deque<base::Closure> pending_tasks_; | 179 std::deque<base::Closure> pending_tasks_; |
161 | 180 |
162 int64 largest_changestamp_; | 181 int64 largest_changestamp_; |
163 ChangeQueue pending_changes_; | 182 ChangeQueue pending_changes_; |
164 ChangeStampMap changestamp_map_; | 183 ChangeStampMap changestamp_map_; |
165 | 184 |
166 // Absence of |token_| implies a task is running. Incoming tasks should | 185 // Absence of |token_| implies a task is running. Incoming tasks should |
167 // wait for the task to finish in |pending_tasks_| if |token_| is null. | 186 // wait for the task to finish in |pending_tasks_| if |token_| is null. |
168 // Each task must take TaskToken instance from |token_| and must hold it | 187 // Each task must take TaskToken instance from |token_| and must hold it |
169 // until it finished. And the task must return the instance through | 188 // until it finished. And the task must return the instance through |
170 // NotifyTaskDone when the task finished. | 189 // NotifyTaskDone when the task finished. |
171 scoped_ptr<TaskToken> token_; | 190 scoped_ptr<TaskToken> token_; |
172 | 191 |
173 ObserverList<Observer> observers_; | 192 ObserverList<Observer> observers_; |
174 base::WeakPtrFactory<DriveFileSyncService> weak_factory_; | 193 base::WeakPtrFactory<DriveFileSyncService> weak_factory_; |
175 | 194 |
176 DISALLOW_COPY_AND_ASSIGN(DriveFileSyncService); | 195 DISALLOW_COPY_AND_ASSIGN(DriveFileSyncService); |
177 }; | 196 }; |
178 | 197 |
179 } // namespace sync_file_system | 198 } // namespace sync_file_system |
180 | 199 |
181 #endif // CHROME_BROWSER_SYNC_FILE_SYSTEM_DRIVE_FILE_SYNC_SERVICE_H_ | 200 #endif // CHROME_BROWSER_SYNC_FILE_SYSTEM_DRIVE_FILE_SYNC_SERVICE_H_ |
OLD | NEW |