| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/sync_file_system/drive_backend/sync_task_token.h" | 5 #include "chrome/browser/sync_file_system/drive_backend/sync_task_token.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/debug/trace_event.h" | 8 #include "base/debug/trace_event.h" |
| 9 #include "base/thread_task_runner_handle.h" | 9 #include "base/thread_task_runner_handle.h" |
| 10 #include "chrome/browser/sync_file_system/drive_backend/sync_task_manager.h" | 10 #include "chrome/browser/sync_file_system/drive_backend/sync_task_manager.h" |
| 11 #include "chrome/browser/sync_file_system/drive_backend/task_dependency_manager.
h" | 11 #include "chrome/browser/sync_file_system/drive_backend/task_dependency_manager.
h" |
| 12 | 12 |
| 13 namespace sync_file_system { | 13 namespace sync_file_system { |
| 14 namespace drive_backend { | 14 namespace drive_backend { |
| 15 | 15 |
| 16 const int64 SyncTaskToken::kTestingTaskTokenID = -1; | 16 const int64 SyncTaskToken::kTestingTaskTokenID = -1; |
| 17 const int64 SyncTaskToken::kForegroundTaskTokenID = 0; | 17 const int64 SyncTaskToken::kForegroundTaskTokenID = 0; |
| 18 const int64 SyncTaskToken::kMinimumBackgroundTaskTokenID = 1; | 18 const int64 SyncTaskToken::kMinimumBackgroundTaskTokenID = 1; |
| 19 | 19 |
| 20 // static | 20 // static |
| 21 scoped_ptr<SyncTaskToken> SyncTaskToken::CreateForTesting( | 21 scoped_ptr<SyncTaskToken> SyncTaskToken::CreateForTesting( |
| 22 const SyncStatusCallback& callback) { | 22 const SyncStatusCallback& callback) { |
| 23 return make_scoped_ptr(new SyncTaskToken( | 23 return make_scoped_ptr(new SyncTaskToken( |
| 24 base::WeakPtr<SyncTaskManager>(), | 24 base::WeakPtr<SyncTaskManager>(), |
| 25 base::ThreadTaskRunnerHandle::Get(), | 25 base::ThreadTaskRunnerHandle::Get(), |
| 26 kTestingTaskTokenID, | 26 kTestingTaskTokenID, |
| 27 scoped_ptr<BlockingFactor>(), | 27 scoped_ptr<TaskBlocker>(), |
| 28 callback)); | 28 callback)); |
| 29 } | 29 } |
| 30 | 30 |
| 31 // static | 31 // static |
| 32 scoped_ptr<SyncTaskToken> SyncTaskToken::CreateForForegroundTask( | 32 scoped_ptr<SyncTaskToken> SyncTaskToken::CreateForForegroundTask( |
| 33 const base::WeakPtr<SyncTaskManager>& manager, | 33 const base::WeakPtr<SyncTaskManager>& manager, |
| 34 base::SequencedTaskRunner* task_runner) { | 34 base::SequencedTaskRunner* task_runner) { |
| 35 return make_scoped_ptr(new SyncTaskToken( | 35 return make_scoped_ptr(new SyncTaskToken( |
| 36 manager, | 36 manager, |
| 37 task_runner, | 37 task_runner, |
| 38 kForegroundTaskTokenID, | 38 kForegroundTaskTokenID, |
| 39 scoped_ptr<BlockingFactor>(), | 39 scoped_ptr<TaskBlocker>(), |
| 40 SyncStatusCallback())); | 40 SyncStatusCallback())); |
| 41 } | 41 } |
| 42 | 42 |
| 43 // static | 43 // static |
| 44 scoped_ptr<SyncTaskToken> SyncTaskToken::CreateForBackgroundTask( | 44 scoped_ptr<SyncTaskToken> SyncTaskToken::CreateForBackgroundTask( |
| 45 const base::WeakPtr<SyncTaskManager>& manager, | 45 const base::WeakPtr<SyncTaskManager>& manager, |
| 46 base::SequencedTaskRunner* task_runner, | 46 base::SequencedTaskRunner* task_runner, |
| 47 int64 token_id, | 47 int64 token_id, |
| 48 scoped_ptr<BlockingFactor> blocking_factor) { | 48 scoped_ptr<TaskBlocker> task_blocker) { |
| 49 return make_scoped_ptr(new SyncTaskToken( | 49 return make_scoped_ptr(new SyncTaskToken( |
| 50 manager, | 50 manager, |
| 51 task_runner, | 51 task_runner, |
| 52 token_id, | 52 token_id, |
| 53 blocking_factor.Pass(), | 53 task_blocker.Pass(), |
| 54 SyncStatusCallback())); | 54 SyncStatusCallback())); |
| 55 } | 55 } |
| 56 | 56 |
| 57 void SyncTaskToken::UpdateTask(const tracked_objects::Location& location, | 57 void SyncTaskToken::UpdateTask(const tracked_objects::Location& location, |
| 58 const SyncStatusCallback& callback) { | 58 const SyncStatusCallback& callback) { |
| 59 DCHECK(callback_.is_null()); | 59 DCHECK(callback_.is_null()); |
| 60 location_ = location; | 60 location_ = location; |
| 61 callback_ = callback; | 61 callback_ = callback; |
| 62 DVLOG(2) << "Token updated: " << location_.ToString(); | 62 DVLOG(2) << "Token updated: " << location_.ToString(); |
| 63 } | 63 } |
| 64 | 64 |
| 65 SyncTaskToken::~SyncTaskToken() { | 65 SyncTaskToken::~SyncTaskToken() { |
| 66 // All task on Client must hold TaskToken instance to ensure | 66 // All task on Client must hold TaskToken instance to ensure |
| 67 // no other tasks are running. Also, as soon as a task finishes to work, | 67 // no other tasks are running. Also, as soon as a task finishes to work, |
| 68 // it must return the token to TaskManager. | 68 // it must return the token to TaskManager. |
| 69 // Destroying a token with valid |client| indicates the token was | 69 // Destroying a token with valid |client| indicates the token was |
| 70 // dropped by a task without returning. | 70 // dropped by a task without returning. |
| 71 if (task_runner_.get() && task_runner_->RunsTasksOnCurrentThread() && | 71 if (task_runner_.get() && task_runner_->RunsTasksOnCurrentThread() && |
| 72 manager_ && manager_->IsRunningTask(token_id_)) { | 72 manager_ && manager_->IsRunningTask(token_id_)) { |
| 73 NOTREACHED() | 73 NOTREACHED() |
| 74 << "Unexpected TaskToken deletion from: " << location_.ToString(); | 74 << "Unexpected TaskToken deletion from: " << location_.ToString(); |
| 75 | 75 |
| 76 // Reinitializes the token. | 76 // Reinitializes the token. |
| 77 SyncTaskManager::NotifyTaskDone( | 77 SyncTaskManager::NotifyTaskDone( |
| 78 make_scoped_ptr(new SyncTaskToken(manager_, | 78 make_scoped_ptr(new SyncTaskToken(manager_, |
| 79 task_runner_.get(), | 79 task_runner_.get(), |
| 80 token_id_, | 80 token_id_, |
| 81 blocking_factor_.Pass(), | 81 task_blocker_.Pass(), |
| 82 SyncStatusCallback())), | 82 SyncStatusCallback())), |
| 83 SYNC_STATUS_OK); | 83 SYNC_STATUS_OK); |
| 84 } | 84 } |
| 85 } | 85 } |
| 86 | 86 |
| 87 // static | 87 // static |
| 88 SyncStatusCallback SyncTaskToken::WrapToCallback( | 88 SyncStatusCallback SyncTaskToken::WrapToCallback( |
| 89 scoped_ptr<SyncTaskToken> token) { | 89 scoped_ptr<SyncTaskToken> token) { |
| 90 return base::Bind(&SyncTaskManager::NotifyTaskDone, base::Passed(&token)); | 90 return base::Bind(&SyncTaskManager::NotifyTaskDone, base::Passed(&token)); |
| 91 } | 91 } |
| 92 | 92 |
| 93 void SyncTaskToken::set_blocking_factor( | 93 void SyncTaskToken::set_task_blocker( |
| 94 scoped_ptr<BlockingFactor> blocking_factor) { | 94 scoped_ptr<TaskBlocker> task_blocker) { |
| 95 blocking_factor_ = blocking_factor.Pass(); | 95 task_blocker_ = task_blocker.Pass(); |
| 96 } | 96 } |
| 97 | 97 |
| 98 const BlockingFactor* SyncTaskToken::blocking_factor() const { | 98 const TaskBlocker* SyncTaskToken::task_blocker() const { |
| 99 return blocking_factor_.get(); | 99 return task_blocker_.get(); |
| 100 } | 100 } |
| 101 | 101 |
| 102 void SyncTaskToken::clear_blocking_factor() { | 102 void SyncTaskToken::clear_task_blocker() { |
| 103 blocking_factor_.reset(); | 103 task_blocker_.reset(); |
| 104 } | 104 } |
| 105 | 105 |
| 106 void SyncTaskToken::InitializeTaskLog(const std::string& task_description) { | 106 void SyncTaskToken::InitializeTaskLog(const std::string& task_description) { |
| 107 task_log_.reset(new TaskLogger::TaskLog); | 107 task_log_.reset(new TaskLogger::TaskLog); |
| 108 task_log_->start_time = base::TimeTicks::Now(); | 108 task_log_->start_time = base::TimeTicks::Now(); |
| 109 task_log_->task_description = task_description; | 109 task_log_->task_description = task_description; |
| 110 | 110 |
| 111 TRACE_EVENT_ASYNC_BEGIN1( | 111 TRACE_EVENT_ASYNC_BEGIN1( |
| 112 TRACE_DISABLED_BY_DEFAULT("SyncFileSystem"), | 112 TRACE_DISABLED_BY_DEFAULT("SyncFileSystem"), |
| 113 "SyncTask", task_log_->log_id, | 113 "SyncTask", task_log_->log_id, |
| (...skipping 21 matching lines...) Expand all Loading... |
| 135 } | 135 } |
| 136 | 136 |
| 137 scoped_ptr<TaskLogger::TaskLog> SyncTaskToken::PassTaskLog() { | 137 scoped_ptr<TaskLogger::TaskLog> SyncTaskToken::PassTaskLog() { |
| 138 return task_log_.Pass(); | 138 return task_log_.Pass(); |
| 139 } | 139 } |
| 140 | 140 |
| 141 SyncTaskToken::SyncTaskToken( | 141 SyncTaskToken::SyncTaskToken( |
| 142 const base::WeakPtr<SyncTaskManager>& manager, | 142 const base::WeakPtr<SyncTaskManager>& manager, |
| 143 const scoped_refptr<base::SequencedTaskRunner>& task_runner, | 143 const scoped_refptr<base::SequencedTaskRunner>& task_runner, |
| 144 int64 token_id, | 144 int64 token_id, |
| 145 scoped_ptr<BlockingFactor> blocking_factor, | 145 scoped_ptr<TaskBlocker> task_blocker, |
| 146 const SyncStatusCallback& callback) | 146 const SyncStatusCallback& callback) |
| 147 : manager_(manager), | 147 : manager_(manager), |
| 148 task_runner_(task_runner), | 148 task_runner_(task_runner), |
| 149 token_id_(token_id), | 149 token_id_(token_id), |
| 150 callback_(callback), | 150 callback_(callback), |
| 151 blocking_factor_(blocking_factor.Pass()) { | 151 task_blocker_(task_blocker.Pass()) { |
| 152 } | 152 } |
| 153 | 153 |
| 154 } // namespace drive_backend | 154 } // namespace drive_backend |
| 155 } // namespace sync_file_system | 155 } // namespace sync_file_system |
| OLD | NEW |