| 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 "chrome/browser/sync_file_system/drive_backend/sync_task_manager.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" | 9 #include "chrome/browser/sync_file_system/drive_backend/task_dependency_manager.
h" |
| 10 | 10 |
| 11 namespace sync_file_system { | 11 namespace sync_file_system { |
| 12 namespace drive_backend { | 12 namespace drive_backend { |
| 13 | 13 |
| 14 const int64 SyncTaskToken::kTestingTaskTokenID = -1; |
| 14 const int64 SyncTaskToken::kForegroundTaskTokenID = 0; | 15 const int64 SyncTaskToken::kForegroundTaskTokenID = 0; |
| 15 const int64 SyncTaskToken::kMinimumBackgroundTaskTokenID = 1; | 16 const int64 SyncTaskToken::kMinimumBackgroundTaskTokenID = 1; |
| 16 | 17 |
| 17 // static | 18 // static |
| 19 scoped_ptr<SyncTaskToken> SyncTaskToken::CreateForTesting( |
| 20 const SyncStatusCallback& callback) { |
| 21 return make_scoped_ptr(new SyncTaskToken( |
| 22 base::WeakPtr<SyncTaskManager>(), |
| 23 kTestingTaskTokenID, |
| 24 scoped_ptr<BlockingFactor>(), |
| 25 callback)); |
| 26 } |
| 27 |
| 28 // static |
| 18 scoped_ptr<SyncTaskToken> SyncTaskToken::CreateForForegroundTask( | 29 scoped_ptr<SyncTaskToken> SyncTaskToken::CreateForForegroundTask( |
| 19 const base::WeakPtr<SyncTaskManager>& manager) { | 30 const base::WeakPtr<SyncTaskManager>& manager) { |
| 20 return make_scoped_ptr(new SyncTaskToken( | 31 return make_scoped_ptr(new SyncTaskToken( |
| 21 manager, | 32 manager, |
| 22 kForegroundTaskTokenID, | 33 kForegroundTaskTokenID, |
| 23 scoped_ptr<BlockingFactor>())); | 34 scoped_ptr<BlockingFactor>(), |
| 35 SyncStatusCallback())); |
| 24 } | 36 } |
| 25 | 37 |
| 26 // static | 38 // static |
| 27 scoped_ptr<SyncTaskToken> SyncTaskToken::CreateForBackgroundTask( | 39 scoped_ptr<SyncTaskToken> SyncTaskToken::CreateForBackgroundTask( |
| 28 const base::WeakPtr<SyncTaskManager>& manager, | 40 const base::WeakPtr<SyncTaskManager>& manager, |
| 29 int64 token_id, | 41 int64 token_id, |
| 30 scoped_ptr<BlockingFactor> blocking_factor) { | 42 scoped_ptr<BlockingFactor> blocking_factor) { |
| 31 return make_scoped_ptr(new SyncTaskToken( | 43 return make_scoped_ptr(new SyncTaskToken( |
| 32 manager, | 44 manager, |
| 33 token_id, | 45 token_id, |
| 34 blocking_factor.Pass())); | 46 blocking_factor.Pass(), |
| 47 SyncStatusCallback())); |
| 35 } | 48 } |
| 36 | 49 |
| 37 void SyncTaskToken::UpdateTask(const tracked_objects::Location& location, | 50 void SyncTaskToken::UpdateTask(const tracked_objects::Location& location, |
| 38 const SyncStatusCallback& callback) { | 51 const SyncStatusCallback& callback) { |
| 39 DCHECK(callback_.is_null()); | 52 DCHECK(callback_.is_null()); |
| 40 location_ = location; | 53 location_ = location; |
| 41 callback_ = callback; | 54 callback_ = callback; |
| 42 DVLOG(2) << "Token updated: " << location_.ToString(); | 55 DVLOG(2) << "Token updated: " << location_.ToString(); |
| 43 } | 56 } |
| 44 | 57 |
| 45 SyncTaskToken::~SyncTaskToken() { | 58 SyncTaskToken::~SyncTaskToken() { |
| 46 // All task on Client must hold TaskToken instance to ensure | 59 // 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, | 60 // no other tasks are running. Also, as soon as a task finishes to work, |
| 48 // it must return the token to TaskManager. | 61 // it must return the token to TaskManager. |
| 49 // Destroying a token with valid |client| indicates the token was | 62 // Destroying a token with valid |client| indicates the token was |
| 50 // dropped by a task without returning. | 63 // dropped by a task without returning. |
| 51 if (manager_.get() && manager_->IsRunningTask(token_id_)) { | 64 if (manager_.get() && manager_->IsRunningTask(token_id_)) { |
| 52 NOTREACHED() | 65 NOTREACHED() |
| 53 << "Unexpected TaskToken deletion from: " << location_.ToString(); | 66 << "Unexpected TaskToken deletion from: " << location_.ToString(); |
| 54 | 67 |
| 55 // Reinitializes the token. | 68 // Reinitializes the token. |
| 56 SyncTaskManager::NotifyTaskDone( | 69 SyncTaskManager::NotifyTaskDone( |
| 57 make_scoped_ptr(new SyncTaskToken( | 70 make_scoped_ptr(new SyncTaskToken( |
| 58 manager_, token_id_, blocking_factor_.Pass())), | 71 manager_, token_id_, blocking_factor_.Pass(), |
| 72 SyncStatusCallback())), |
| 59 SYNC_STATUS_OK); | 73 SYNC_STATUS_OK); |
| 60 } | 74 } |
| 61 } | 75 } |
| 62 | 76 |
| 63 // static | 77 // static |
| 64 SyncStatusCallback SyncTaskToken::WrapToCallback( | 78 SyncStatusCallback SyncTaskToken::WrapToCallback( |
| 65 scoped_ptr<SyncTaskToken> token) { | 79 scoped_ptr<SyncTaskToken> token) { |
| 66 return base::Bind(&SyncTaskManager::NotifyTaskDone, base::Passed(&token)); | 80 return base::Bind(&SyncTaskManager::NotifyTaskDone, base::Passed(&token)); |
| 67 } | 81 } |
| 68 | 82 |
| 69 void SyncTaskToken::set_blocking_factor( | 83 void SyncTaskToken::set_blocking_factor( |
| 70 scoped_ptr<BlockingFactor> blocking_factor) { | 84 scoped_ptr<BlockingFactor> blocking_factor) { |
| 71 blocking_factor_ = blocking_factor.Pass(); | 85 blocking_factor_ = blocking_factor.Pass(); |
| 72 } | 86 } |
| 73 | 87 |
| 74 const BlockingFactor* SyncTaskToken::blocking_factor() const { | 88 const BlockingFactor* SyncTaskToken::blocking_factor() const { |
| 75 return blocking_factor_.get(); | 89 return blocking_factor_.get(); |
| 76 } | 90 } |
| 77 | 91 |
| 78 void SyncTaskToken::clear_blocking_factor() { | 92 void SyncTaskToken::clear_blocking_factor() { |
| 79 blocking_factor_.reset(); | 93 blocking_factor_.reset(); |
| 80 } | 94 } |
| 81 | 95 |
| 82 SyncTaskToken::SyncTaskToken(const base::WeakPtr<SyncTaskManager>& manager, | 96 SyncTaskToken::SyncTaskToken(const base::WeakPtr<SyncTaskManager>& manager, |
| 83 int64 token_id, | 97 int64 token_id, |
| 84 scoped_ptr<BlockingFactor> blocking_factor) | 98 scoped_ptr<BlockingFactor> blocking_factor, |
| 99 const SyncStatusCallback& callback) |
| 85 : manager_(manager), | 100 : manager_(manager), |
| 86 token_id_(token_id), | 101 token_id_(token_id), |
| 87 blocking_factor_(blocking_factor.Pass()) { | 102 blocking_factor_(blocking_factor.Pass()), |
| 103 callback_(callback) { |
| 88 } | 104 } |
| 89 | 105 |
| 90 } // namespace drive_backend | 106 } // namespace drive_backend |
| 91 } // namespace sync_file_system | 107 } // namespace sync_file_system |
| OLD | NEW |