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
3 // found in the LICENSE file.
5 #include "chrome/browser/sync_file_system/drive_backend/sync_task_token.h"
8 #include "chrome/browser/sync_file_system/drive_backend/sync_task_manager.h"
9 #include "chrome/browser/sync_file_system/drive_backend/task_dependency_manager.h"
11 namespace sync_file_system {
12 namespace drive_backend {
14 const int64 SyncTaskToken::kForegroundTaskTokenID = 0;
15 const int64 SyncTaskToken::kMinimumBackgroundTaskTokenID = 1;
18 scoped_ptr<SyncTaskToken> SyncTaskToken::CreateForForegroundTask(
19 const base::WeakPtr<SyncTaskManager>& manager) {
20 return make_scoped_ptr(new SyncTaskToken(
22 kForegroundTaskTokenID,
23 scoped_ptr<BlockingFactor>()));
27 scoped_ptr<SyncTaskToken> SyncTaskToken::CreateForBackgroundTask(
28 const base::WeakPtr<SyncTaskManager>& manager,
30 scoped_ptr<BlockingFactor> blocking_factor) {
31 return make_scoped_ptr(new SyncTaskToken(
34 blocking_factor.Pass()));
37 void SyncTaskToken::UpdateTask(const tracked_objects::Location& location,
38 const SyncStatusCallback& callback) {
39 DCHECK(callback_.is_null());
42 DVLOG(2) << "Token updated: " << location_.ToString();
45 SyncTaskToken::~SyncTaskToken() {
46 // All task on Client must hold TaskToken instance to ensure
47 // no other tasks are running. Also, as soon as a task finishes to work,
48 // it must return the token to TaskManager.
49 // Destroying a token with valid |client| indicates the token was
50 // dropped by a task without returning.
51 if (manager_.get() && manager_->IsRunningTask(token_id_)) {
53 << "Unexpected TaskToken deletion from: " << location_.ToString();
55 // Reinitializes the token.
56 SyncTaskManager::NotifyTaskDone(
57 make_scoped_ptr(new SyncTaskToken(
58 manager_, token_id_, blocking_factor_.Pass())),
64 SyncStatusCallback SyncTaskToken::WrapToCallback(
65 scoped_ptr<SyncTaskToken> token) {
66 return base::Bind(&SyncTaskManager::NotifyTaskDone, base::Passed(&token));
69 void SyncTaskToken::set_blocking_factor(
70 scoped_ptr<BlockingFactor> blocking_factor) {
71 blocking_factor_ = blocking_factor.Pass();
74 const BlockingFactor* SyncTaskToken::blocking_factor() const {
75 return blocking_factor_.get();
78 void SyncTaskToken::clear_blocking_factor() {
79 blocking_factor_.reset();
82 SyncTaskToken::SyncTaskToken(const base::WeakPtr<SyncTaskManager>& manager,
84 scoped_ptr<BlockingFactor> blocking_factor)
87 blocking_factor_(blocking_factor.Pass()) {
90 } // namespace drive_backend
91 } // namespace sync_file_system