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 <utility> |
| 8 |
7 #include "base/bind.h" | 9 #include "base/bind.h" |
8 #include "base/thread_task_runner_handle.h" | 10 #include "base/thread_task_runner_handle.h" |
9 #include "base/trace_event/trace_event.h" | 11 #include "base/trace_event/trace_event.h" |
10 #include "chrome/browser/sync_file_system/drive_backend/sync_task_manager.h" | 12 #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" | 13 #include "chrome/browser/sync_file_system/drive_backend/task_dependency_manager.
h" |
12 | 14 |
13 namespace sync_file_system { | 15 namespace sync_file_system { |
14 namespace drive_backend { | 16 namespace drive_backend { |
15 | 17 |
16 const int64_t SyncTaskToken::kTestingTaskTokenID = -1; | 18 const int64_t SyncTaskToken::kTestingTaskTokenID = -1; |
(...skipping 22 matching lines...) Expand all Loading... |
39 nullptr, // task_blocker | 41 nullptr, // task_blocker |
40 SyncStatusCallback())); | 42 SyncStatusCallback())); |
41 } | 43 } |
42 | 44 |
43 // static | 45 // static |
44 scoped_ptr<SyncTaskToken> SyncTaskToken::CreateForBackgroundTask( | 46 scoped_ptr<SyncTaskToken> SyncTaskToken::CreateForBackgroundTask( |
45 const base::WeakPtr<SyncTaskManager>& manager, | 47 const base::WeakPtr<SyncTaskManager>& manager, |
46 base::SequencedTaskRunner* task_runner, | 48 base::SequencedTaskRunner* task_runner, |
47 int64_t token_id, | 49 int64_t token_id, |
48 scoped_ptr<TaskBlocker> task_blocker) { | 50 scoped_ptr<TaskBlocker> task_blocker) { |
49 return make_scoped_ptr(new SyncTaskToken( | 51 return make_scoped_ptr(new SyncTaskToken(manager, task_runner, token_id, |
50 manager, | 52 std::move(task_blocker), |
51 task_runner, | 53 SyncStatusCallback())); |
52 token_id, | |
53 task_blocker.Pass(), | |
54 SyncStatusCallback())); | |
55 } | 54 } |
56 | 55 |
57 void SyncTaskToken::UpdateTask(const tracked_objects::Location& location, | 56 void SyncTaskToken::UpdateTask(const tracked_objects::Location& location, |
58 const SyncStatusCallback& callback) { | 57 const SyncStatusCallback& callback) { |
59 DCHECK(callback_.is_null()); | 58 DCHECK(callback_.is_null()); |
60 location_ = location; | 59 location_ = location; |
61 callback_ = callback; | 60 callback_ = callback; |
62 DVLOG(2) << "Token updated: " << location_.ToString(); | 61 DVLOG(2) << "Token updated: " << location_.ToString(); |
63 } | 62 } |
64 | 63 |
65 SyncTaskToken::~SyncTaskToken() { | 64 SyncTaskToken::~SyncTaskToken() { |
66 // All task on Client must hold TaskToken instance to ensure | 65 // 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, | 66 // no other tasks are running. Also, as soon as a task finishes to work, |
68 // it must return the token to TaskManager. | 67 // it must return the token to TaskManager. |
69 // Destroying a token with valid |client| indicates the token was | 68 // Destroying a token with valid |client| indicates the token was |
70 // dropped by a task without returning. | 69 // dropped by a task without returning. |
71 if (task_runner_.get() && task_runner_->RunsTasksOnCurrentThread() && | 70 if (task_runner_.get() && task_runner_->RunsTasksOnCurrentThread() && |
72 manager_ && manager_->IsRunningTask(token_id_)) { | 71 manager_ && manager_->IsRunningTask(token_id_)) { |
73 if (!manager_->ShouldTrackTaskToken()) | 72 if (!manager_->ShouldTrackTaskToken()) |
74 return; | 73 return; |
75 | 74 |
76 NOTREACHED() | 75 NOTREACHED() |
77 << "Unexpected TaskToken deletion from: " << location_.ToString(); | 76 << "Unexpected TaskToken deletion from: " << location_.ToString(); |
78 | 77 |
79 // Reinitializes the token. | 78 // Reinitializes the token. |
80 SyncTaskManager::NotifyTaskDone( | 79 SyncTaskManager::NotifyTaskDone( |
81 make_scoped_ptr(new SyncTaskToken(manager_, | 80 make_scoped_ptr(new SyncTaskToken(manager_, task_runner_.get(), |
82 task_runner_.get(), | 81 token_id_, std::move(task_blocker_), |
83 token_id_, | |
84 task_blocker_.Pass(), | |
85 SyncStatusCallback())), | 82 SyncStatusCallback())), |
86 SYNC_STATUS_OK); | 83 SYNC_STATUS_OK); |
87 } | 84 } |
88 } | 85 } |
89 | 86 |
90 // static | 87 // static |
91 SyncStatusCallback SyncTaskToken::WrapToCallback( | 88 SyncStatusCallback SyncTaskToken::WrapToCallback( |
92 scoped_ptr<SyncTaskToken> token) { | 89 scoped_ptr<SyncTaskToken> token) { |
93 return base::Bind(&SyncTaskManager::NotifyTaskDone, base::Passed(&token)); | 90 return base::Bind(&SyncTaskManager::NotifyTaskDone, base::Passed(&token)); |
94 } | 91 } |
95 | 92 |
96 void SyncTaskToken::set_task_blocker( | 93 void SyncTaskToken::set_task_blocker( |
97 scoped_ptr<TaskBlocker> task_blocker) { | 94 scoped_ptr<TaskBlocker> task_blocker) { |
98 task_blocker_ = task_blocker.Pass(); | 95 task_blocker_ = std::move(task_blocker); |
99 } | 96 } |
100 | 97 |
101 const TaskBlocker* SyncTaskToken::task_blocker() const { | 98 const TaskBlocker* SyncTaskToken::task_blocker() const { |
102 return task_blocker_.get(); | 99 return task_blocker_.get(); |
103 } | 100 } |
104 | 101 |
105 void SyncTaskToken::clear_task_blocker() { | 102 void SyncTaskToken::clear_task_blocker() { |
106 task_blocker_.reset(); | 103 task_blocker_.reset(); |
107 } | 104 } |
108 | 105 |
(...skipping 18 matching lines...) Expand all Loading... |
127 task_log_->result_description = result_description; | 124 task_log_->result_description = result_description; |
128 task_log_->end_time = base::TimeTicks::Now(); | 125 task_log_->end_time = base::TimeTicks::Now(); |
129 } | 126 } |
130 | 127 |
131 void SyncTaskToken::RecordLog(const std::string& message) { | 128 void SyncTaskToken::RecordLog(const std::string& message) { |
132 DCHECK(task_log_); | 129 DCHECK(task_log_); |
133 task_log_->details.push_back(message); | 130 task_log_->details.push_back(message); |
134 } | 131 } |
135 | 132 |
136 void SyncTaskToken::SetTaskLog(scoped_ptr<TaskLogger::TaskLog> task_log) { | 133 void SyncTaskToken::SetTaskLog(scoped_ptr<TaskLogger::TaskLog> task_log) { |
137 task_log_ = task_log.Pass(); | 134 task_log_ = std::move(task_log); |
138 } | 135 } |
139 | 136 |
140 scoped_ptr<TaskLogger::TaskLog> SyncTaskToken::PassTaskLog() { | 137 scoped_ptr<TaskLogger::TaskLog> SyncTaskToken::PassTaskLog() { |
141 return task_log_.Pass(); | 138 return std::move(task_log_); |
142 } | 139 } |
143 | 140 |
144 SyncTaskToken::SyncTaskToken( | 141 SyncTaskToken::SyncTaskToken( |
145 const base::WeakPtr<SyncTaskManager>& manager, | 142 const base::WeakPtr<SyncTaskManager>& manager, |
146 const scoped_refptr<base::SequencedTaskRunner>& task_runner, | 143 const scoped_refptr<base::SequencedTaskRunner>& task_runner, |
147 int64_t token_id, | 144 int64_t token_id, |
148 scoped_ptr<TaskBlocker> task_blocker, | 145 scoped_ptr<TaskBlocker> task_blocker, |
149 const SyncStatusCallback& callback) | 146 const SyncStatusCallback& callback) |
150 : manager_(manager), | 147 : manager_(manager), |
151 task_runner_(task_runner), | 148 task_runner_(task_runner), |
152 token_id_(token_id), | 149 token_id_(token_id), |
153 callback_(callback), | 150 callback_(callback), |
154 task_blocker_(task_blocker.Pass()) {} | 151 task_blocker_(std::move(task_blocker)) {} |
155 | 152 |
156 } // namespace drive_backend | 153 } // namespace drive_backend |
157 } // namespace sync_file_system | 154 } // namespace sync_file_system |
OLD | NEW |