sync_task_token.h revision 0529e5d033099cbfc42635f6f6183833b09dff6e
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#ifndef CHROME_BROWSER_SYNC_FILE_SYSTEM_DRIVE_BACKEND_SYNC_TASK_TOKEN_H_ 6#define CHROME_BROWSER_SYNC_FILE_SYSTEM_DRIVE_BACKEND_SYNC_TASK_TOKEN_H_ 7 8#include "base/callback.h" 9#include "base/location.h" 10#include "base/memory/scoped_ptr.h" 11#include "base/memory/weak_ptr.h" 12#include "chrome/browser/sync_file_system/sync_callbacks.h" 13 14namespace sync_file_system { 15namespace drive_backend { 16 17class SyncTaskManager; 18struct BlockingFactor; 19 20// Represents a running sequence of SyncTasks. Owned by a callback chain that 21// should run exclusively, and held by SyncTaskManager when no task is running. 22class SyncTaskToken { 23 public: 24 static const int64 kForegroundTaskTokenID; 25 static const int64 kMinimumBackgroundTaskTokenID; 26 27 static scoped_ptr<SyncTaskToken> CreateForForegroundTask( 28 const base::WeakPtr<SyncTaskManager>& manager); 29 static scoped_ptr<SyncTaskToken> CreateForBackgroundTask( 30 const base::WeakPtr<SyncTaskManager>& manager, 31 int64 token_id, 32 scoped_ptr<BlockingFactor> blocking_factor); 33 34 void UpdateTask(const tracked_objects::Location& location, 35 const SyncStatusCallback& callback); 36 37 const tracked_objects::Location& location() const { return location_; } 38 virtual ~SyncTaskToken(); 39 40 static SyncStatusCallback WrapToCallback(scoped_ptr<SyncTaskToken> token); 41 42 SyncTaskManager* manager() { return manager_.get(); } 43 44 const SyncStatusCallback& callback() const { return callback_; } 45 void clear_callback() { callback_.Reset(); } 46 47 void set_blocking_factor(scoped_ptr<BlockingFactor> blocking_factor); 48 const BlockingFactor* blocking_factor() const; 49 void clear_blocking_factor(); 50 51 int64 token_id() const { return token_id_; } 52 53 private: 54 SyncTaskToken(const base::WeakPtr<SyncTaskManager>& manager, 55 int64 token_id, 56 scoped_ptr<BlockingFactor> blocking_factor); 57 58 base::WeakPtr<SyncTaskManager> manager_; 59 tracked_objects::Location location_; 60 int64 token_id_; 61 SyncStatusCallback callback_; 62 63 scoped_ptr<BlockingFactor> blocking_factor_; 64 65 DISALLOW_COPY_AND_ASSIGN(SyncTaskToken); 66}; 67 68} // namespace drive_backend 69} // namespace sync_file_system 70 71#endif // CHROME_BROWSER_SYNC_FILE_SYSTEM_DRIVE_BACKEND_SYNC_TASK_TOKEN_H_ 72