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 #include "chrome/browser/chromeos/drive/drive_scheduler.h" | 5 #include "chrome/browser/chromeos/drive/job_scheduler.h" |
6 | 6 |
7 #include <math.h> | 7 #include <math.h> |
8 | 8 |
9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
10 #include "base/prefs/pref_service.h" | 10 #include "base/prefs/pref_service.h" |
11 #include "base/rand_util.h" | 11 #include "base/rand_util.h" |
12 #include "base/stl_util.h" | 12 #include "base/stl_util.h" |
13 #include "base/strings/string_number_conversions.h" | 13 #include "base/strings/string_number_conversions.h" |
14 #include "chrome/browser/chromeos/drive/drive_file_system_util.h" | 14 #include "chrome/browser/chromeos/drive/drive_file_system_util.h" |
15 #include "chrome/browser/chromeos/drive/logging.h" | 15 #include "chrome/browser/chromeos/drive/logging.h" |
16 #include "chrome/browser/google_apis/drive_api_parser.h" | 16 #include "chrome/browser/google_apis/drive_api_parser.h" |
17 #include "chrome/browser/google_apis/gdata_wapi_parser.h" | 17 #include "chrome/browser/google_apis/gdata_wapi_parser.h" |
18 #include "chrome/browser/profiles/profile.h" | 18 #include "chrome/browser/profiles/profile.h" |
19 #include "chrome/common/pref_names.h" | 19 #include "chrome/common/pref_names.h" |
20 #include "content/public/browser/browser_thread.h" | 20 #include "content/public/browser/browser_thread.h" |
21 | 21 |
22 using content::BrowserThread; | 22 using content::BrowserThread; |
23 | 23 |
24 namespace drive { | 24 namespace drive { |
25 | 25 |
26 namespace { | 26 namespace { |
27 const int kMaxThrottleCount = 5; | 27 const int kMaxThrottleCount = 5; |
28 } | 28 } |
29 | 29 |
30 const int DriveScheduler::kMaxJobCount[] = { | 30 const int JobScheduler::kMaxJobCount[] = { |
31 5, // METADATA_QUEUE | 31 5, // METADATA_QUEUE |
32 1, // FILE_QUEUE | 32 1, // FILE_QUEUE |
33 }; | 33 }; |
34 | 34 |
35 DriveScheduler::QueueEntry::QueueEntry() | 35 JobScheduler::QueueEntry::QueueEntry() |
36 : job_id(-1), | 36 : job_id(-1), |
37 context(DriveClientContext(USER_INITIATED)) { | 37 context(DriveClientContext(USER_INITIATED)) { |
38 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 38 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
39 } | 39 } |
40 | 40 |
41 DriveScheduler::QueueEntry::~QueueEntry() { | 41 JobScheduler::QueueEntry::~QueueEntry() { |
42 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 42 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
43 } | 43 } |
44 | 44 |
45 bool DriveScheduler::QueueEntry::Compare( | 45 bool JobScheduler::QueueEntry::Compare( |
46 const DriveScheduler::QueueEntry* left, | 46 const JobScheduler::QueueEntry* left, |
47 const DriveScheduler::QueueEntry* right) { | 47 const JobScheduler::QueueEntry* right) { |
48 return (left->context.type < right->context.type); | 48 return (left->context.type < right->context.type); |
49 } | 49 } |
50 | 50 |
51 DriveScheduler::DriveScheduler( | 51 JobScheduler::JobScheduler( |
52 Profile* profile, | 52 Profile* profile, |
53 google_apis::DriveServiceInterface* drive_service) | 53 google_apis::DriveServiceInterface* drive_service) |
54 : throttle_count_(0), | 54 : throttle_count_(0), |
55 disable_throttling_(false), | 55 disable_throttling_(false), |
56 drive_service_(drive_service), | 56 drive_service_(drive_service), |
57 uploader_(new google_apis::DriveUploader(drive_service)), | 57 uploader_(new google_apis::DriveUploader(drive_service)), |
58 profile_(profile), | 58 profile_(profile), |
59 weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { | 59 weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { |
60 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 60 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
61 for (int i = 0; i < NUM_QUEUES; ++i) { | 61 for (int i = 0; i < NUM_QUEUES; ++i) { |
62 jobs_running_[i] = 0; | 62 jobs_running_[i] = 0; |
63 } | 63 } |
64 | 64 |
65 net::NetworkChangeNotifier::AddConnectionTypeObserver(this); | 65 net::NetworkChangeNotifier::AddConnectionTypeObserver(this); |
66 } | 66 } |
67 | 67 |
68 DriveScheduler::~DriveScheduler() { | 68 JobScheduler::~JobScheduler() { |
69 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 69 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
70 | 70 |
71 size_t num_pending_jobs = 0; | 71 size_t num_pending_jobs = 0; |
72 size_t num_running_jobs = 0; | 72 size_t num_running_jobs = 0; |
73 for (int i = 0; i < NUM_QUEUES; ++i) { | 73 for (int i = 0; i < NUM_QUEUES; ++i) { |
74 num_pending_jobs += queue_[i].size(); | 74 num_pending_jobs += queue_[i].size(); |
75 num_running_jobs += jobs_running_[i]; | 75 num_running_jobs += jobs_running_[i]; |
76 } | 76 } |
77 DCHECK_EQ(num_pending_jobs + num_running_jobs, job_map_.size()); | 77 DCHECK_EQ(num_pending_jobs + num_running_jobs, job_map_.size()); |
78 | 78 |
79 for (int i = 0; i < NUM_QUEUES; ++i) { | 79 for (int i = 0; i < NUM_QUEUES; ++i) { |
80 STLDeleteElements(&queue_[i]); | 80 STLDeleteElements(&queue_[i]); |
81 } | 81 } |
82 net::NetworkChangeNotifier::RemoveConnectionTypeObserver(this); | 82 net::NetworkChangeNotifier::RemoveConnectionTypeObserver(this); |
83 } | 83 } |
84 | 84 |
85 std::vector<JobInfo> DriveScheduler::GetJobInfoList() { | 85 std::vector<JobInfo> JobScheduler::GetJobInfoList() { |
86 std::vector<JobInfo> job_info_list; | 86 std::vector<JobInfo> job_info_list; |
87 for (JobIDMap::iterator iter(&job_map_); !iter.IsAtEnd(); iter.Advance()) | 87 for (JobIDMap::iterator iter(&job_map_); !iter.IsAtEnd(); iter.Advance()) |
88 job_info_list.push_back(*iter.GetCurrentValue()); | 88 job_info_list.push_back(*iter.GetCurrentValue()); |
89 return job_info_list; | 89 return job_info_list; |
90 } | 90 } |
91 | 91 |
92 void DriveScheduler::AddObserver(JobListObserver* observer) { | 92 void JobScheduler::AddObserver(JobListObserver* observer) { |
93 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 93 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
94 observer_list_.AddObserver(observer); | 94 observer_list_.AddObserver(observer); |
95 } | 95 } |
96 | 96 |
97 void DriveScheduler::RemoveObserver(JobListObserver* observer) { | 97 void JobScheduler::RemoveObserver(JobListObserver* observer) { |
98 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 98 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
99 observer_list_.RemoveObserver(observer); | 99 observer_list_.RemoveObserver(observer); |
100 } | 100 } |
101 | 101 |
102 void DriveScheduler::CancelJob(JobID job_id) { | 102 void JobScheduler::CancelJob(JobID job_id) { |
103 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 103 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
104 | 104 |
105 // TODO(kinaba): Move the cancellation feature from DriveService | 105 // TODO(kinaba): Move the cancellation feature from DriveService |
106 // to DriveScheduler. In particular, implement cancel based on job_id. | 106 // to JobScheduler. In particular, implement cancel based on job_id. |
107 // crbug.com/231029 | 107 // crbug.com/231029 |
108 JobInfo* info = job_map_.Lookup(job_id); | 108 JobInfo* info = job_map_.Lookup(job_id); |
109 if (info) | 109 if (info) |
110 drive_service_->CancelForFilePath(info->file_path); | 110 drive_service_->CancelForFilePath(info->file_path); |
111 } | 111 } |
112 | 112 |
113 void DriveScheduler::CancelAllJobs() { | 113 void JobScheduler::CancelAllJobs() { |
114 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 114 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
115 | 115 |
116 // TODO(kinaba): Move the cancellation feature from DriveService | 116 // TODO(kinaba): Move the cancellation feature from DriveService |
117 // to DriveScheduler. | 117 // to JobScheduler. |
118 drive_service_->CancelAll(); | 118 drive_service_->CancelAll(); |
119 } | 119 } |
120 | 120 |
121 void DriveScheduler::GetAccountMetadata( | 121 void JobScheduler::GetAccountMetadata( |
122 const google_apis::GetAccountMetadataCallback& callback) { | 122 const google_apis::GetAccountMetadataCallback& callback) { |
123 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 123 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
124 DCHECK(!callback.is_null()); | 124 DCHECK(!callback.is_null()); |
125 | 125 |
126 scoped_ptr<QueueEntry> new_job(new QueueEntry); | 126 scoped_ptr<QueueEntry> new_job(new QueueEntry); |
127 new_job->get_account_metadata_callback = callback; | 127 new_job->get_account_metadata_callback = callback; |
128 | 128 |
129 StartNewJob(new_job.Pass(), TYPE_GET_ACCOUNT_METADATA); | 129 StartNewJob(new_job.Pass(), TYPE_GET_ACCOUNT_METADATA); |
130 } | 130 } |
131 | 131 |
132 void DriveScheduler::GetAboutResource( | 132 void JobScheduler::GetAboutResource( |
133 const google_apis::GetAboutResourceCallback& callback) { | 133 const google_apis::GetAboutResourceCallback& callback) { |
134 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 134 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
135 DCHECK(!callback.is_null()); | 135 DCHECK(!callback.is_null()); |
136 | 136 |
137 scoped_ptr<QueueEntry> new_job(new QueueEntry); | 137 scoped_ptr<QueueEntry> new_job(new QueueEntry); |
138 new_job->get_about_resource_callback = callback; | 138 new_job->get_about_resource_callback = callback; |
139 | 139 |
140 StartNewJob(new_job.Pass(), TYPE_GET_ABOUT_RESOURCE); | 140 StartNewJob(new_job.Pass(), TYPE_GET_ABOUT_RESOURCE); |
141 } | 141 } |
142 | 142 |
143 void DriveScheduler::GetAppList( | 143 void JobScheduler::GetAppList( |
144 const google_apis::GetAppListCallback& callback) { | 144 const google_apis::GetAppListCallback& callback) { |
145 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 145 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
146 DCHECK(!callback.is_null()); | 146 DCHECK(!callback.is_null()); |
147 | 147 |
148 scoped_ptr<QueueEntry> new_job(new QueueEntry); | 148 scoped_ptr<QueueEntry> new_job(new QueueEntry); |
149 new_job->get_app_list_callback = callback; | 149 new_job->get_app_list_callback = callback; |
150 | 150 |
151 StartNewJob(new_job.Pass(), TYPE_GET_APP_LIST); | 151 StartNewJob(new_job.Pass(), TYPE_GET_APP_LIST); |
152 } | 152 } |
153 | 153 |
154 void DriveScheduler::GetAllResourceList( | 154 void JobScheduler::GetAllResourceList( |
155 const google_apis::GetResourceListCallback& callback) { | 155 const google_apis::GetResourceListCallback& callback) { |
156 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 156 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
157 DCHECK(!callback.is_null()); | 157 DCHECK(!callback.is_null()); |
158 | 158 |
159 scoped_ptr<QueueEntry> new_job(new QueueEntry); | 159 scoped_ptr<QueueEntry> new_job(new QueueEntry); |
160 new_job->get_resource_list_callback = callback; | 160 new_job->get_resource_list_callback = callback; |
161 | 161 |
162 StartNewJob(new_job.Pass(), TYPE_GET_ALL_RESOURCE_LIST); | 162 StartNewJob(new_job.Pass(), TYPE_GET_ALL_RESOURCE_LIST); |
163 } | 163 } |
164 | 164 |
165 void DriveScheduler::GetResourceListInDirectory( | 165 void JobScheduler::GetResourceListInDirectory( |
166 const std::string& directory_resource_id, | 166 const std::string& directory_resource_id, |
167 const google_apis::GetResourceListCallback& callback) { | 167 const google_apis::GetResourceListCallback& callback) { |
168 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 168 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
169 DCHECK(!callback.is_null()); | 169 DCHECK(!callback.is_null()); |
170 | 170 |
171 scoped_ptr<QueueEntry> new_job(new QueueEntry); | 171 scoped_ptr<QueueEntry> new_job(new QueueEntry); |
172 new_job->directory_resource_id = directory_resource_id; | 172 new_job->directory_resource_id = directory_resource_id; |
173 new_job->get_resource_list_callback = callback; | 173 new_job->get_resource_list_callback = callback; |
174 | 174 |
175 StartNewJob(new_job.Pass(), TYPE_GET_RESOURCE_LIST_IN_DIRECTORY); | 175 StartNewJob(new_job.Pass(), TYPE_GET_RESOURCE_LIST_IN_DIRECTORY); |
176 } | 176 } |
177 | 177 |
178 void DriveScheduler::Search( | 178 void JobScheduler::Search( |
179 const std::string& search_query, | 179 const std::string& search_query, |
180 const google_apis::GetResourceListCallback& callback) { | 180 const google_apis::GetResourceListCallback& callback) { |
181 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 181 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
182 DCHECK(!callback.is_null()); | 182 DCHECK(!callback.is_null()); |
183 | 183 |
184 scoped_ptr<QueueEntry> new_job(new QueueEntry); | 184 scoped_ptr<QueueEntry> new_job(new QueueEntry); |
185 new_job->search_query = search_query; | 185 new_job->search_query = search_query; |
186 new_job->get_resource_list_callback = callback; | 186 new_job->get_resource_list_callback = callback; |
187 | 187 |
188 StartNewJob(new_job.Pass(), TYPE_SEARCH); | 188 StartNewJob(new_job.Pass(), TYPE_SEARCH); |
189 } | 189 } |
190 | 190 |
191 void DriveScheduler::GetChangeList( | 191 void JobScheduler::GetChangeList( |
192 int64 start_changestamp, | 192 int64 start_changestamp, |
193 const google_apis::GetResourceListCallback& callback) { | 193 const google_apis::GetResourceListCallback& callback) { |
194 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 194 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
195 DCHECK(!callback.is_null()); | 195 DCHECK(!callback.is_null()); |
196 | 196 |
197 scoped_ptr<QueueEntry> new_job(new QueueEntry); | 197 scoped_ptr<QueueEntry> new_job(new QueueEntry); |
198 new_job->start_changestamp = start_changestamp; | 198 new_job->start_changestamp = start_changestamp; |
199 new_job->get_resource_list_callback = callback; | 199 new_job->get_resource_list_callback = callback; |
200 | 200 |
201 StartNewJob(new_job.Pass(), TYPE_GET_CHANGE_LIST); | 201 StartNewJob(new_job.Pass(), TYPE_GET_CHANGE_LIST); |
202 } | 202 } |
203 | 203 |
204 void DriveScheduler::ContinueGetResourceList( | 204 void JobScheduler::ContinueGetResourceList( |
205 const GURL& feed_url, | 205 const GURL& feed_url, |
206 const google_apis::GetResourceListCallback& callback) { | 206 const google_apis::GetResourceListCallback& callback) { |
207 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 207 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
208 DCHECK(!callback.is_null()); | 208 DCHECK(!callback.is_null()); |
209 | 209 |
210 scoped_ptr<QueueEntry> new_job(new QueueEntry); | 210 scoped_ptr<QueueEntry> new_job(new QueueEntry); |
211 new_job->feed_url = feed_url; | 211 new_job->feed_url = feed_url; |
212 new_job->get_resource_list_callback = callback; | 212 new_job->get_resource_list_callback = callback; |
213 | 213 |
214 StartNewJob(new_job.Pass(), TYPE_CONTINUE_GET_RESOURCE_LIST); | 214 StartNewJob(new_job.Pass(), TYPE_CONTINUE_GET_RESOURCE_LIST); |
215 } | 215 } |
216 | 216 |
217 void DriveScheduler::GetResourceEntry( | 217 void JobScheduler::GetResourceEntry( |
218 const std::string& resource_id, | 218 const std::string& resource_id, |
219 const DriveClientContext& context, | 219 const DriveClientContext& context, |
220 const google_apis::GetResourceEntryCallback& callback) { | 220 const google_apis::GetResourceEntryCallback& callback) { |
221 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 221 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
222 DCHECK(!callback.is_null()); | 222 DCHECK(!callback.is_null()); |
223 | 223 |
224 scoped_ptr<QueueEntry> new_job(new QueueEntry); | 224 scoped_ptr<QueueEntry> new_job(new QueueEntry); |
225 new_job->resource_id = resource_id; | 225 new_job->resource_id = resource_id; |
226 new_job->context = context; | 226 new_job->context = context; |
227 new_job->get_resource_entry_callback = callback; | 227 new_job->get_resource_entry_callback = callback; |
228 | 228 |
229 StartNewJob(new_job.Pass(), TYPE_GET_RESOURCE_ENTRY); | 229 StartNewJob(new_job.Pass(), TYPE_GET_RESOURCE_ENTRY); |
230 } | 230 } |
231 | 231 |
232 void DriveScheduler::DeleteResource( | 232 void JobScheduler::DeleteResource( |
233 const std::string& resource_id, | 233 const std::string& resource_id, |
234 const google_apis::EntryActionCallback& callback) { | 234 const google_apis::EntryActionCallback& callback) { |
235 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 235 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
236 DCHECK(!callback.is_null()); | 236 DCHECK(!callback.is_null()); |
237 | 237 |
238 scoped_ptr<QueueEntry> new_job(new QueueEntry); | 238 scoped_ptr<QueueEntry> new_job(new QueueEntry); |
239 new_job->resource_id = resource_id; | 239 new_job->resource_id = resource_id; |
240 new_job->entry_action_callback = callback; | 240 new_job->entry_action_callback = callback; |
241 | 241 |
242 StartNewJob(new_job.Pass(), TYPE_DELETE_RESOURCE); | 242 StartNewJob(new_job.Pass(), TYPE_DELETE_RESOURCE); |
243 } | 243 } |
244 | 244 |
245 | 245 |
246 void DriveScheduler::CopyHostedDocument( | 246 void JobScheduler::CopyHostedDocument( |
247 const std::string& resource_id, | 247 const std::string& resource_id, |
248 const std::string& new_name, | 248 const std::string& new_name, |
249 const google_apis::GetResourceEntryCallback& callback) { | 249 const google_apis::GetResourceEntryCallback& callback) { |
250 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 250 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
251 DCHECK(!callback.is_null()); | 251 DCHECK(!callback.is_null()); |
252 | 252 |
253 scoped_ptr<QueueEntry> new_job(new QueueEntry); | 253 scoped_ptr<QueueEntry> new_job(new QueueEntry); |
254 new_job->resource_id = resource_id; | 254 new_job->resource_id = resource_id; |
255 new_job->new_name = new_name; | 255 new_job->new_name = new_name; |
256 new_job->get_resource_entry_callback = callback; | 256 new_job->get_resource_entry_callback = callback; |
257 | 257 |
258 StartNewJob(new_job.Pass(), TYPE_COPY_HOSTED_DOCUMENT); | 258 StartNewJob(new_job.Pass(), TYPE_COPY_HOSTED_DOCUMENT); |
259 } | 259 } |
260 | 260 |
261 void DriveScheduler::RenameResource( | 261 void JobScheduler::RenameResource( |
262 const std::string& resource_id, | 262 const std::string& resource_id, |
263 const std::string& new_name, | 263 const std::string& new_name, |
264 const google_apis::EntryActionCallback& callback) { | 264 const google_apis::EntryActionCallback& callback) { |
265 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 265 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
266 DCHECK(!callback.is_null()); | 266 DCHECK(!callback.is_null()); |
267 | 267 |
268 scoped_ptr<QueueEntry> new_job(new QueueEntry); | 268 scoped_ptr<QueueEntry> new_job(new QueueEntry); |
269 new_job->resource_id = resource_id; | 269 new_job->resource_id = resource_id; |
270 new_job->new_name = new_name; | 270 new_job->new_name = new_name; |
271 new_job->entry_action_callback = callback; | 271 new_job->entry_action_callback = callback; |
272 | 272 |
273 StartNewJob(new_job.Pass(), TYPE_RENAME_RESOURCE); | 273 StartNewJob(new_job.Pass(), TYPE_RENAME_RESOURCE); |
274 } | 274 } |
275 | 275 |
276 void DriveScheduler::AddResourceToDirectory( | 276 void JobScheduler::AddResourceToDirectory( |
277 const std::string& parent_resource_id, | 277 const std::string& parent_resource_id, |
278 const std::string& resource_id, | 278 const std::string& resource_id, |
279 const google_apis::EntryActionCallback& callback) { | 279 const google_apis::EntryActionCallback& callback) { |
280 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 280 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
281 DCHECK(!callback.is_null()); | 281 DCHECK(!callback.is_null()); |
282 | 282 |
283 scoped_ptr<QueueEntry> new_job(new QueueEntry); | 283 scoped_ptr<QueueEntry> new_job(new QueueEntry); |
284 new_job->parent_resource_id = parent_resource_id; | 284 new_job->parent_resource_id = parent_resource_id; |
285 new_job->resource_id = resource_id; | 285 new_job->resource_id = resource_id; |
286 new_job->entry_action_callback = callback; | 286 new_job->entry_action_callback = callback; |
287 | 287 |
288 StartNewJob(new_job.Pass(), TYPE_ADD_RESOURCE_TO_DIRECTORY); | 288 StartNewJob(new_job.Pass(), TYPE_ADD_RESOURCE_TO_DIRECTORY); |
289 } | 289 } |
290 | 290 |
291 void DriveScheduler::RemoveResourceFromDirectory( | 291 void JobScheduler::RemoveResourceFromDirectory( |
292 const std::string& parent_resource_id, | 292 const std::string& parent_resource_id, |
293 const std::string& resource_id, | 293 const std::string& resource_id, |
294 const google_apis::EntryActionCallback& callback) { | 294 const google_apis::EntryActionCallback& callback) { |
295 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 295 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
296 | 296 |
297 scoped_ptr<QueueEntry> new_job(new QueueEntry); | 297 scoped_ptr<QueueEntry> new_job(new QueueEntry); |
298 new_job->parent_resource_id = parent_resource_id; | 298 new_job->parent_resource_id = parent_resource_id; |
299 new_job->resource_id = resource_id; | 299 new_job->resource_id = resource_id; |
300 new_job->entry_action_callback = callback; | 300 new_job->entry_action_callback = callback; |
301 | 301 |
302 StartNewJob(new_job.Pass(), TYPE_REMOVE_RESOURCE_FROM_DIRECTORY); | 302 StartNewJob(new_job.Pass(), TYPE_REMOVE_RESOURCE_FROM_DIRECTORY); |
303 } | 303 } |
304 | 304 |
305 void DriveScheduler::AddNewDirectory( | 305 void JobScheduler::AddNewDirectory( |
306 const std::string& parent_resource_id, | 306 const std::string& parent_resource_id, |
307 const std::string& directory_name, | 307 const std::string& directory_name, |
308 const google_apis::GetResourceEntryCallback& callback) { | 308 const google_apis::GetResourceEntryCallback& callback) { |
309 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 309 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
310 | 310 |
311 scoped_ptr<QueueEntry> new_job(new QueueEntry); | 311 scoped_ptr<QueueEntry> new_job(new QueueEntry); |
312 new_job->parent_resource_id = parent_resource_id; | 312 new_job->parent_resource_id = parent_resource_id; |
313 new_job->directory_name = directory_name; | 313 new_job->directory_name = directory_name; |
314 new_job->get_resource_entry_callback = callback; | 314 new_job->get_resource_entry_callback = callback; |
315 | 315 |
316 StartNewJob(new_job.Pass(), TYPE_ADD_NEW_DIRECTORY); | 316 StartNewJob(new_job.Pass(), TYPE_ADD_NEW_DIRECTORY); |
317 } | 317 } |
318 | 318 |
319 void DriveScheduler::DownloadFile( | 319 void JobScheduler::DownloadFile( |
320 const base::FilePath& virtual_path, | 320 const base::FilePath& virtual_path, |
321 const base::FilePath& local_cache_path, | 321 const base::FilePath& local_cache_path, |
322 const GURL& download_url, | 322 const GURL& download_url, |
323 const DriveClientContext& context, | 323 const DriveClientContext& context, |
324 const google_apis::DownloadActionCallback& download_action_callback, | 324 const google_apis::DownloadActionCallback& download_action_callback, |
325 const google_apis::GetContentCallback& get_content_callback) { | 325 const google_apis::GetContentCallback& get_content_callback) { |
326 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 326 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
327 | 327 |
328 scoped_ptr<QueueEntry> new_job(new QueueEntry); | 328 scoped_ptr<QueueEntry> new_job(new QueueEntry); |
329 new_job->drive_file_path = virtual_path; | 329 new_job->drive_file_path = virtual_path; |
330 new_job->local_file_path = local_cache_path; | 330 new_job->local_file_path = local_cache_path; |
331 new_job->download_url = download_url; | 331 new_job->download_url = download_url; |
332 new_job->context = context; | 332 new_job->context = context; |
333 new_job->download_action_callback = download_action_callback; | 333 new_job->download_action_callback = download_action_callback; |
334 new_job->get_content_callback = get_content_callback; | 334 new_job->get_content_callback = get_content_callback; |
335 | 335 |
336 StartNewJob(new_job.Pass(), TYPE_DOWNLOAD_FILE); | 336 StartNewJob(new_job.Pass(), TYPE_DOWNLOAD_FILE); |
337 } | 337 } |
338 | 338 |
339 void DriveScheduler::UploadNewFile( | 339 void JobScheduler::UploadNewFile( |
340 const std::string& parent_resource_id, | 340 const std::string& parent_resource_id, |
341 const base::FilePath& drive_file_path, | 341 const base::FilePath& drive_file_path, |
342 const base::FilePath& local_file_path, | 342 const base::FilePath& local_file_path, |
343 const std::string& title, | 343 const std::string& title, |
344 const std::string& content_type, | 344 const std::string& content_type, |
345 const DriveClientContext& context, | 345 const DriveClientContext& context, |
346 const google_apis::UploadCompletionCallback& callback) { | 346 const google_apis::UploadCompletionCallback& callback) { |
347 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 347 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
348 | 348 |
349 scoped_ptr<QueueEntry> new_job(new QueueEntry); | 349 scoped_ptr<QueueEntry> new_job(new QueueEntry); |
350 new_job->resource_id = parent_resource_id; | 350 new_job->resource_id = parent_resource_id; |
351 new_job->drive_file_path = drive_file_path; | 351 new_job->drive_file_path = drive_file_path; |
352 new_job->local_file_path = local_file_path; | 352 new_job->local_file_path = local_file_path; |
353 new_job->title = title; | 353 new_job->title = title; |
354 new_job->content_type = content_type; | 354 new_job->content_type = content_type; |
355 new_job->upload_completion_callback = callback; | 355 new_job->upload_completion_callback = callback; |
356 new_job->context = context; | 356 new_job->context = context; |
357 | 357 |
358 StartNewJob(new_job.Pass(), TYPE_UPLOAD_NEW_FILE); | 358 StartNewJob(new_job.Pass(), TYPE_UPLOAD_NEW_FILE); |
359 } | 359 } |
360 | 360 |
361 void DriveScheduler::UploadExistingFile( | 361 void JobScheduler::UploadExistingFile( |
362 const std::string& resource_id, | 362 const std::string& resource_id, |
363 const base::FilePath& drive_file_path, | 363 const base::FilePath& drive_file_path, |
364 const base::FilePath& local_file_path, | 364 const base::FilePath& local_file_path, |
365 const std::string& content_type, | 365 const std::string& content_type, |
366 const std::string& etag, | 366 const std::string& etag, |
367 const DriveClientContext& context, | 367 const DriveClientContext& context, |
368 const google_apis::UploadCompletionCallback& upload_completion_callback) { | 368 const google_apis::UploadCompletionCallback& upload_completion_callback) { |
369 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 369 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
370 | 370 |
371 scoped_ptr<QueueEntry> new_job(new QueueEntry); | 371 scoped_ptr<QueueEntry> new_job(new QueueEntry); |
372 new_job->resource_id = resource_id; | 372 new_job->resource_id = resource_id; |
373 new_job->drive_file_path = drive_file_path; | 373 new_job->drive_file_path = drive_file_path; |
374 new_job->local_file_path = local_file_path; | 374 new_job->local_file_path = local_file_path; |
375 new_job->content_type = content_type; | 375 new_job->content_type = content_type; |
376 new_job->etag = etag; | 376 new_job->etag = etag; |
377 new_job->upload_completion_callback = upload_completion_callback; | 377 new_job->upload_completion_callback = upload_completion_callback; |
378 new_job->context = context; | 378 new_job->context = context; |
379 | 379 |
380 StartNewJob(new_job.Pass(), TYPE_UPLOAD_EXISTING_FILE); | 380 StartNewJob(new_job.Pass(), TYPE_UPLOAD_EXISTING_FILE); |
381 } | 381 } |
382 | 382 |
383 void DriveScheduler::StartNewJob(scoped_ptr<QueueEntry> job, JobType type) { | 383 void JobScheduler::StartNewJob(scoped_ptr<QueueEntry> job, JobType type) { |
384 // job_info is owned by job_map_ and released when it is removed in OnJobDone. | 384 // job_info is owned by job_map_ and released when it is removed in OnJobDone. |
385 JobInfo* job_info = new JobInfo(type); | 385 JobInfo* job_info = new JobInfo(type); |
386 job->job_id = job_info->job_id = job_map_.Add(job_info); | 386 job->job_id = job_info->job_id = job_map_.Add(job_info); |
387 job_info->file_path = job->drive_file_path; | 387 job_info->file_path = job->drive_file_path; |
388 | 388 |
389 QueueJob(job.Pass()); | 389 QueueJob(job.Pass()); |
390 NotifyJobAdded(*job_info); | 390 NotifyJobAdded(*job_info); |
391 StartJobLoop(GetJobQueueType(type)); | 391 StartJobLoop(GetJobQueueType(type)); |
392 } | 392 } |
393 | 393 |
394 void DriveScheduler::QueueJob(scoped_ptr<QueueEntry> job) { | 394 void JobScheduler::QueueJob(scoped_ptr<QueueEntry> job) { |
395 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 395 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
396 | 396 |
397 JobInfo* job_info = job_map_.Lookup(job->job_id); | 397 JobInfo* job_info = job_map_.Lookup(job->job_id); |
398 DCHECK(job_info); | 398 DCHECK(job_info); |
399 util::Log("Queue job: %s [%d]", | 399 util::Log("Queue job: %s [%d]", |
400 JobTypeToString(job_info->job_type).c_str(), | 400 JobTypeToString(job_info->job_type).c_str(), |
401 job_info->job_id); | 401 job_info->job_id); |
402 | 402 |
403 QueueType queue_type = GetJobQueueType(job_info->job_type); | 403 QueueType queue_type = GetJobQueueType(job_info->job_type); |
404 std::list<QueueEntry*>& queue = queue_[queue_type]; | 404 std::list<QueueEntry*>& queue = queue_[queue_type]; |
405 | 405 |
406 queue.push_back(job.release()); | 406 queue.push_back(job.release()); |
407 queue.sort(&QueueEntry::Compare); | 407 queue.sort(&QueueEntry::Compare); |
408 } | 408 } |
409 | 409 |
410 void DriveScheduler::StartJobLoop(QueueType queue_type) { | 410 void JobScheduler::StartJobLoop(QueueType queue_type) { |
411 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 411 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
412 | 412 |
413 if (jobs_running_[queue_type] < kMaxJobCount[queue_type]) | 413 if (jobs_running_[queue_type] < kMaxJobCount[queue_type]) |
414 DoJobLoop(queue_type); | 414 DoJobLoop(queue_type); |
415 } | 415 } |
416 | 416 |
417 void DriveScheduler::DoJobLoop(QueueType queue_type) { | 417 void JobScheduler::DoJobLoop(QueueType queue_type) { |
418 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 418 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
419 | 419 |
420 if (queue_[queue_type].empty()) { | 420 if (queue_[queue_type].empty()) { |
421 return; | 421 return; |
422 } | 422 } |
423 | 423 |
424 // Check if we should defer based on the first item in the queue | 424 // Check if we should defer based on the first item in the queue |
425 if (ShouldStopJobLoop(queue_type, queue_[queue_type].front()->context)) { | 425 if (ShouldStopJobLoop(queue_type, queue_[queue_type].front()->context)) { |
426 return; | 426 return; |
427 } | 427 } |
(...skipping 14 matching lines...) Expand all Loading... |
442 // The some arguments are evaluated after bind, so we copy the pointer to the | 442 // The some arguments are evaluated after bind, so we copy the pointer to the |
443 // QueueEntry | 443 // QueueEntry |
444 QueueEntry* entry = queue_entry.get(); | 444 QueueEntry* entry = queue_entry.get(); |
445 util::Log("Start job: %s [%d]", | 445 util::Log("Start job: %s [%d]", |
446 JobTypeToString(job_info->job_type).c_str(), | 446 JobTypeToString(job_info->job_type).c_str(), |
447 job_info->job_id); | 447 job_info->job_id); |
448 | 448 |
449 switch (job_info->job_type) { | 449 switch (job_info->job_type) { |
450 case TYPE_GET_ABOUT_RESOURCE: { | 450 case TYPE_GET_ABOUT_RESOURCE: { |
451 drive_service_->GetAboutResource( | 451 drive_service_->GetAboutResource( |
452 base::Bind(&DriveScheduler::OnGetAboutResourceJobDone, | 452 base::Bind(&JobScheduler::OnGetAboutResourceJobDone, |
453 weak_ptr_factory_.GetWeakPtr(), | 453 weak_ptr_factory_.GetWeakPtr(), |
454 base::Passed(&queue_entry))); | 454 base::Passed(&queue_entry))); |
455 } | 455 } |
456 break; | 456 break; |
457 | 457 |
458 case TYPE_GET_ACCOUNT_METADATA: { | 458 case TYPE_GET_ACCOUNT_METADATA: { |
459 drive_service_->GetAccountMetadata( | 459 drive_service_->GetAccountMetadata( |
460 base::Bind(&DriveScheduler::OnGetAccountMetadataJobDone, | 460 base::Bind(&JobScheduler::OnGetAccountMetadataJobDone, |
461 weak_ptr_factory_.GetWeakPtr(), | 461 weak_ptr_factory_.GetWeakPtr(), |
462 base::Passed(&queue_entry))); | 462 base::Passed(&queue_entry))); |
463 } | 463 } |
464 break; | 464 break; |
465 | 465 |
466 case TYPE_GET_APP_LIST: { | 466 case TYPE_GET_APP_LIST: { |
467 drive_service_->GetAppList( | 467 drive_service_->GetAppList( |
468 base::Bind(&DriveScheduler::OnGetAppListJobDone, | 468 base::Bind(&JobScheduler::OnGetAppListJobDone, |
469 weak_ptr_factory_.GetWeakPtr(), | 469 weak_ptr_factory_.GetWeakPtr(), |
470 base::Passed(&queue_entry))); | 470 base::Passed(&queue_entry))); |
471 } | 471 } |
472 break; | 472 break; |
473 | 473 |
474 case TYPE_GET_ALL_RESOURCE_LIST: { | 474 case TYPE_GET_ALL_RESOURCE_LIST: { |
475 drive_service_->GetAllResourceList( | 475 drive_service_->GetAllResourceList( |
476 base::Bind(&DriveScheduler::OnGetResourceListJobDone, | 476 base::Bind(&JobScheduler::OnGetResourceListJobDone, |
477 weak_ptr_factory_.GetWeakPtr(), | 477 weak_ptr_factory_.GetWeakPtr(), |
478 base::Passed(&queue_entry))); | 478 base::Passed(&queue_entry))); |
479 } | 479 } |
480 break; | 480 break; |
481 | 481 |
482 case TYPE_GET_RESOURCE_LIST_IN_DIRECTORY: { | 482 case TYPE_GET_RESOURCE_LIST_IN_DIRECTORY: { |
483 drive_service_->GetResourceListInDirectory( | 483 drive_service_->GetResourceListInDirectory( |
484 entry->directory_resource_id, | 484 entry->directory_resource_id, |
485 base::Bind(&DriveScheduler::OnGetResourceListJobDone, | 485 base::Bind(&JobScheduler::OnGetResourceListJobDone, |
486 weak_ptr_factory_.GetWeakPtr(), | 486 weak_ptr_factory_.GetWeakPtr(), |
487 base::Passed(&queue_entry))); | 487 base::Passed(&queue_entry))); |
488 } | 488 } |
489 break; | 489 break; |
490 | 490 |
491 case TYPE_SEARCH: { | 491 case TYPE_SEARCH: { |
492 drive_service_->Search( | 492 drive_service_->Search( |
493 entry->search_query, | 493 entry->search_query, |
494 base::Bind(&DriveScheduler::OnGetResourceListJobDone, | 494 base::Bind(&JobScheduler::OnGetResourceListJobDone, |
495 weak_ptr_factory_.GetWeakPtr(), | 495 weak_ptr_factory_.GetWeakPtr(), |
496 base::Passed(&queue_entry))); | 496 base::Passed(&queue_entry))); |
497 } | 497 } |
498 break; | 498 break; |
499 | 499 |
500 case TYPE_GET_CHANGE_LIST: { | 500 case TYPE_GET_CHANGE_LIST: { |
501 drive_service_->GetChangeList( | 501 drive_service_->GetChangeList( |
502 entry->start_changestamp, | 502 entry->start_changestamp, |
503 base::Bind(&DriveScheduler::OnGetResourceListJobDone, | 503 base::Bind(&JobScheduler::OnGetResourceListJobDone, |
504 weak_ptr_factory_.GetWeakPtr(), | 504 weak_ptr_factory_.GetWeakPtr(), |
505 base::Passed(&queue_entry))); | 505 base::Passed(&queue_entry))); |
506 } | 506 } |
507 break; | 507 break; |
508 | 508 |
509 case TYPE_CONTINUE_GET_RESOURCE_LIST: { | 509 case TYPE_CONTINUE_GET_RESOURCE_LIST: { |
510 drive_service_->ContinueGetResourceList( | 510 drive_service_->ContinueGetResourceList( |
511 entry->feed_url, | 511 entry->feed_url, |
512 base::Bind(&DriveScheduler::OnGetResourceListJobDone, | 512 base::Bind(&JobScheduler::OnGetResourceListJobDone, |
513 weak_ptr_factory_.GetWeakPtr(), | 513 weak_ptr_factory_.GetWeakPtr(), |
514 base::Passed(&queue_entry))); | 514 base::Passed(&queue_entry))); |
515 } | 515 } |
516 break; | 516 break; |
517 | 517 |
518 case TYPE_GET_RESOURCE_ENTRY: { | 518 case TYPE_GET_RESOURCE_ENTRY: { |
519 drive_service_->GetResourceEntry( | 519 drive_service_->GetResourceEntry( |
520 entry->resource_id, | 520 entry->resource_id, |
521 base::Bind(&DriveScheduler::OnGetResourceEntryJobDone, | 521 base::Bind(&JobScheduler::OnGetResourceEntryJobDone, |
522 weak_ptr_factory_.GetWeakPtr(), | 522 weak_ptr_factory_.GetWeakPtr(), |
523 base::Passed(&queue_entry))); | 523 base::Passed(&queue_entry))); |
524 } | 524 } |
525 break; | 525 break; |
526 | 526 |
527 case TYPE_DELETE_RESOURCE: { | 527 case TYPE_DELETE_RESOURCE: { |
528 drive_service_->DeleteResource( | 528 drive_service_->DeleteResource( |
529 entry->resource_id, | 529 entry->resource_id, |
530 "", // etag | 530 "", // etag |
531 base::Bind(&DriveScheduler::OnEntryActionJobDone, | 531 base::Bind(&JobScheduler::OnEntryActionJobDone, |
532 weak_ptr_factory_.GetWeakPtr(), | 532 weak_ptr_factory_.GetWeakPtr(), |
533 base::Passed(&queue_entry))); | 533 base::Passed(&queue_entry))); |
534 } | 534 } |
535 break; | 535 break; |
536 | 536 |
537 | 537 |
538 case TYPE_COPY_HOSTED_DOCUMENT: { | 538 case TYPE_COPY_HOSTED_DOCUMENT: { |
539 drive_service_->CopyHostedDocument( | 539 drive_service_->CopyHostedDocument( |
540 entry->resource_id, | 540 entry->resource_id, |
541 entry->new_name, | 541 entry->new_name, |
542 base::Bind(&DriveScheduler::OnGetResourceEntryJobDone, | 542 base::Bind(&JobScheduler::OnGetResourceEntryJobDone, |
543 weak_ptr_factory_.GetWeakPtr(), | 543 weak_ptr_factory_.GetWeakPtr(), |
544 base::Passed(&queue_entry))); | 544 base::Passed(&queue_entry))); |
545 } | 545 } |
546 break; | 546 break; |
547 | 547 |
548 case TYPE_RENAME_RESOURCE: { | 548 case TYPE_RENAME_RESOURCE: { |
549 drive_service_->RenameResource( | 549 drive_service_->RenameResource( |
550 entry->resource_id, | 550 entry->resource_id, |
551 entry->new_name, | 551 entry->new_name, |
552 base::Bind(&DriveScheduler::OnEntryActionJobDone, | 552 base::Bind(&JobScheduler::OnEntryActionJobDone, |
553 weak_ptr_factory_.GetWeakPtr(), | 553 weak_ptr_factory_.GetWeakPtr(), |
554 base::Passed(&queue_entry))); | 554 base::Passed(&queue_entry))); |
555 } | 555 } |
556 break; | 556 break; |
557 | 557 |
558 case TYPE_ADD_RESOURCE_TO_DIRECTORY: { | 558 case TYPE_ADD_RESOURCE_TO_DIRECTORY: { |
559 drive_service_->AddResourceToDirectory( | 559 drive_service_->AddResourceToDirectory( |
560 entry->parent_resource_id, | 560 entry->parent_resource_id, |
561 entry->resource_id, | 561 entry->resource_id, |
562 base::Bind(&DriveScheduler::OnEntryActionJobDone, | 562 base::Bind(&JobScheduler::OnEntryActionJobDone, |
563 weak_ptr_factory_.GetWeakPtr(), | 563 weak_ptr_factory_.GetWeakPtr(), |
564 base::Passed(&queue_entry))); | 564 base::Passed(&queue_entry))); |
565 } | 565 } |
566 break; | 566 break; |
567 | 567 |
568 case TYPE_REMOVE_RESOURCE_FROM_DIRECTORY: { | 568 case TYPE_REMOVE_RESOURCE_FROM_DIRECTORY: { |
569 drive_service_->RemoveResourceFromDirectory( | 569 drive_service_->RemoveResourceFromDirectory( |
570 entry->parent_resource_id, | 570 entry->parent_resource_id, |
571 entry->resource_id, | 571 entry->resource_id, |
572 base::Bind(&DriveScheduler::OnEntryActionJobDone, | 572 base::Bind(&JobScheduler::OnEntryActionJobDone, |
573 weak_ptr_factory_.GetWeakPtr(), | 573 weak_ptr_factory_.GetWeakPtr(), |
574 base::Passed(&queue_entry))); | 574 base::Passed(&queue_entry))); |
575 } | 575 } |
576 break; | 576 break; |
577 | 577 |
578 case TYPE_ADD_NEW_DIRECTORY: { | 578 case TYPE_ADD_NEW_DIRECTORY: { |
579 drive_service_->AddNewDirectory( | 579 drive_service_->AddNewDirectory( |
580 entry->parent_resource_id, | 580 entry->parent_resource_id, |
581 entry->directory_name, | 581 entry->directory_name, |
582 base::Bind(&DriveScheduler::OnGetResourceEntryJobDone, | 582 base::Bind(&JobScheduler::OnGetResourceEntryJobDone, |
583 weak_ptr_factory_.GetWeakPtr(), | 583 weak_ptr_factory_.GetWeakPtr(), |
584 base::Passed(&queue_entry))); | 584 base::Passed(&queue_entry))); |
585 } | 585 } |
586 break; | 586 break; |
587 | 587 |
588 case TYPE_DOWNLOAD_FILE: { | 588 case TYPE_DOWNLOAD_FILE: { |
589 drive_service_->DownloadFile( | 589 drive_service_->DownloadFile( |
590 entry->drive_file_path, | 590 entry->drive_file_path, |
591 entry->local_file_path, | 591 entry->local_file_path, |
592 entry->download_url, | 592 entry->download_url, |
593 base::Bind(&DriveScheduler::OnDownloadActionJobDone, | 593 base::Bind(&JobScheduler::OnDownloadActionJobDone, |
594 weak_ptr_factory_.GetWeakPtr(), | 594 weak_ptr_factory_.GetWeakPtr(), |
595 base::Passed(&queue_entry)), | 595 base::Passed(&queue_entry)), |
596 entry->get_content_callback, | 596 entry->get_content_callback, |
597 base::Bind(&DriveScheduler::UpdateProgress, | 597 base::Bind(&JobScheduler::UpdateProgress, |
598 weak_ptr_factory_.GetWeakPtr(), | 598 weak_ptr_factory_.GetWeakPtr(), |
599 job_info->job_id)); | 599 job_info->job_id)); |
600 } | 600 } |
601 break; | 601 break; |
602 | 602 |
603 case TYPE_UPLOAD_NEW_FILE: { | 603 case TYPE_UPLOAD_NEW_FILE: { |
604 uploader_->UploadNewFile( | 604 uploader_->UploadNewFile( |
605 entry->resource_id, | 605 entry->resource_id, |
606 entry->drive_file_path, | 606 entry->drive_file_path, |
607 entry->local_file_path, | 607 entry->local_file_path, |
608 entry->title, | 608 entry->title, |
609 entry->content_type, | 609 entry->content_type, |
610 base::Bind(&DriveScheduler::OnUploadCompletionJobDone, | 610 base::Bind(&JobScheduler::OnUploadCompletionJobDone, |
611 weak_ptr_factory_.GetWeakPtr(), | 611 weak_ptr_factory_.GetWeakPtr(), |
612 base::Passed(&queue_entry)), | 612 base::Passed(&queue_entry)), |
613 base::Bind(&DriveScheduler::UpdateProgress, | 613 base::Bind(&JobScheduler::UpdateProgress, |
614 weak_ptr_factory_.GetWeakPtr(), | 614 weak_ptr_factory_.GetWeakPtr(), |
615 job_info->job_id)); | 615 job_info->job_id)); |
616 } | 616 } |
617 break; | 617 break; |
618 | 618 |
619 case TYPE_UPLOAD_EXISTING_FILE: { | 619 case TYPE_UPLOAD_EXISTING_FILE: { |
620 uploader_->UploadExistingFile( | 620 uploader_->UploadExistingFile( |
621 entry->resource_id, | 621 entry->resource_id, |
622 entry->drive_file_path, | 622 entry->drive_file_path, |
623 entry->local_file_path, | 623 entry->local_file_path, |
624 entry->content_type, | 624 entry->content_type, |
625 entry->etag, | 625 entry->etag, |
626 base::Bind(&DriveScheduler::OnUploadCompletionJobDone, | 626 base::Bind(&JobScheduler::OnUploadCompletionJobDone, |
627 weak_ptr_factory_.GetWeakPtr(), | 627 weak_ptr_factory_.GetWeakPtr(), |
628 base::Passed(&queue_entry)), | 628 base::Passed(&queue_entry)), |
629 base::Bind(&DriveScheduler::UpdateProgress, | 629 base::Bind(&JobScheduler::UpdateProgress, |
630 weak_ptr_factory_.GetWeakPtr(), | 630 weak_ptr_factory_.GetWeakPtr(), |
631 job_info->job_id)); | 631 job_info->job_id)); |
632 } | 632 } |
633 break; | 633 break; |
634 | 634 |
635 // There is no default case so that there will be a compiler error if a type | 635 // There is no default case so that there will be a compiler error if a type |
636 // is added but unhandled. | 636 // is added but unhandled. |
637 } | 637 } |
638 } | 638 } |
639 | 639 |
640 bool DriveScheduler::ShouldStopJobLoop(QueueType queue_type, | 640 bool JobScheduler::ShouldStopJobLoop(QueueType queue_type, |
641 const DriveClientContext& context) { | 641 const DriveClientContext& context) { |
642 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 642 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
643 | 643 |
644 // Should stop if the gdata feature was disabled while running the fetch | 644 // Should stop if the gdata feature was disabled while running the fetch |
645 // loop. | 645 // loop. |
646 if (profile_->GetPrefs()->GetBoolean(prefs::kDisableDrive)) | 646 if (profile_->GetPrefs()->GetBoolean(prefs::kDisableDrive)) |
647 return true; | 647 return true; |
648 | 648 |
649 // Should stop if the network is not online. | 649 // Should stop if the network is not online. |
650 if (net::NetworkChangeNotifier::IsOffline()) | 650 if (net::NetworkChangeNotifier::IsOffline()) |
651 return true; | 651 return true; |
(...skipping 13 matching lines...) Expand all Loading... |
665 if (should_stop_on_cellular_network && | 665 if (should_stop_on_cellular_network && |
666 profile_->GetPrefs()->GetBoolean(prefs::kDisableDriveOverCellular) && | 666 profile_->GetPrefs()->GetBoolean(prefs::kDisableDriveOverCellular) && |
667 net::NetworkChangeNotifier::IsConnectionCellular( | 667 net::NetworkChangeNotifier::IsConnectionCellular( |
668 net::NetworkChangeNotifier::GetConnectionType())) { | 668 net::NetworkChangeNotifier::GetConnectionType())) { |
669 return true; | 669 return true; |
670 } | 670 } |
671 | 671 |
672 return false; | 672 return false; |
673 } | 673 } |
674 | 674 |
675 void DriveScheduler::ThrottleAndContinueJobLoop(QueueType queue_type) { | 675 void JobScheduler::ThrottleAndContinueJobLoop(QueueType queue_type) { |
676 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 676 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
677 | 677 |
678 if (throttle_count_ < kMaxThrottleCount) | 678 if (throttle_count_ < kMaxThrottleCount) |
679 throttle_count_++; | 679 throttle_count_++; |
680 | 680 |
681 base::TimeDelta delay; | 681 base::TimeDelta delay; |
682 if (disable_throttling_) { | 682 if (disable_throttling_) { |
683 delay = base::TimeDelta::FromSeconds(0); | 683 delay = base::TimeDelta::FromSeconds(0); |
684 } else { | 684 } else { |
685 delay = | 685 delay = |
686 base::TimeDelta::FromSeconds(pow(2, throttle_count_ - 1)) + | 686 base::TimeDelta::FromSeconds(pow(2, throttle_count_ - 1)) + |
687 base::TimeDelta::FromMilliseconds(base::RandInt(0, 1000)); | 687 base::TimeDelta::FromMilliseconds(base::RandInt(0, 1000)); |
688 } | 688 } |
689 VLOG(1) << "Throttling for " << delay.InMillisecondsF(); | 689 VLOG(1) << "Throttling for " << delay.InMillisecondsF(); |
690 | 690 |
691 const bool posted = base::MessageLoopProxy::current()->PostDelayedTask( | 691 const bool posted = base::MessageLoopProxy::current()->PostDelayedTask( |
692 FROM_HERE, | 692 FROM_HERE, |
693 base::Bind(&DriveScheduler::DoJobLoop, | 693 base::Bind(&JobScheduler::DoJobLoop, |
694 weak_ptr_factory_.GetWeakPtr(), | 694 weak_ptr_factory_.GetWeakPtr(), |
695 queue_type), | 695 queue_type), |
696 delay); | 696 delay); |
697 DCHECK(posted); | 697 DCHECK(posted); |
698 } | 698 } |
699 | 699 |
700 void DriveScheduler::ResetThrottleAndContinueJobLoop(QueueType queue_type) { | 700 void JobScheduler::ResetThrottleAndContinueJobLoop(QueueType queue_type) { |
701 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 701 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
702 | 702 |
703 // Post a task to continue the job loop. This allows us to finish handling | 703 // Post a task to continue the job loop. This allows us to finish handling |
704 // the current job before starting the next one. | 704 // the current job before starting the next one. |
705 throttle_count_ = 0; | 705 throttle_count_ = 0; |
706 base::MessageLoopProxy::current()->PostTask(FROM_HERE, | 706 base::MessageLoopProxy::current()->PostTask(FROM_HERE, |
707 base::Bind(&DriveScheduler::DoJobLoop, | 707 base::Bind(&JobScheduler::DoJobLoop, |
708 weak_ptr_factory_.GetWeakPtr(), | 708 weak_ptr_factory_.GetWeakPtr(), |
709 queue_type)); | 709 queue_type)); |
710 } | 710 } |
711 | 711 |
712 scoped_ptr<DriveScheduler::QueueEntry> DriveScheduler::OnJobDone( | 712 scoped_ptr<JobScheduler::QueueEntry> JobScheduler::OnJobDone( |
713 scoped_ptr<DriveScheduler::QueueEntry> queue_entry, | 713 scoped_ptr<JobScheduler::QueueEntry> queue_entry, |
714 FileError error) { | 714 FileError error) { |
715 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 715 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
716 | 716 |
717 JobInfo* job_info = job_map_.Lookup(queue_entry->job_id); | 717 JobInfo* job_info = job_map_.Lookup(queue_entry->job_id); |
718 DCHECK(job_info); | 718 DCHECK(job_info); |
719 QueueType queue_type = GetJobQueueType(job_info->job_type); | 719 QueueType queue_type = GetJobQueueType(job_info->job_type); |
720 | 720 |
721 const base::TimeDelta elapsed = base::Time::Now() - job_info->start_time; | 721 const base::TimeDelta elapsed = base::Time::Now() - job_info->start_time; |
722 util::Log("Job done: %s [%d] => %s (elapsed time: %sms)", | 722 util::Log("Job done: %s [%d] => %s (elapsed time: %sms)", |
723 JobTypeToString(job_info->job_type).c_str(), | 723 JobTypeToString(job_info->job_type).c_str(), |
724 job_info->job_id, | 724 job_info->job_id, |
725 FileErrorToString(error).c_str(), | 725 FileErrorToString(error).c_str(), |
726 base::Int64ToString(elapsed.InMilliseconds()).c_str()); | 726 base::Int64ToString(elapsed.InMilliseconds()).c_str()); |
727 | 727 |
728 // Decrement the number of jobs for this queue. | 728 // Decrement the number of jobs for this queue. |
729 --jobs_running_[queue_type]; | 729 --jobs_running_[queue_type]; |
730 | 730 |
731 // Retry, depending on the error. | 731 // Retry, depending on the error. |
732 if (error == FILE_ERROR_THROTTLED) { | 732 if (error == FILE_ERROR_THROTTLED) { |
733 job_info->state = STATE_RETRY; | 733 job_info->state = STATE_RETRY; |
734 NotifyJobUpdated(*job_info); | 734 NotifyJobUpdated(*job_info); |
735 | 735 |
736 // Requeue the job. | 736 // Requeue the job. |
737 QueueJob(queue_entry.Pass()); | 737 QueueJob(queue_entry.Pass()); |
738 | 738 |
739 ThrottleAndContinueJobLoop(queue_type); | 739 ThrottleAndContinueJobLoop(queue_type); |
740 | 740 |
741 return scoped_ptr<DriveScheduler::QueueEntry>(); | 741 return scoped_ptr<JobScheduler::QueueEntry>(); |
742 } else { | 742 } else { |
743 NotifyJobDone(*job_info, error); | 743 NotifyJobDone(*job_info, error); |
744 // The job has finished, no retry will happen in the scheduler. Now we can | 744 // The job has finished, no retry will happen in the scheduler. Now we can |
745 // remove the job info from the map. This is the only place of the removal. | 745 // remove the job info from the map. This is the only place of the removal. |
746 job_map_.Remove(queue_entry->job_id); | 746 job_map_.Remove(queue_entry->job_id); |
747 | 747 |
748 ResetThrottleAndContinueJobLoop(queue_type); | 748 ResetThrottleAndContinueJobLoop(queue_type); |
749 | 749 |
750 // Send the entry back. | 750 // Send the entry back. |
751 return queue_entry.Pass(); | 751 return queue_entry.Pass(); |
752 } | 752 } |
753 } | 753 } |
754 | 754 |
755 void DriveScheduler::OnGetResourceListJobDone( | 755 void JobScheduler::OnGetResourceListJobDone( |
756 scoped_ptr<DriveScheduler::QueueEntry> queue_entry, | 756 scoped_ptr<JobScheduler::QueueEntry> queue_entry, |
757 google_apis::GDataErrorCode error, | 757 google_apis::GDataErrorCode error, |
758 scoped_ptr<google_apis::ResourceList> resource_list) { | 758 scoped_ptr<google_apis::ResourceList> resource_list) { |
759 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 759 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
760 | 760 |
761 FileError drive_error(util::GDataToFileError(error)); | 761 FileError drive_error(util::GDataToFileError(error)); |
762 | 762 |
763 queue_entry = OnJobDone(queue_entry.Pass(), drive_error); | 763 queue_entry = OnJobDone(queue_entry.Pass(), drive_error); |
764 | 764 |
765 if (!queue_entry) | 765 if (!queue_entry) |
766 return; | 766 return; |
767 | 767 |
768 // Handle the callback. | 768 // Handle the callback. |
769 base::MessageLoopProxy::current()->PostTask( | 769 base::MessageLoopProxy::current()->PostTask( |
770 FROM_HERE, | 770 FROM_HERE, |
771 base::Bind(queue_entry->get_resource_list_callback, | 771 base::Bind(queue_entry->get_resource_list_callback, |
772 error, | 772 error, |
773 base::Passed(&resource_list))); | 773 base::Passed(&resource_list))); |
774 } | 774 } |
775 | 775 |
776 void DriveScheduler::OnGetResourceEntryJobDone( | 776 void JobScheduler::OnGetResourceEntryJobDone( |
777 scoped_ptr<DriveScheduler::QueueEntry> queue_entry, | 777 scoped_ptr<JobScheduler::QueueEntry> queue_entry, |
778 google_apis::GDataErrorCode error, | 778 google_apis::GDataErrorCode error, |
779 scoped_ptr<google_apis::ResourceEntry> entry) { | 779 scoped_ptr<google_apis::ResourceEntry> entry) { |
780 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 780 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
781 | 781 |
782 FileError drive_error(util::GDataToFileError(error)); | 782 FileError drive_error(util::GDataToFileError(error)); |
783 | 783 |
784 queue_entry = OnJobDone(queue_entry.Pass(), drive_error); | 784 queue_entry = OnJobDone(queue_entry.Pass(), drive_error); |
785 | 785 |
786 if (!queue_entry) | 786 if (!queue_entry) |
787 return; | 787 return; |
788 | 788 |
789 // Handle the callback. | 789 // Handle the callback. |
790 base::MessageLoopProxy::current()->PostTask( | 790 base::MessageLoopProxy::current()->PostTask( |
791 FROM_HERE, | 791 FROM_HERE, |
792 base::Bind(queue_entry->get_resource_entry_callback, | 792 base::Bind(queue_entry->get_resource_entry_callback, |
793 error, | 793 error, |
794 base::Passed(&entry))); | 794 base::Passed(&entry))); |
795 } | 795 } |
796 | 796 |
797 void DriveScheduler::OnGetAboutResourceJobDone( | 797 void JobScheduler::OnGetAboutResourceJobDone( |
798 scoped_ptr<QueueEntry> queue_entry, | 798 scoped_ptr<QueueEntry> queue_entry, |
799 google_apis::GDataErrorCode error, | 799 google_apis::GDataErrorCode error, |
800 scoped_ptr<google_apis::AboutResource> about_resource) { | 800 scoped_ptr<google_apis::AboutResource> about_resource) { |
801 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 801 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
802 | 802 |
803 FileError drive_error(util::GDataToFileError(error)); | 803 FileError drive_error(util::GDataToFileError(error)); |
804 | 804 |
805 queue_entry = OnJobDone(queue_entry.Pass(), drive_error); | 805 queue_entry = OnJobDone(queue_entry.Pass(), drive_error); |
806 | 806 |
807 if (!queue_entry) | 807 if (!queue_entry) |
808 return; | 808 return; |
809 | 809 |
810 // Handle the callback. | 810 // Handle the callback. |
811 queue_entry->get_about_resource_callback.Run(error, about_resource.Pass()); | 811 queue_entry->get_about_resource_callback.Run(error, about_resource.Pass()); |
812 } | 812 } |
813 | 813 |
814 void DriveScheduler::OnGetAccountMetadataJobDone( | 814 void JobScheduler::OnGetAccountMetadataJobDone( |
815 scoped_ptr<QueueEntry> queue_entry, | 815 scoped_ptr<QueueEntry> queue_entry, |
816 google_apis::GDataErrorCode error, | 816 google_apis::GDataErrorCode error, |
817 scoped_ptr<google_apis::AccountMetadata> account_metadata) { | 817 scoped_ptr<google_apis::AccountMetadata> account_metadata) { |
818 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 818 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
819 | 819 |
820 FileError drive_error(util::GDataToFileError(error)); | 820 FileError drive_error(util::GDataToFileError(error)); |
821 | 821 |
822 queue_entry = OnJobDone(queue_entry.Pass(), drive_error); | 822 queue_entry = OnJobDone(queue_entry.Pass(), drive_error); |
823 | 823 |
824 if (!queue_entry) | 824 if (!queue_entry) |
825 return; | 825 return; |
826 | 826 |
827 // Handle the callback. | 827 // Handle the callback. |
828 queue_entry->get_account_metadata_callback.Run(error, | 828 queue_entry->get_account_metadata_callback.Run(error, |
829 account_metadata.Pass()); | 829 account_metadata.Pass()); |
830 } | 830 } |
831 | 831 |
832 void DriveScheduler::OnGetAppListJobDone( | 832 void JobScheduler::OnGetAppListJobDone( |
833 scoped_ptr<DriveScheduler::QueueEntry> queue_entry, | 833 scoped_ptr<JobScheduler::QueueEntry> queue_entry, |
834 google_apis::GDataErrorCode error, | 834 google_apis::GDataErrorCode error, |
835 scoped_ptr<google_apis::AppList> app_list) { | 835 scoped_ptr<google_apis::AppList> app_list) { |
836 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 836 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
837 | 837 |
838 FileError drive_error(util::GDataToFileError(error)); | 838 FileError drive_error(util::GDataToFileError(error)); |
839 | 839 |
840 queue_entry = OnJobDone(queue_entry.Pass(), drive_error); | 840 queue_entry = OnJobDone(queue_entry.Pass(), drive_error); |
841 | 841 |
842 if (!queue_entry) | 842 if (!queue_entry) |
843 return; | 843 return; |
844 | 844 |
845 // Handle the callback. | 845 // Handle the callback. |
846 queue_entry->get_app_list_callback.Run(error, app_list.Pass()); | 846 queue_entry->get_app_list_callback.Run(error, app_list.Pass()); |
847 } | 847 } |
848 | 848 |
849 void DriveScheduler::OnEntryActionJobDone( | 849 void JobScheduler::OnEntryActionJobDone( |
850 scoped_ptr<DriveScheduler::QueueEntry> queue_entry, | 850 scoped_ptr<JobScheduler::QueueEntry> queue_entry, |
851 google_apis::GDataErrorCode error) { | 851 google_apis::GDataErrorCode error) { |
852 FileError drive_error(util::GDataToFileError(error)); | 852 FileError drive_error(util::GDataToFileError(error)); |
853 | 853 |
854 queue_entry = OnJobDone(queue_entry.Pass(), drive_error); | 854 queue_entry = OnJobDone(queue_entry.Pass(), drive_error); |
855 | 855 |
856 if (!queue_entry) | 856 if (!queue_entry) |
857 return; | 857 return; |
858 | 858 |
859 // Handle the callback. | 859 // Handle the callback. |
860 DCHECK(!queue_entry->entry_action_callback.is_null()); | 860 DCHECK(!queue_entry->entry_action_callback.is_null()); |
861 queue_entry->entry_action_callback.Run(error); | 861 queue_entry->entry_action_callback.Run(error); |
862 } | 862 } |
863 | 863 |
864 void DriveScheduler::OnDownloadActionJobDone( | 864 void JobScheduler::OnDownloadActionJobDone( |
865 scoped_ptr<DriveScheduler::QueueEntry> queue_entry, | 865 scoped_ptr<JobScheduler::QueueEntry> queue_entry, |
866 google_apis::GDataErrorCode error, | 866 google_apis::GDataErrorCode error, |
867 const base::FilePath& temp_file) { | 867 const base::FilePath& temp_file) { |
868 FileError drive_error(util::GDataToFileError(error)); | 868 FileError drive_error(util::GDataToFileError(error)); |
869 | 869 |
870 queue_entry = OnJobDone(queue_entry.Pass(), drive_error); | 870 queue_entry = OnJobDone(queue_entry.Pass(), drive_error); |
871 | 871 |
872 if (!queue_entry) | 872 if (!queue_entry) |
873 return; | 873 return; |
874 | 874 |
875 // Handle the callback. | 875 // Handle the callback. |
876 DCHECK(!queue_entry->download_action_callback.is_null()); | 876 DCHECK(!queue_entry->download_action_callback.is_null()); |
877 queue_entry->download_action_callback.Run(error, temp_file); | 877 queue_entry->download_action_callback.Run(error, temp_file); |
878 } | 878 } |
879 | 879 |
880 void DriveScheduler::OnUploadCompletionJobDone( | 880 void JobScheduler::OnUploadCompletionJobDone( |
881 scoped_ptr<QueueEntry> queue_entry, | 881 scoped_ptr<QueueEntry> queue_entry, |
882 google_apis::DriveUploadError error, | 882 google_apis::DriveUploadError error, |
883 const base::FilePath& drive_path, | 883 const base::FilePath& drive_path, |
884 const base::FilePath& file_path, | 884 const base::FilePath& file_path, |
885 scoped_ptr<google_apis::ResourceEntry> resource_entry) { | 885 scoped_ptr<google_apis::ResourceEntry> resource_entry) { |
886 FileError drive_error(DriveUploadErrorToFileError(error)); | 886 FileError drive_error(DriveUploadErrorToFileError(error)); |
887 | 887 |
888 queue_entry = OnJobDone(queue_entry.Pass(), drive_error); | 888 queue_entry = OnJobDone(queue_entry.Pass(), drive_error); |
889 | 889 |
890 if (!queue_entry) | 890 if (!queue_entry) |
891 return; | 891 return; |
892 | 892 |
893 // Handle the callback. | 893 // Handle the callback. |
894 DCHECK(!queue_entry->upload_completion_callback.is_null()); | 894 DCHECK(!queue_entry->upload_completion_callback.is_null()); |
895 queue_entry->upload_completion_callback.Run( | 895 queue_entry->upload_completion_callback.Run( |
896 error, drive_path, file_path, resource_entry.Pass()); | 896 error, drive_path, file_path, resource_entry.Pass()); |
897 } | 897 } |
898 | 898 |
899 void DriveScheduler::UpdateProgress(JobID job_id, int64 progress, int64 total) { | 899 void JobScheduler::UpdateProgress(JobID job_id, int64 progress, int64 total) { |
900 JobInfo* job_info = job_map_.Lookup(job_id); | 900 JobInfo* job_info = job_map_.Lookup(job_id); |
901 DCHECK(job_info); | 901 DCHECK(job_info); |
902 | 902 |
903 job_info->num_completed_bytes = progress; | 903 job_info->num_completed_bytes = progress; |
904 job_info->num_total_bytes = total; | 904 job_info->num_total_bytes = total; |
905 NotifyJobUpdated(*job_info); | 905 NotifyJobUpdated(*job_info); |
906 } | 906 } |
907 | 907 |
908 void DriveScheduler::OnConnectionTypeChanged( | 908 void JobScheduler::OnConnectionTypeChanged( |
909 net::NetworkChangeNotifier::ConnectionType type) { | 909 net::NetworkChangeNotifier::ConnectionType type) { |
910 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 910 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
911 | 911 |
912 // Resume the job loop if the network is back online. Note that we don't | 912 // Resume the job loop if the network is back online. Note that we don't |
913 // need to check the type of the network as it will be checked in | 913 // need to check the type of the network as it will be checked in |
914 // ShouldStopJobLoop() as soon as the loop is resumed. | 914 // ShouldStopJobLoop() as soon as the loop is resumed. |
915 if (!net::NetworkChangeNotifier::IsOffline()) { | 915 if (!net::NetworkChangeNotifier::IsOffline()) { |
916 for (int i = METADATA_QUEUE; i < NUM_QUEUES; ++i) { | 916 for (int i = METADATA_QUEUE; i < NUM_QUEUES; ++i) { |
917 StartJobLoop(static_cast<QueueType>(i)); | 917 StartJobLoop(static_cast<QueueType>(i)); |
918 } | 918 } |
919 } | 919 } |
920 } | 920 } |
921 | 921 |
922 DriveScheduler::QueueType DriveScheduler::GetJobQueueType(JobType type) { | 922 JobScheduler::QueueType JobScheduler::GetJobQueueType(JobType type) { |
923 switch (type) { | 923 switch (type) { |
924 case TYPE_GET_ABOUT_RESOURCE: | 924 case TYPE_GET_ABOUT_RESOURCE: |
925 case TYPE_GET_ACCOUNT_METADATA: | 925 case TYPE_GET_ACCOUNT_METADATA: |
926 case TYPE_GET_APP_LIST: | 926 case TYPE_GET_APP_LIST: |
927 case TYPE_GET_ALL_RESOURCE_LIST: | 927 case TYPE_GET_ALL_RESOURCE_LIST: |
928 case TYPE_GET_RESOURCE_LIST_IN_DIRECTORY: | 928 case TYPE_GET_RESOURCE_LIST_IN_DIRECTORY: |
929 case TYPE_SEARCH: | 929 case TYPE_SEARCH: |
930 case TYPE_GET_CHANGE_LIST: | 930 case TYPE_GET_CHANGE_LIST: |
931 case TYPE_CONTINUE_GET_RESOURCE_LIST: | 931 case TYPE_CONTINUE_GET_RESOURCE_LIST: |
932 case TYPE_GET_RESOURCE_ENTRY: | 932 case TYPE_GET_RESOURCE_ENTRY: |
933 case TYPE_DELETE_RESOURCE: | 933 case TYPE_DELETE_RESOURCE: |
934 case TYPE_COPY_HOSTED_DOCUMENT: | 934 case TYPE_COPY_HOSTED_DOCUMENT: |
935 case TYPE_RENAME_RESOURCE: | 935 case TYPE_RENAME_RESOURCE: |
936 case TYPE_ADD_RESOURCE_TO_DIRECTORY: | 936 case TYPE_ADD_RESOURCE_TO_DIRECTORY: |
937 case TYPE_REMOVE_RESOURCE_FROM_DIRECTORY: | 937 case TYPE_REMOVE_RESOURCE_FROM_DIRECTORY: |
938 case TYPE_ADD_NEW_DIRECTORY: | 938 case TYPE_ADD_NEW_DIRECTORY: |
939 return METADATA_QUEUE; | 939 return METADATA_QUEUE; |
940 | 940 |
941 case TYPE_DOWNLOAD_FILE: | 941 case TYPE_DOWNLOAD_FILE: |
942 case TYPE_UPLOAD_NEW_FILE: | 942 case TYPE_UPLOAD_NEW_FILE: |
943 case TYPE_UPLOAD_EXISTING_FILE: | 943 case TYPE_UPLOAD_EXISTING_FILE: |
944 return FILE_QUEUE; | 944 return FILE_QUEUE; |
945 } | 945 } |
946 NOTREACHED(); | 946 NOTREACHED(); |
947 return FILE_QUEUE; | 947 return FILE_QUEUE; |
948 } | 948 } |
949 | 949 |
950 void DriveScheduler::NotifyJobAdded(const JobInfo& job_info) { | 950 void JobScheduler::NotifyJobAdded(const JobInfo& job_info) { |
951 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 951 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
952 FOR_EACH_OBSERVER(JobListObserver, observer_list_, OnJobAdded(job_info)); | 952 FOR_EACH_OBSERVER(JobListObserver, observer_list_, OnJobAdded(job_info)); |
953 } | 953 } |
954 | 954 |
955 void DriveScheduler::NotifyJobDone(const JobInfo& job_info, | 955 void JobScheduler::NotifyJobDone(const JobInfo& job_info, |
956 FileError error) { | 956 FileError error) { |
957 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 957 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
958 FOR_EACH_OBSERVER(JobListObserver, observer_list_, | 958 FOR_EACH_OBSERVER(JobListObserver, observer_list_, |
959 OnJobDone(job_info, error)); | 959 OnJobDone(job_info, error)); |
960 } | 960 } |
961 | 961 |
962 void DriveScheduler::NotifyJobUpdated(const JobInfo& job_info) { | 962 void JobScheduler::NotifyJobUpdated(const JobInfo& job_info) { |
963 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 963 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
964 FOR_EACH_OBSERVER(JobListObserver, observer_list_, OnJobUpdated(job_info)); | 964 FOR_EACH_OBSERVER(JobListObserver, observer_list_, OnJobUpdated(job_info)); |
965 } | 965 } |
966 | 966 |
967 } // namespace drive | 967 } // namespace drive |
OLD | NEW |