sync_task_token.cc revision a1401311d1ab56c4ed0a474bd38c108f75cb0cd9
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. 4 5#include "chrome/browser/sync_file_system/drive_backend/sync_task_token.h" 6 7#include "base/bind.h" 8#include "chrome/browser/sync_file_system/drive_backend/sync_task_manager.h" 9 10namespace sync_file_system { 11namespace drive_backend { 12 13SyncTaskToken::SyncTaskToken(const base::WeakPtr<SyncTaskManager>& manager) 14 : manager_(manager) { 15} 16 17void SyncTaskToken::UpdateTask(const tracked_objects::Location& location, 18 const SyncStatusCallback& callback) { 19 DCHECK(callback_.is_null()); 20 location_ = location; 21 callback_ = callback; 22 DVLOG(2) << "Token updated: " << location_.ToString(); 23} 24 25SyncTaskToken::~SyncTaskToken() { 26 // All task on Client must hold TaskToken instance to ensure 27 // no other tasks are running. Also, as soon as a task finishes to work, 28 // it must return the token to TaskManager. 29 // Destroying a token with valid |client| indicates the token was 30 // dropped by a task without returning. 31 if (manager_.get() && manager_->HasClient()) { 32 NOTREACHED() 33 << "Unexpected TaskToken deletion from: " << location_.ToString(); 34 35 // Reinitializes the token. 36 SyncTaskManager::NotifyTaskDone( 37 make_scoped_ptr(new SyncTaskToken(manager_)), SYNC_STATUS_OK); 38 } 39} 40 41// static 42SyncStatusCallback SyncTaskToken::WrapToCallback( 43 scoped_ptr<SyncTaskToken> token) { 44 return base::Bind(&SyncTaskManager::NotifyTaskDone, base::Passed(&token)); 45} 46 47} // namespace drive_backend 48} // namespace sync_file_system 49