| 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/sync_client.h" | 5 #include "chrome/browser/chromeos/drive/sync_client.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/message_loop/message_loop_proxy.h" | 10 #include "base/message_loop/message_loop_proxy.h" |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 if (error != FILE_ERROR_OK) { | 120 if (error != FILE_ERROR_OK) { |
| 121 LOG(WARNING) << "Failed to pin cache entry: " << local_id; | 121 LOG(WARNING) << "Failed to pin cache entry: " << local_id; |
| 122 continue; | 122 continue; |
| 123 } | 123 } |
| 124 | 124 |
| 125 local_ids->push_back(local_id); | 125 local_ids->push_back(local_id); |
| 126 } | 126 } |
| 127 DCHECK(!it->HasError()); | 127 DCHECK(!it->HasError()); |
| 128 } | 128 } |
| 129 | 129 |
| 130 // Runs the task and returns a dummy cancel closure. |
| 131 base::Closure RunTaskAndReturnDummyCancelClosure(const base::Closure& task) { |
| 132 task.Run(); |
| 133 return base::Closure(); |
| 134 } |
| 135 |
| 130 } // namespace | 136 } // namespace |
| 131 | 137 |
| 132 SyncClient::SyncTask::SyncTask() : state(PENDING), should_run_again(false) {} | 138 SyncClient::SyncTask::SyncTask() : state(PENDING), should_run_again(false) {} |
| 133 SyncClient::SyncTask::~SyncTask() {} | 139 SyncClient::SyncTask::~SyncTask() {} |
| 134 | 140 |
| 135 SyncClient::SyncClient(base::SequencedTaskRunner* blocking_task_runner, | 141 SyncClient::SyncClient(base::SequencedTaskRunner* blocking_task_runner, |
| 136 file_system::OperationObserver* observer, | 142 file_system::OperationObserver* observer, |
| 137 JobScheduler* scheduler, | 143 JobScheduler* scheduler, |
| 138 ResourceMetadata* metadata, | 144 ResourceMetadata* metadata, |
| 139 FileCache* cache, | 145 FileCache* cache, |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 228 void SyncClient::AddFetchTaskInternal(const std::string& local_id, | 234 void SyncClient::AddFetchTaskInternal(const std::string& local_id, |
| 229 const base::TimeDelta& delay) { | 235 const base::TimeDelta& delay) { |
| 230 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 236 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 231 | 237 |
| 232 SyncTask task; | 238 SyncTask task; |
| 233 task.task = base::Bind( | 239 task.task = base::Bind( |
| 234 &file_system::DownloadOperation::EnsureFileDownloadedByLocalId, | 240 &file_system::DownloadOperation::EnsureFileDownloadedByLocalId, |
| 235 base::Unretained(download_operation_.get()), | 241 base::Unretained(download_operation_.get()), |
| 236 local_id, | 242 local_id, |
| 237 ClientContext(BACKGROUND), | 243 ClientContext(BACKGROUND), |
| 238 base::Bind(&SyncClient::OnGetFileContentInitialized, | 244 GetFileContentInitializedCallback(), |
| 239 weak_ptr_factory_.GetWeakPtr()), | |
| 240 google_apis::GetContentCallback(), | 245 google_apis::GetContentCallback(), |
| 241 base::Bind(&SyncClient::OnFetchFileComplete, | 246 base::Bind(&SyncClient::OnFetchFileComplete, |
| 242 weak_ptr_factory_.GetWeakPtr(), | 247 weak_ptr_factory_.GetWeakPtr(), |
| 243 local_id)); | 248 local_id)); |
| 244 AddTask(SyncTasks::key_type(FETCH, local_id), task, delay); | 249 AddTask(SyncTasks::key_type(FETCH, local_id), task, delay); |
| 245 } | 250 } |
| 246 | 251 |
| 247 void SyncClient::AddUpdateTaskInternal(const ClientContext& context, | 252 void SyncClient::AddUpdateTaskInternal(const ClientContext& context, |
| 248 const std::string& local_id, | 253 const std::string& local_id, |
| 249 const base::TimeDelta& delay) { | 254 const base::TimeDelta& delay) { |
| 250 SyncTask task; | 255 SyncTask task; |
| 251 task.task = base::Bind( | 256 task.task = base::Bind( |
| 252 &EntryUpdatePerformer::UpdateEntry, | 257 &RunTaskAndReturnDummyCancelClosure, |
| 253 base::Unretained(entry_update_performer_.get()), | 258 base::Bind(&EntryUpdatePerformer::UpdateEntry, |
| 254 local_id, | 259 base::Unretained(entry_update_performer_.get()), |
| 255 context, | 260 local_id, |
| 256 base::Bind(&SyncClient::OnUpdateComplete, | 261 context, |
| 257 weak_ptr_factory_.GetWeakPtr(), | 262 base::Bind(&SyncClient::OnUpdateComplete, |
| 258 local_id)); | 263 weak_ptr_factory_.GetWeakPtr(), |
| 264 local_id))); |
| 259 AddTask(SyncTasks::key_type(UPDATE, local_id), task, delay); | 265 AddTask(SyncTasks::key_type(UPDATE, local_id), task, delay); |
| 260 } | 266 } |
| 261 | 267 |
| 262 void SyncClient::AddTask(const SyncTasks::key_type& key, | 268 void SyncClient::AddTask(const SyncTasks::key_type& key, |
| 263 const SyncTask& task, | 269 const SyncTask& task, |
| 264 const base::TimeDelta& delay) { | 270 const base::TimeDelta& delay) { |
| 265 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 271 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 266 | 272 |
| 267 SyncTasks::iterator it = tasks_.find(key); | 273 SyncTasks::iterator it = tasks_.find(key); |
| 268 if (it != tasks_.end()) { | 274 if (it != tasks_.end()) { |
| (...skipping 20 matching lines...) Expand all Loading... |
| 289 | 295 |
| 290 void SyncClient::StartTask(const SyncTasks::key_type& key) { | 296 void SyncClient::StartTask(const SyncTasks::key_type& key) { |
| 291 SyncTasks::iterator it = tasks_.find(key); | 297 SyncTasks::iterator it = tasks_.find(key); |
| 292 if (it == tasks_.end()) | 298 if (it == tasks_.end()) |
| 293 return; | 299 return; |
| 294 | 300 |
| 295 SyncTask* task = &it->second; | 301 SyncTask* task = &it->second; |
| 296 switch (task->state) { | 302 switch (task->state) { |
| 297 case PENDING: | 303 case PENDING: |
| 298 task->state = RUNNING; | 304 task->state = RUNNING; |
| 299 task->task.Run(); | 305 task->cancel_closure = task->task.Run(); |
| 300 break; | 306 break; |
| 301 case RUNNING: // Do nothing. | 307 case RUNNING: // Do nothing. |
| 302 break; | 308 break; |
| 303 } | 309 } |
| 304 } | 310 } |
| 305 | 311 |
| 306 void SyncClient::OnGetLocalIdsOfBacklog( | 312 void SyncClient::OnGetLocalIdsOfBacklog( |
| 307 const std::vector<std::string>* to_fetch, | 313 const std::vector<std::string>* to_fetch, |
| 308 const std::vector<std::string>* to_update) { | 314 const std::vector<std::string>* to_update) { |
| 309 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 315 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 323 } | 329 } |
| 324 } | 330 } |
| 325 | 331 |
| 326 void SyncClient::AddFetchTasks(const std::vector<std::string>* local_ids) { | 332 void SyncClient::AddFetchTasks(const std::vector<std::string>* local_ids) { |
| 327 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 333 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 328 | 334 |
| 329 for (size_t i = 0; i < local_ids->size(); ++i) | 335 for (size_t i = 0; i < local_ids->size(); ++i) |
| 330 AddFetchTask((*local_ids)[i]); | 336 AddFetchTask((*local_ids)[i]); |
| 331 } | 337 } |
| 332 | 338 |
| 333 void SyncClient::OnGetFileContentInitialized( | |
| 334 FileError error, | |
| 335 scoped_ptr<ResourceEntry> entry, | |
| 336 const base::FilePath& local_cache_file_path, | |
| 337 const base::Closure& cancel_download_closure) { | |
| 338 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 339 | |
| 340 if (error != FILE_ERROR_OK) | |
| 341 return; | |
| 342 | |
| 343 const SyncTasks::key_type key(FETCH, entry->local_id()); | |
| 344 SyncTasks::iterator it = tasks_.find(key); | |
| 345 DCHECK(it != tasks_.end()); | |
| 346 | |
| 347 it->second.cancel_closure = cancel_download_closure; | |
| 348 } | |
| 349 | |
| 350 bool SyncClient::OnTaskComplete(SyncType type, const std::string& local_id) { | 339 bool SyncClient::OnTaskComplete(SyncType type, const std::string& local_id) { |
| 351 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 340 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 352 | 341 |
| 353 const SyncTasks::key_type key(type, local_id); | 342 const SyncTasks::key_type key(type, local_id); |
| 354 SyncTasks::iterator it = tasks_.find(key); | 343 SyncTasks::iterator it = tasks_.find(key); |
| 355 DCHECK(it != tasks_.end()); | 344 DCHECK(it != tasks_.end()); |
| 356 | 345 |
| 357 if (it->second.should_run_again) { | 346 if (it->second.should_run_again) { |
| 358 DVLOG(1) << "Running again: type = " << type << ", id = " << local_id; | 347 DVLOG(1) << "Running again: type = " << type << ", id = " << local_id; |
| 359 it->second.should_run_again = false; | 348 it->second.should_run_again = false; |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 464 const ResourceEntry& entry = (*entries)[i]; | 453 const ResourceEntry& entry = (*entries)[i]; |
| 465 if (entry.metadata_edit_state() != ResourceEntry::CLEAN) { | 454 if (entry.metadata_edit_state() != ResourceEntry::CLEAN) { |
| 466 AddUpdateTaskInternal(ClientContext(BACKGROUND), entry.local_id(), | 455 AddUpdateTaskInternal(ClientContext(BACKGROUND), entry.local_id(), |
| 467 base::TimeDelta::FromSeconds(0)); | 456 base::TimeDelta::FromSeconds(0)); |
| 468 } | 457 } |
| 469 } | 458 } |
| 470 } | 459 } |
| 471 | 460 |
| 472 } // namespace internal | 461 } // namespace internal |
| 473 } // namespace drive | 462 } // namespace drive |
| OLD | NEW |