| 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> |
| 11 | 11 |
| 12 #include "base/callback.h" | 12 #include "base/callback.h" |
| 13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
| 14 #include "base/memory/weak_ptr.h" | 14 #include "base/memory/weak_ptr.h" |
| 15 #include "base/time/time.h" | 15 #include "base/time/time.h" |
| 16 #include "chrome/browser/chromeos/drive/file_errors.h" | 16 #include "chrome/browser/chromeos/drive/file_errors.h" |
| 17 #include "chrome/browser/chromeos/drive/job_scheduler.h" |
| 17 #include "chrome/browser/chromeos/drive/resource_metadata.h" | 18 #include "chrome/browser/chromeos/drive/resource_metadata.h" |
| 18 | 19 |
| 19 namespace base { | 20 namespace base { |
| 20 class SequencedTaskRunner; | 21 class SequencedTaskRunner; |
| 21 } | 22 } |
| 22 | 23 |
| 23 namespace drive { | 24 namespace drive { |
| 24 | 25 |
| 25 class FileCacheEntry; | 26 class FileCacheEntry; |
| 26 class JobScheduler; | 27 class JobScheduler; |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 | 87 |
| 87 private: | 88 private: |
| 88 // Types of sync tasks. | 89 // Types of sync tasks. |
| 89 enum SyncType { | 90 enum SyncType { |
| 90 FETCH, // Fetch a file from the Drive server. | 91 FETCH, // Fetch a file from the Drive server. |
| 91 UPDATE, // Updates an entry's metadata or content on the Drive server. | 92 UPDATE, // Updates an entry's metadata or content on the Drive server. |
| 92 }; | 93 }; |
| 93 | 94 |
| 94 // States of sync tasks. | 95 // States of sync tasks. |
| 95 enum SyncState { | 96 enum SyncState { |
| 96 PENDING, | 97 SUSPENDED, // Task is currently inactive. |
| 97 RUNNING, | 98 PENDING, // Task is going to run. |
| 99 RUNNING, // Task is running. |
| 98 }; | 100 }; |
| 99 | 101 |
| 102 typedef std::pair<SyncType, std::string> SyncTaskKey; |
| 103 |
| 100 struct SyncTask { | 104 struct SyncTask { |
| 101 SyncTask(); | 105 SyncTask(); |
| 102 ~SyncTask(); | 106 ~SyncTask(); |
| 103 SyncState state; | 107 SyncState state; |
| 104 base::Callback<base::Closure()> task; | 108 ClientContext context; |
| 109 base::Callback<base::Closure(const ClientContext& context)> task; |
| 105 bool should_run_again; | 110 bool should_run_again; |
| 106 base::Closure cancel_closure; | 111 base::Closure cancel_closure; |
| 112 std::vector<SyncTaskKey> dependent_tasks; |
| 107 }; | 113 }; |
| 108 | 114 |
| 109 typedef std::map<std::pair<SyncType, std::string>, SyncTask> SyncTasks; | 115 typedef std::map<SyncTaskKey, SyncTask> SyncTasks; |
| 116 |
| 117 // Performs a FETCH task. |
| 118 base::Closure PerformFetchTask(const std::string& local_id, |
| 119 const ClientContext& context); |
| 110 | 120 |
| 111 // Adds a FETCH task. | 121 // Adds a FETCH task. |
| 112 void AddFetchTaskInternal(const std::string& local_id, | 122 void AddFetchTaskInternal(const std::string& local_id, |
| 113 const base::TimeDelta& delay); | 123 const base::TimeDelta& delay); |
| 114 | 124 |
| 125 // Performs a UPDATE task. |
| 126 base::Closure PerformUpdateTask(const std::string& local_id, |
| 127 const ClientContext& context); |
| 128 |
| 115 // Adds a UPDATE task. | 129 // Adds a UPDATE task. |
| 116 void AddUpdateTaskInternal(const ClientContext& context, | 130 void AddUpdateTaskInternal(const ClientContext& context, |
| 117 const std::string& local_id, | 131 const std::string& local_id, |
| 118 const base::TimeDelta& delay); | 132 const base::TimeDelta& delay); |
| 119 | 133 |
| 120 // Adds the given task. If the same task is found, does nothing. | 134 // Adds the given task. If the same task is found, does nothing. |
| 121 void AddTask(const SyncTasks::key_type& key, | 135 void AddTask(const SyncTasks::key_type& key, |
| 122 const SyncTask& task, | 136 const SyncTask& task, |
| 123 const base::TimeDelta& delay); | 137 const base::TimeDelta& delay); |
| 124 | 138 |
| 125 // Called when a task is ready to start. | 139 // Called when a task is ready to start. |
| 126 void StartTask(const SyncTasks::key_type& key); | 140 void StartTask(const SyncTasks::key_type& key); |
| 127 | 141 |
| 128 // Called when the local IDs of files in the backlog are obtained. | 142 // Called when the local IDs of files in the backlog are obtained. |
| 129 void OnGetLocalIdsOfBacklog(const std::vector<std::string>* to_fetch, | 143 void OnGetLocalIdsOfBacklog(const std::vector<std::string>* to_fetch, |
| 130 const std::vector<std::string>* to_update); | 144 const std::vector<std::string>* to_update); |
| 131 | 145 |
| 132 // Adds fetch tasks. | 146 // Adds fetch tasks. |
| 133 void AddFetchTasks(const std::vector<std::string>* local_ids); | 147 void AddFetchTasks(const std::vector<std::string>* local_ids); |
| 134 | 148 |
| 135 // Erases the task and returns true if task is completed. | 149 // Called when a task is completed. |
| 136 bool OnTaskComplete(SyncType type, const std::string& local_id); | 150 void OnTaskComplete(SyncType type, |
| 151 const std::string& local_id, |
| 152 FileError error); |
| 137 | 153 |
| 138 // Called when the file for |local_id| is fetched. | 154 // Called when the file for |local_id| is fetched. |
| 139 void OnFetchFileComplete(const std::string& local_id, | 155 void OnFetchFileComplete(const std::string& local_id, |
| 140 FileError error, | 156 FileError error, |
| 141 const base::FilePath& local_path, | 157 const base::FilePath& local_path, |
| 142 scoped_ptr<ResourceEntry> entry); | 158 scoped_ptr<ResourceEntry> entry); |
| 143 | 159 |
| 144 // Called when the entry is updated. | 160 // Adds the task as a dependent task of the parent entry's task. |
| 145 void OnUpdateComplete(const std::string& local_id, FileError error); | 161 void AddDependentTask(SyncType type, |
| 146 | 162 const std::string& local_id, |
| 147 // Adds update tasks for |entries|. | 163 const ResourceEntry* entry, |
| 148 void AddChildUpdateTasks(const ResourceEntryVector* entries, | 164 FileError error); |
| 149 FileError error); | |
| 150 | 165 |
| 151 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_; | 166 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_; |
| 152 file_system::OperationObserver* operation_observer_; | 167 file_system::OperationObserver* operation_observer_; |
| 153 ResourceMetadata* metadata_; | 168 ResourceMetadata* metadata_; |
| 154 FileCache* cache_; | 169 FileCache* cache_; |
| 155 | 170 |
| 156 // Used to fetch pinned files. | 171 // Used to fetch pinned files. |
| 157 scoped_ptr<file_system::DownloadOperation> download_operation_; | 172 scoped_ptr<file_system::DownloadOperation> download_operation_; |
| 158 | 173 |
| 159 // Used to update entry metadata. | 174 // Used to update entry metadata. |
| (...skipping 12 matching lines...) Expand all Loading... |
| 172 // invalidate its weak pointers before any other members are destroyed. | 187 // invalidate its weak pointers before any other members are destroyed. |
| 173 base::WeakPtrFactory<SyncClient> weak_ptr_factory_; | 188 base::WeakPtrFactory<SyncClient> weak_ptr_factory_; |
| 174 | 189 |
| 175 DISALLOW_COPY_AND_ASSIGN(SyncClient); | 190 DISALLOW_COPY_AND_ASSIGN(SyncClient); |
| 176 }; | 191 }; |
| 177 | 192 |
| 178 } // namespace internal | 193 } // namespace internal |
| 179 } // namespace drive | 194 } // namespace drive |
| 180 | 195 |
| 181 #endif // CHROME_BROWSER_CHROMEOS_DRIVE_SYNC_CLIENT_H_ | 196 #endif // CHROME_BROWSER_CHROMEOS_DRIVE_SYNC_CLIENT_H_ |
| OLD | NEW |