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 #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_
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"
14 namespace sync_file_system {
15 namespace drive_backend {
17 class SyncTaskManager;
18 struct BlockingFactor;
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.
24 static const int64 kForegroundTaskTokenID;
25 static const int64 kMinimumBackgroundTaskTokenID;
27 static scoped_ptr<SyncTaskToken> CreateForForegroundTask(
28 const base::WeakPtr<SyncTaskManager>& manager);
29 static scoped_ptr<SyncTaskToken> CreateForBackgroundTask(
30 const base::WeakPtr<SyncTaskManager>& manager,
32 scoped_ptr<BlockingFactor> blocking_factor);
34 void UpdateTask(const tracked_objects::Location& location,
35 const SyncStatusCallback& callback);
37 const tracked_objects::Location& location() const { return location_; }
38 virtual ~SyncTaskToken();
40 static SyncStatusCallback WrapToCallback(scoped_ptr<SyncTaskToken> token);
42 SyncTaskManager* manager() { return manager_.get(); }
44 const SyncStatusCallback& callback() const { return callback_; }
45 void clear_callback() { callback_.Reset(); }
47 void set_blocking_factor(scoped_ptr<BlockingFactor> blocking_factor);
48 const BlockingFactor* blocking_factor() const;
49 void clear_blocking_factor();
51 int64 token_id() const { return token_id_; }
54 SyncTaskToken(const base::WeakPtr<SyncTaskManager>& manager,
56 scoped_ptr<BlockingFactor> blocking_factor);
58 base::WeakPtr<SyncTaskManager> manager_;
59 tracked_objects::Location location_;
61 SyncStatusCallback callback_;
63 scoped_ptr<BlockingFactor> blocking_factor_;
65 DISALLOW_COPY_AND_ASSIGN(SyncTaskToken);
68 } // namespace drive_backend
69 } // namespace sync_file_system
71 #endif // CHROME_BROWSER_SYNC_FILE_SYSTEM_DRIVE_BACKEND_SYNC_TASK_TOKEN_H_