| 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 17 matching lines...) Expand all Loading... |
| 144 const fileapi::SyncStatusCallback& callback, | 162 const fileapi::SyncStatusCallback& callback, |
| 145 fileapi::SyncStatusCode status); | 163 fileapi::SyncStatusCode status); |
| 146 | 164 |
| 147 void AppendNewRemoteChange(const GURL& origin, | 165 void AppendNewRemoteChange(const GURL& origin, |
| 148 google_apis::DocumentEntry* entry, | 166 google_apis::DocumentEntry* entry, |
| 149 int64 changestamp); | 167 int64 changestamp); |
| 150 | 168 |
| 151 scoped_ptr<DriveMetadataStore> metadata_store_; | 169 scoped_ptr<DriveMetadataStore> metadata_store_; |
| 152 scoped_ptr<DriveFileSyncClient> sync_client_; | 170 scoped_ptr<DriveFileSyncClient> sync_client_; |
| 153 | 171 |
| 154 fileapi::SyncStatusCode status_; | 172 fileapi::SyncStatusCode last_operation_status_; |
| 173 RemoteServiceState state_; |
| 155 std::deque<base::Closure> pending_tasks_; | 174 std::deque<base::Closure> pending_tasks_; |
| 156 | 175 |
| 157 int64 largest_changestamp_; | 176 int64 largest_changestamp_; |
| 158 ChangeQueue pending_changes_; | 177 ChangeQueue pending_changes_; |
| 159 ChangeStampMap changestamp_map_; | 178 ChangeStampMap changestamp_map_; |
| 160 | 179 |
| 161 // Absence of |token_| implies a task is running. Incoming tasks should | 180 // Absence of |token_| implies a task is running. Incoming tasks should |
| 162 // wait for the task to finish in |pending_tasks_| if |token_| is null. | 181 // wait for the task to finish in |pending_tasks_| if |token_| is null. |
| 163 // Each task must take TaskToken instance from |token_| and must hold it | 182 // Each task must take TaskToken instance from |token_| and must hold it |
| 164 // until it finished. And the task must return the instance through | 183 // until it finished. And the task must return the instance through |
| 165 // NotifyTaskDone when the task finished. | 184 // NotifyTaskDone when the task finished. |
| 166 scoped_ptr<TaskToken> token_; | 185 scoped_ptr<TaskToken> token_; |
| 167 | 186 |
| 168 ObserverList<Observer> observers_; | 187 ObserverList<Observer> observers_; |
| 169 base::WeakPtrFactory<DriveFileSyncService> weak_factory_; | 188 base::WeakPtrFactory<DriveFileSyncService> weak_factory_; |
| 170 | 189 |
| 171 DISALLOW_COPY_AND_ASSIGN(DriveFileSyncService); | 190 DISALLOW_COPY_AND_ASSIGN(DriveFileSyncService); |
| 172 }; | 191 }; |
| 173 | 192 |
| 174 } // namespace sync_file_system | 193 } // namespace sync_file_system |
| 175 | 194 |
| 176 #endif // CHROME_BROWSER_SYNC_FILE_SYSTEM_DRIVE_FILE_SYNC_SERVICE_H_ | 195 #endif // CHROME_BROWSER_SYNC_FILE_SYSTEM_DRIVE_FILE_SYNC_SERVICE_H_ |
| OLD | NEW |