OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/sync_task_manager.h" | 5 #include "chrome/browser/sync_file_system/sync_task_manager.h" |
6 | 6 |
7 #include "base/debug/trace_event.h" | 7 #include "base/debug/trace_event.h" |
8 #include "base/location.h" | 8 #include "base/location.h" |
9 #include "chrome/browser/sync_file_system/sync_file_metadata.h" | 9 #include "chrome/browser/sync_file_system/sync_file_metadata.h" |
10 | 10 |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 token_.reset(); | 77 token_.reset(); |
78 } | 78 } |
79 | 79 |
80 void SyncTaskManager::Initialize(SyncStatusCode status) { | 80 void SyncTaskManager::Initialize(SyncStatusCode status) { |
81 DCHECK(!token_); | 81 DCHECK(!token_); |
82 NotifyTaskDone(make_scoped_ptr(new TaskToken(AsWeakPtr())), | 82 NotifyTaskDone(make_scoped_ptr(new TaskToken(AsWeakPtr())), |
83 status); | 83 status); |
84 } | 84 } |
85 | 85 |
86 void SyncTaskManager::ScheduleTask( | 86 void SyncTaskManager::ScheduleTask( |
| 87 const tracked_objects::Location& from_here, |
87 const Task& task, | 88 const Task& task, |
88 const SyncStatusCallback& callback) { | 89 const SyncStatusCallback& callback) { |
89 ScheduleTaskAtPriority(task, PRIORITY_MED, callback); | 90 ScheduleTaskAtPriority(from_here, task, PRIORITY_MED, callback); |
90 } | 91 } |
91 | 92 |
92 void SyncTaskManager::ScheduleSyncTask( | 93 void SyncTaskManager::ScheduleSyncTask( |
| 94 const tracked_objects::Location& from_here, |
93 scoped_ptr<SyncTask> task, | 95 scoped_ptr<SyncTask> task, |
94 const SyncStatusCallback& callback) { | 96 const SyncStatusCallback& callback) { |
95 ScheduleSyncTaskAtPriority(task.Pass(), PRIORITY_MED, callback); | 97 ScheduleSyncTaskAtPriority(from_here, task.Pass(), PRIORITY_MED, callback); |
96 } | 98 } |
97 | 99 |
98 void SyncTaskManager::ScheduleTaskAtPriority( | 100 void SyncTaskManager::ScheduleTaskAtPriority( |
| 101 const tracked_objects::Location& from_here, |
99 const Task& task, | 102 const Task& task, |
100 Priority priority, | 103 Priority priority, |
101 const SyncStatusCallback& callback) { | 104 const SyncStatusCallback& callback) { |
102 scoped_ptr<TaskToken> token(GetToken(FROM_HERE)); | 105 scoped_ptr<TaskToken> token(GetToken(from_here)); |
103 if (!token) { | 106 if (!token) { |
104 PushPendingTask( | 107 PushPendingTask( |
105 base::Bind(&SyncTaskManager::ScheduleTask, AsWeakPtr(), | 108 base::Bind(&SyncTaskManager::ScheduleTask, AsWeakPtr(), from_here, |
106 task, callback), | 109 task, callback), |
107 priority); | 110 priority); |
108 return; | 111 return; |
109 } | 112 } |
110 task.Run(CreateCompletionCallback(token.Pass(), callback)); | 113 task.Run(CreateCompletionCallback(token.Pass(), callback)); |
111 } | 114 } |
112 | 115 |
113 void SyncTaskManager::ScheduleSyncTaskAtPriority( | 116 void SyncTaskManager::ScheduleSyncTaskAtPriority( |
| 117 const tracked_objects::Location& from_here, |
114 scoped_ptr<SyncTask> task, | 118 scoped_ptr<SyncTask> task, |
115 Priority priority, | 119 Priority priority, |
116 const SyncStatusCallback& callback) { | 120 const SyncStatusCallback& callback) { |
117 scoped_ptr<TaskToken> token(GetToken(FROM_HERE)); | 121 scoped_ptr<TaskToken> token(GetToken(from_here)); |
118 if (!token) { | 122 if (!token) { |
119 PushPendingTask( | 123 PushPendingTask( |
120 base::Bind(&SyncTaskManager::ScheduleSyncTask, | 124 base::Bind(&SyncTaskManager::ScheduleSyncTask, AsWeakPtr(), from_here, |
121 AsWeakPtr(), base::Passed(&task), callback), | 125 base::Passed(&task), callback), |
122 priority); | 126 priority); |
123 return; | 127 return; |
124 } | 128 } |
125 DCHECK(!running_task_); | 129 DCHECK(!running_task_); |
126 running_task_ = task.Pass(); | 130 running_task_ = task.Pass(); |
127 running_task_->Run(CreateCompletionCallback(token.Pass(), callback)); | 131 running_task_->Run(CreateCompletionCallback(token.Pass(), callback)); |
128 } | 132 } |
129 | 133 |
130 bool SyncTaskManager::ScheduleTaskIfIdle(const Task& task, | 134 bool SyncTaskManager::ScheduleTaskIfIdle( |
131 const SyncStatusCallback& callback) { | 135 const tracked_objects::Location& from_here, |
132 scoped_ptr<TaskToken> token(GetToken(FROM_HERE)); | 136 const Task& task, |
| 137 const SyncStatusCallback& callback) { |
| 138 scoped_ptr<TaskToken> token(GetToken(from_here)); |
133 if (!token) | 139 if (!token) |
134 return false; | 140 return false; |
135 task.Run(CreateCompletionCallback(token.Pass(), callback)); | 141 task.Run(CreateCompletionCallback(token.Pass(), callback)); |
136 return true; | 142 return true; |
137 } | 143 } |
138 | 144 |
139 bool SyncTaskManager::ScheduleSyncTaskIfIdle( | 145 bool SyncTaskManager::ScheduleSyncTaskIfIdle( |
| 146 const tracked_objects::Location& from_here, |
140 scoped_ptr<SyncTask> task, | 147 scoped_ptr<SyncTask> task, |
141 const SyncStatusCallback& callback) { | 148 const SyncStatusCallback& callback) { |
142 scoped_ptr<TaskToken> token(GetToken(FROM_HERE)); | 149 scoped_ptr<TaskToken> token(GetToken(from_here)); |
143 if (!token) | 150 if (!token) |
144 return false; | 151 return false; |
145 DCHECK(!running_task_); | 152 DCHECK(!running_task_); |
146 running_task_ = task.Pass(); | 153 running_task_ = task.Pass(); |
147 running_task_->Run(CreateCompletionCallback(token.Pass(), | 154 running_task_->Run(CreateCompletionCallback(token.Pass(), |
148 callback)); | 155 callback)); |
149 return true; | 156 return true; |
150 } | 157 } |
151 | 158 |
152 void SyncTaskManager::NotifyTaskDone( | 159 void SyncTaskManager::NotifyTaskDone( |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
206 return base::Bind(&SyncTaskManager::NotifyTaskDone, | 213 return base::Bind(&SyncTaskManager::NotifyTaskDone, |
207 AsWeakPtr(), base::Passed(&token)); | 214 AsWeakPtr(), base::Passed(&token)); |
208 } | 215 } |
209 | 216 |
210 void SyncTaskManager::PushPendingTask( | 217 void SyncTaskManager::PushPendingTask( |
211 const base::Closure& closure, Priority priority) { | 218 const base::Closure& closure, Priority priority) { |
212 pending_tasks_.push(PendingTask(closure, priority, pending_task_seq_++)); | 219 pending_tasks_.push(PendingTask(closure, priority, pending_task_seq_++)); |
213 } | 220 } |
214 | 221 |
215 } // namespace sync_file_system | 222 } // namespace sync_file_system |
OLD | NEW |