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 <set> | 8 #include <set> |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
(...skipping 16 matching lines...) Expand all Loading... |
27 | 27 |
28 namespace file_system { | 28 namespace file_system { |
29 class DownloadOperation; | 29 class DownloadOperation; |
30 class OperationObserver; | 30 class OperationObserver; |
31 class UpdateOperation; | 31 class UpdateOperation; |
32 } | 32 } |
33 | 33 |
34 namespace internal { | 34 namespace internal { |
35 | 35 |
36 class FileCache; | 36 class FileCache; |
| 37 class RemovePerformer; |
37 class ResourceMetadata; | 38 class ResourceMetadata; |
38 | 39 |
39 // 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 |
40 // cache on the local drive. | 41 // cache on the local drive. |
41 // | 42 // |
42 // If the user logs out before fetching of the pinned files is complete, this | 43 // If the user logs out before fetching of the pinned files is complete, this |
43 // client resumes fetching operations next time the user logs in, based on | 44 // client resumes fetching operations next time the user logs in, based on |
44 // the states left in the cache. | 45 // the states left in the cache. |
45 class SyncClient { | 46 class SyncClient { |
46 public: | 47 public: |
(...skipping 17 matching lines...) Expand all Loading... |
64 // Adds a fetch task to the queue. | 65 // Adds a fetch task to the queue. |
65 void AddFetchTask(const std::string& local_id); | 66 void AddFetchTask(const std::string& local_id); |
66 | 67 |
67 // Removes a fetch task from the queue. | 68 // Removes a fetch task from the queue. |
68 void RemoveFetchTask(const std::string& local_id); | 69 void RemoveFetchTask(const std::string& local_id); |
69 | 70 |
70 // Adds an upload task to the queue. | 71 // Adds an upload task to the queue. |
71 void AddUploadTask(const ClientContext& context, | 72 void AddUploadTask(const ClientContext& context, |
72 const std::string& local_id); | 73 const std::string& local_id); |
73 | 74 |
| 75 // Adds a remove task to the queue. |
| 76 void AddRemoveTask(const std::string& local_id); |
| 77 |
74 // Starts processing the backlog (i.e. pinned-but-not-filed files and | 78 // Starts processing the backlog (i.e. pinned-but-not-filed files and |
75 // dirty-but-not-uploaded files). Kicks off retrieval of the local | 79 // dirty-but-not-uploaded files). Kicks off retrieval of the local |
76 // IDs of these files, and then starts the sync loop. | 80 // IDs of these files, and then starts the sync loop. |
77 void StartProcessingBacklog(); | 81 void StartProcessingBacklog(); |
78 | 82 |
79 // Starts checking the existing pinned files to see if these are | 83 // Starts checking the existing pinned files to see if these are |
80 // up-to-date. If stale files are detected, the local IDs of these files | 84 // up-to-date. If stale files are detected, the local IDs of these files |
81 // are added to the queue and the sync loop is started. | 85 // are added to the queue and the sync loop is started. |
82 void StartCheckingExistingPinnedFiles(); | 86 void StartCheckingExistingPinnedFiles(); |
83 | 87 |
(...skipping 13 matching lines...) Expand all Loading... |
97 const std::string& local_id, | 101 const std::string& local_id, |
98 const base::TimeDelta& delay); | 102 const base::TimeDelta& delay); |
99 | 103 |
100 // Called when a task is ready to be added to the queue. | 104 // Called when a task is ready to be added to the queue. |
101 void StartTask(SyncType type, | 105 void StartTask(SyncType type, |
102 const ClientContext& context, | 106 const ClientContext& context, |
103 const std::string& local_id); | 107 const std::string& local_id); |
104 | 108 |
105 // Called when the local IDs of files in the backlog are obtained. | 109 // Called when the local IDs of files in the backlog are obtained. |
106 void OnGetLocalIdsOfBacklog(const std::vector<std::string>* to_fetch, | 110 void OnGetLocalIdsOfBacklog(const std::vector<std::string>* to_fetch, |
107 const std::vector<std::string>* to_upload); | 111 const std::vector<std::string>* to_upload, |
| 112 const std::vector<std::string>* to_remove); |
108 | 113 |
109 // Adds fetch tasks. | 114 // Adds fetch tasks. |
110 void AddFetchTasks(const std::vector<std::string>* local_ids); | 115 void AddFetchTasks(const std::vector<std::string>* local_ids); |
111 | 116 |
112 // Called when the file for |local_id| is fetched. | 117 // Called when the file for |local_id| is fetched. |
113 // Calls DoSyncLoop() to go back to the sync loop. | 118 // Calls DoSyncLoop() to go back to the sync loop. |
114 void OnFetchFileComplete(const std::string& local_id, | 119 void OnFetchFileComplete(const std::string& local_id, |
115 FileError error, | 120 FileError error, |
116 const base::FilePath& local_path, | 121 const base::FilePath& local_path, |
117 scoped_ptr<ResourceEntry> entry); | 122 scoped_ptr<ResourceEntry> entry); |
118 | 123 |
119 // Called when the file for |local_id| is uploaded. | 124 // Called when the file for |local_id| is uploaded. |
120 // Calls DoSyncLoop() to go back to the sync loop. | 125 // Calls DoSyncLoop() to go back to the sync loop. |
121 void OnUploadFileComplete(const std::string& local_id, FileError error); | 126 void OnUploadFileComplete(const std::string& local_id, FileError error); |
122 | 127 |
| 128 // Called when the entry is removed. |
| 129 void OnRemoveComplete(const std::string& local_id, FileError error); |
| 130 |
123 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_; | 131 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_; |
124 ResourceMetadata* metadata_; | 132 ResourceMetadata* metadata_; |
125 FileCache* cache_; | 133 FileCache* cache_; |
126 | 134 |
127 // Used to fetch pinned files. | 135 // Used to fetch pinned files. |
128 scoped_ptr<file_system::DownloadOperation> download_operation_; | 136 scoped_ptr<file_system::DownloadOperation> download_operation_; |
129 | 137 |
130 // Used to upload committed files. | 138 // Used to upload committed files. |
131 scoped_ptr<file_system::UpdateOperation> update_operation_; | 139 scoped_ptr<file_system::UpdateOperation> update_operation_; |
132 | 140 |
| 141 // Used to remove entries from the trash. |
| 142 scoped_ptr<RemovePerformer> remove_performer_; |
| 143 |
133 // List of the local ids of resources which have a fetch task created. | 144 // List of the local ids of resources which have a fetch task created. |
134 std::set<std::string> fetch_list_; | 145 std::set<std::string> fetch_list_; |
135 | 146 |
136 // List of the local ids of resources which have a upload task created. | 147 // List of the local ids of resources which have a upload task created. |
137 std::set<std::string> upload_list_; | 148 std::set<std::string> upload_list_; |
138 | 149 |
139 // Fetch tasks which have been created, but not started yet. If they are | 150 // Fetch tasks which have been created, but not started yet. If they are |
140 // removed before starting, they will be cancelled. | 151 // removed before starting, they will be cancelled. |
141 std::set<std::string> pending_fetch_list_; | 152 std::set<std::string> pending_fetch_list_; |
142 | 153 |
143 // The delay is used for delaying processing tasks in AddTaskToQueue(). | 154 // The delay is used for delaying processing tasks in AddTaskToQueue(). |
144 base::TimeDelta delay_; | 155 base::TimeDelta delay_; |
145 | 156 |
146 // The delay is used for delaying retry of tasks on server errors. | 157 // The delay is used for delaying retry of tasks on server errors. |
147 base::TimeDelta long_delay_; | 158 base::TimeDelta long_delay_; |
148 | 159 |
149 // Note: This should remain the last member so it'll be destroyed and | 160 // Note: This should remain the last member so it'll be destroyed and |
150 // invalidate its weak pointers before any other members are destroyed. | 161 // invalidate its weak pointers before any other members are destroyed. |
151 base::WeakPtrFactory<SyncClient> weak_ptr_factory_; | 162 base::WeakPtrFactory<SyncClient> weak_ptr_factory_; |
152 | 163 |
153 DISALLOW_COPY_AND_ASSIGN(SyncClient); | 164 DISALLOW_COPY_AND_ASSIGN(SyncClient); |
154 }; | 165 }; |
155 | 166 |
156 } // namespace internal | 167 } // namespace internal |
157 } // namespace drive | 168 } // namespace drive |
158 | 169 |
159 #endif // CHROME_BROWSER_CHROMEOS_DRIVE_SYNC_CLIENT_H_ | 170 #endif // CHROME_BROWSER_CHROMEOS_DRIVE_SYNC_CLIENT_H_ |
OLD | NEW |