| 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_DRIVE_SYNC_CLIENT_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_DRIVE_SYNC_CLIENT_H_ |
| 6 #define CHROME_BROWSER_CHROMEOS_DRIVE_SYNC_CLIENT_H_ | 6 #define CHROME_BROWSER_CHROMEOS_DRIVE_SYNC_CLIENT_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 namespace drive { | 22 namespace drive { |
| 23 | 23 |
| 24 class FileCacheEntry; | 24 class FileCacheEntry; |
| 25 class JobScheduler; | 25 class JobScheduler; |
| 26 class ResourceEntry; | 26 class ResourceEntry; |
| 27 struct ClientContext; | 27 struct ClientContext; |
| 28 | 28 |
| 29 namespace file_system { | 29 namespace file_system { |
| 30 class DownloadOperation; | 30 class DownloadOperation; |
| 31 class OperationObserver; | 31 class OperationObserver; |
| 32 class ContentUpdatePerformer; | |
| 33 } | 32 } |
| 34 | 33 |
| 35 namespace internal { | 34 namespace internal { |
| 36 | 35 |
| 37 class EntryUpdatePerformer; | 36 class EntryUpdatePerformer; |
| 38 class FileCache; | 37 class FileCache; |
| 39 class ResourceMetadata; | 38 class ResourceMetadata; |
| 40 | 39 |
| 41 // The SyncClient is used to synchronize pinned files on Drive and the | 40 // The SyncClient is used to synchronize pinned files on Drive and the |
| 42 // cache on the local drive. | 41 // cache on the local drive. |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 81 delay_ = delay; | 80 delay_ = delay; |
| 82 } | 81 } |
| 83 | 82 |
| 84 // Starts the sync loop if it's not running. | 83 // Starts the sync loop if it's not running. |
| 85 void StartSyncLoop(); | 84 void StartSyncLoop(); |
| 86 | 85 |
| 87 private: | 86 private: |
| 88 // Types of sync tasks. | 87 // Types of sync tasks. |
| 89 enum SyncType { | 88 enum SyncType { |
| 90 FETCH, // Fetch a file from the Drive server. | 89 FETCH, // Fetch a file from the Drive server. |
| 91 UPLOAD, // Upload a file to the Drive server. | 90 UPDATE, // Updates an entry's metadata or content on the Drive server. |
| 92 UPDATE, // Updates an entry's metadata on the Drive server. | |
| 93 }; | 91 }; |
| 94 | 92 |
| 95 // States of sync tasks. | 93 // States of sync tasks. |
| 96 enum SyncState { | 94 enum SyncState { |
| 97 PENDING, | 95 PENDING, |
| 98 RUNNING, | 96 RUNNING, |
| 99 }; | 97 }; |
| 100 | 98 |
| 101 struct SyncTask { | 99 struct SyncTask { |
| 102 SyncTask(); | 100 SyncTask(); |
| 103 ~SyncTask(); | 101 ~SyncTask(); |
| 104 SyncState state; | 102 SyncState state; |
| 105 base::Closure task; | 103 base::Closure task; |
| 106 bool should_run_again; | 104 bool should_run_again; |
| 107 }; | 105 }; |
| 108 | 106 |
| 109 typedef std::map<std::pair<SyncType, std::string>, SyncTask> SyncTasks; | 107 typedef std::map<std::pair<SyncType, std::string>, SyncTask> SyncTasks; |
| 110 | 108 |
| 111 // Adds a FETCH task. | 109 // Adds a FETCH task. |
| 112 void AddFetchTaskInternal(const std::string& local_id, | 110 void AddFetchTaskInternal(const std::string& local_id, |
| 113 const base::TimeDelta& delay); | 111 const base::TimeDelta& delay); |
| 114 | 112 |
| 115 // Adds a UPLOAD task. | |
| 116 void AddUploadTaskInternal(const ClientContext& context, | |
| 117 const std::string& local_id, | |
| 118 const base::TimeDelta& delay); | |
| 119 | |
| 120 // Adds a UPDATE task. | 113 // Adds a UPDATE task. |
| 121 void AddUpdateTaskInternal(const ClientContext& context, | 114 void AddUpdateTaskInternal(const ClientContext& context, |
| 122 const std::string& local_id, | 115 const std::string& local_id, |
| 123 const base::TimeDelta& delay); | 116 const base::TimeDelta& delay); |
| 124 | 117 |
| 125 // Adds the given task. If the same task is found, does nothing. | 118 // Adds the given task. If the same task is found, does nothing. |
| 126 void AddTask(const SyncTasks::key_type& key, | 119 void AddTask(const SyncTasks::key_type& key, |
| 127 const SyncTask& task, | 120 const SyncTask& task, |
| 128 const base::TimeDelta& delay); | 121 const base::TimeDelta& delay); |
| 129 | 122 |
| 130 // Called when a task is ready to start. | 123 // Called when a task is ready to start. |
| 131 void StartTask(const SyncTasks::key_type& key); | 124 void StartTask(const SyncTasks::key_type& key); |
| 132 | 125 |
| 133 // Called when the local IDs of files in the backlog are obtained. | 126 // Called when the local IDs of files in the backlog are obtained. |
| 134 void OnGetLocalIdsOfBacklog(const std::vector<std::string>* to_fetch, | 127 void OnGetLocalIdsOfBacklog(const std::vector<std::string>* to_fetch, |
| 135 const std::vector<std::string>* to_upload, | |
| 136 const std::vector<std::string>* to_update); | 128 const std::vector<std::string>* to_update); |
| 137 | 129 |
| 138 // Adds fetch tasks. | 130 // Adds fetch tasks. |
| 139 void AddFetchTasks(const std::vector<std::string>* local_ids); | 131 void AddFetchTasks(const std::vector<std::string>* local_ids); |
| 140 | 132 |
| 141 // Erases the task and returns true if task is completed. | 133 // Erases the task and returns true if task is completed. |
| 142 bool OnTaskComplete(SyncType type, const std::string& local_id); | 134 bool OnTaskComplete(SyncType type, const std::string& local_id); |
| 143 | 135 |
| 144 // Called when the file for |local_id| is fetched. | 136 // Called when the file for |local_id| is fetched. |
| 145 // Calls DoSyncLoop() to go back to the sync loop. | 137 // Calls DoSyncLoop() to go back to the sync loop. |
| (...skipping 10 matching lines...) Expand all Loading... |
| 156 void OnUpdateComplete(const std::string& local_id, FileError error); | 148 void OnUpdateComplete(const std::string& local_id, FileError error); |
| 157 | 149 |
| 158 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_; | 150 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_; |
| 159 file_system::OperationObserver* operation_observer_; | 151 file_system::OperationObserver* operation_observer_; |
| 160 ResourceMetadata* metadata_; | 152 ResourceMetadata* metadata_; |
| 161 FileCache* cache_; | 153 FileCache* cache_; |
| 162 | 154 |
| 163 // Used to fetch pinned files. | 155 // Used to fetch pinned files. |
| 164 scoped_ptr<file_system::DownloadOperation> download_operation_; | 156 scoped_ptr<file_system::DownloadOperation> download_operation_; |
| 165 | 157 |
| 166 // Used to upload committed files. | |
| 167 scoped_ptr<file_system::ContentUpdatePerformer> content_update_performer_; | |
| 168 | |
| 169 // Used to update entry metadata. | 158 // Used to update entry metadata. |
| 170 scoped_ptr<EntryUpdatePerformer> entry_update_performer_; | 159 scoped_ptr<EntryUpdatePerformer> entry_update_performer_; |
| 171 | 160 |
| 172 // Sync tasks to be processed. | 161 // Sync tasks to be processed. |
| 173 SyncTasks tasks_; | 162 SyncTasks tasks_; |
| 174 | 163 |
| 175 // The delay is used for delaying processing tasks in AddTask(). | 164 // The delay is used for delaying processing tasks in AddTask(). |
| 176 base::TimeDelta delay_; | 165 base::TimeDelta delay_; |
| 177 | 166 |
| 178 // The delay is used for delaying retry of tasks on server errors. | 167 // The delay is used for delaying retry of tasks on server errors. |
| 179 base::TimeDelta long_delay_; | 168 base::TimeDelta long_delay_; |
| 180 | 169 |
| 181 // Note: This should remain the last member so it'll be destroyed and | 170 // Note: This should remain the last member so it'll be destroyed and |
| 182 // invalidate its weak pointers before any other members are destroyed. | 171 // invalidate its weak pointers before any other members are destroyed. |
| 183 base::WeakPtrFactory<SyncClient> weak_ptr_factory_; | 172 base::WeakPtrFactory<SyncClient> weak_ptr_factory_; |
| 184 | 173 |
| 185 DISALLOW_COPY_AND_ASSIGN(SyncClient); | 174 DISALLOW_COPY_AND_ASSIGN(SyncClient); |
| 186 }; | 175 }; |
| 187 | 176 |
| 188 } // namespace internal | 177 } // namespace internal |
| 189 } // namespace drive | 178 } // namespace drive |
| 190 | 179 |
| 191 #endif // CHROME_BROWSER_CHROMEOS_DRIVE_SYNC_CLIENT_H_ | 180 #endif // CHROME_BROWSER_CHROMEOS_DRIVE_SYNC_CLIENT_H_ |
| OLD | NEW |