Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(974)

Side by Side Diff: chrome/browser/sync_file_system/sync_task_manager.h

Issue 23513021: Make SyncTaskManager's regular Task cancellable (like SyncTask) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | chrome/browser/sync_file_system/sync_task_manager.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 #ifndef CHROME_BROWSER_SYNC_FILE_SYSTEM_SYNC_TASK_MANAGER_H_ 5 #ifndef CHROME_BROWSER_SYNC_FILE_SYSTEM_SYNC_TASK_MANAGER_H_
6 #define CHROME_BROWSER_SYNC_FILE_SYSTEM_SYNC_TASK_MANAGER_H_ 6 #define CHROME_BROWSER_SYNC_FILE_SYSTEM_SYNC_TASK_MANAGER_H_
7 7
8 #include <deque> 8 #include <deque>
9 9
10 #include "base/callback.h" 10 #include "base/callback.h"
(...skipping 30 matching lines...) Expand all
41 }; 41 };
42 42
43 explicit SyncTaskManager(base::WeakPtr<Client> client); 43 explicit SyncTaskManager(base::WeakPtr<Client> client);
44 virtual ~SyncTaskManager(); 44 virtual ~SyncTaskManager();
45 45
46 // This needs to be called to start task scheduling. 46 // This needs to be called to start task scheduling.
47 // If |status| is not SYNC_STATUS_OK calling this may change the 47 // If |status| is not SYNC_STATUS_OK calling this may change the
48 // service status. This should not be called more than once. 48 // service status. This should not be called more than once.
49 void Initialize(SyncStatusCode status); 49 void Initialize(SyncStatusCode status);
50 50
51 // Note that the argument of |task|'s parameter owns |callback|.
52 // The reference from |callback| to |task| causes circular dependency.
53 void ScheduleTask(const Task& task, 51 void ScheduleTask(const Task& task,
54 const SyncStatusCallback& callback); 52 const SyncStatusCallback& callback);
55 void ScheduleSyncTask(scoped_ptr<SyncTask> task, 53 void ScheduleSyncTask(scoped_ptr<SyncTask> task,
56 const SyncStatusCallback& callback); 54 const SyncStatusCallback& callback);
57 55
58 // Runs the posted task only when we're idle. 56 // Runs the posted task only when we're idle.
59 void ScheduleTaskIfIdle(const Task& task); 57 void ScheduleTaskIfIdle(const Task& task);
60 void ScheduleSyncTaskIfIdle(scoped_ptr<SyncTask> task); 58 void ScheduleSyncTaskIfIdle(scoped_ptr<SyncTask> task);
61 59
62 void NotifyTaskDone(scoped_ptr<TaskToken> token, 60 void NotifyTaskDone(scoped_ptr<TaskToken> token,
63 const SyncStatusCallback& callback,
64 SyncStatusCode status); 61 SyncStatusCode status);
65 62
66 private: 63 private:
67 // This should be called when an async task needs to get a task token. 64 // This should be called when an async task needs to get a task token.
68 scoped_ptr<TaskToken> GetToken(const tracked_objects::Location& from_here); 65 scoped_ptr<TaskToken> GetToken(const tracked_objects::Location& from_here);
69 66
70 // Creates a completion callback that calls NotifyTaskDone. 67 // Creates a completion callback that calls NotifyTaskDone.
71 // It is ok to give null |callback|. 68 // It is ok to give null |callback|.
72 SyncStatusCallback CreateCompletionCallback( 69 SyncStatusCallback CreateCompletionCallback(
73 scoped_ptr<TaskToken> token, 70 scoped_ptr<TaskToken> token,
74 const SyncStatusCallback& callback); 71 const SyncStatusCallback& callback);
75 72
76 base::WeakPtr<Client> client_; 73 base::WeakPtr<Client> client_;
77 74
78 SyncStatusCode last_operation_status_; 75 SyncStatusCode last_operation_status_;
79 scoped_ptr<SyncTask> running_task_; 76 scoped_ptr<SyncTask> running_task_;
80 std::deque<base::Closure> pending_tasks_; 77 std::deque<base::Closure> pending_tasks_;
78 SyncStatusCallback current_callback_;
79
81 80
82 // Absence of |token_| implies a task is running. Incoming tasks should 81 // Absence of |token_| implies a task is running. Incoming tasks should
83 // wait for the task to finish in |pending_tasks_| if |token_| is null. 82 // wait for the task to finish in |pending_tasks_| if |token_| is null.
84 // Each task must take TaskToken instance from |token_| and must hold it 83 // Each task must take TaskToken instance from |token_| and must hold it
85 // until it finished. And the task must return the instance through 84 // until it finished. And the task must return the instance through
86 // NotifyTaskDone when the task finished. 85 // NotifyTaskDone when the task finished.
87 scoped_ptr<TaskToken> token_; 86 scoped_ptr<TaskToken> token_;
88 87
89 DISALLOW_COPY_AND_ASSIGN(SyncTaskManager); 88 DISALLOW_COPY_AND_ASSIGN(SyncTaskManager);
90 }; 89 };
91 90
92 } // namespace sync_file_system 91 } // namespace sync_file_system
93 92
94 #endif // CHROME_BROWSER_SYNC_FILE_SYSTEM_SYNC_TASK_MANAGER_H_ 93 #endif // CHROME_BROWSER_SYNC_FILE_SYSTEM_SYNC_TASK_MANAGER_H_
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/sync_file_system/sync_task_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698