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); |
| 141 void StartTaskAfterGetParentResourceEntry(const SyncTasks::key_type& key, |
| 142 const ResourceEntry* parent, |
| 143 FileError error); |
127 | 144 |
128 // Called when the local IDs of files in the backlog are obtained. | 145 // Called when the local IDs of files in the backlog are obtained. |
129 void OnGetLocalIdsOfBacklog(const std::vector<std::string>* to_fetch, | 146 void OnGetLocalIdsOfBacklog(const std::vector<std::string>* to_fetch, |
130 const std::vector<std::string>* to_update); | 147 const std::vector<std::string>* to_update); |
131 | 148 |
132 // Adds fetch tasks. | 149 // Adds fetch tasks. |
133 void AddFetchTasks(const std::vector<std::string>* local_ids); | 150 void AddFetchTasks(const std::vector<std::string>* local_ids); |
134 | 151 |
135 // Erases the task and returns true if task is completed. | 152 // Called when a task is completed. |
136 bool OnTaskComplete(SyncType type, const std::string& local_id); | 153 void OnTaskComplete(SyncType type, |
| 154 const std::string& local_id, |
| 155 FileError error); |
137 | 156 |
138 // Called when the file for |local_id| is fetched. | 157 // Called when the file for |local_id| is fetched. |
139 void OnFetchFileComplete(const std::string& local_id, | 158 void OnFetchFileComplete(const std::string& local_id, |
140 FileError error, | 159 FileError error, |
141 const base::FilePath& local_path, | 160 const base::FilePath& local_path, |
142 scoped_ptr<ResourceEntry> entry); | 161 scoped_ptr<ResourceEntry> entry); |
143 | 162 |
144 // Called when the entry is updated. | |
145 void OnUpdateComplete(const std::string& local_id, FileError error); | |
146 | |
147 // Adds update tasks for |entries|. | |
148 void AddChildUpdateTasks(const ResourceEntryVector* entries, | |
149 FileError error); | |
150 | |
151 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_; | 163 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_; |
152 file_system::OperationObserver* operation_observer_; | 164 file_system::OperationObserver* operation_observer_; |
153 ResourceMetadata* metadata_; | 165 ResourceMetadata* metadata_; |
154 FileCache* cache_; | 166 FileCache* cache_; |
155 | 167 |
156 // Used to fetch pinned files. | 168 // Used to fetch pinned files. |
157 scoped_ptr<file_system::DownloadOperation> download_operation_; | 169 scoped_ptr<file_system::DownloadOperation> download_operation_; |
158 | 170 |
159 // Used to update entry metadata. | 171 // Used to update entry metadata. |
160 scoped_ptr<EntryUpdatePerformer> entry_update_performer_; | 172 scoped_ptr<EntryUpdatePerformer> entry_update_performer_; |
(...skipping 11 matching lines...) Expand all Loading... |
172 // invalidate its weak pointers before any other members are destroyed. | 184 // invalidate its weak pointers before any other members are destroyed. |
173 base::WeakPtrFactory<SyncClient> weak_ptr_factory_; | 185 base::WeakPtrFactory<SyncClient> weak_ptr_factory_; |
174 | 186 |
175 DISALLOW_COPY_AND_ASSIGN(SyncClient); | 187 DISALLOW_COPY_AND_ASSIGN(SyncClient); |
176 }; | 188 }; |
177 | 189 |
178 } // namespace internal | 190 } // namespace internal |
179 } // namespace drive | 191 } // namespace drive |
180 | 192 |
181 #endif // CHROME_BROWSER_CHROMEOS_DRIVE_SYNC_CLIENT_H_ | 193 #endif // CHROME_BROWSER_CHROMEOS_DRIVE_SYNC_CLIENT_H_ |
OLD | NEW |