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

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

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
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 #include "chrome/browser/sync_file_system/sync_task_manager.h" 5 #include "chrome/browser/sync_file_system/sync_task_manager.h"
6 6
7 #include "base/debug/trace_event.h" 7 #include "base/debug/trace_event.h"
8 #include "base/location.h" 8 #include "base/location.h"
9 #include "chrome/browser/sync_file_system/sync_file_metadata.h" 9 #include "chrome/browser/sync_file_system/sync_file_metadata.h"
10 10
(...skipping 20 matching lines...) Expand all
31 // it must return the token to TaskManager. 31 // it must return the token to TaskManager.
32 // Destroying a token with valid |client| indicates the token was 32 // Destroying a token with valid |client| indicates the token was
33 // dropped by a task without returning. 33 // dropped by a task without returning.
34 if (manager_.get() && manager_->client_.get()) { 34 if (manager_.get() && manager_->client_.get()) {
35 NOTREACHED() 35 NOTREACHED()
36 << "Unexpected TaskToken deletion from: " << location_.ToString(); 36 << "Unexpected TaskToken deletion from: " << location_.ToString();
37 37
38 // Reinitializes the token. 38 // Reinitializes the token.
39 manager_->NotifyTaskDone( 39 manager_->NotifyTaskDone(
40 make_scoped_ptr(new TaskToken(manager_)), 40 make_scoped_ptr(new TaskToken(manager_)),
41 SyncStatusCallback(),
42 SYNC_STATUS_OK); 41 SYNC_STATUS_OK);
43 } 42 }
44 } 43 }
45 44
46 private: 45 private:
47 base::WeakPtr<SyncTaskManager> manager_; 46 base::WeakPtr<SyncTaskManager> manager_;
48 tracked_objects::Location location_; 47 tracked_objects::Location location_;
49 48
50 DISALLOW_COPY_AND_ASSIGN(TaskToken); 49 DISALLOW_COPY_AND_ASSIGN(TaskToken);
51 }; 50 };
52 51
53 SyncTaskManager::SyncTaskManager( 52 SyncTaskManager::SyncTaskManager(
54 base::WeakPtr<Client> client) 53 base::WeakPtr<Client> client)
55 : client_(client), 54 : client_(client),
56 last_operation_status_(SYNC_STATUS_OK) { 55 last_operation_status_(SYNC_STATUS_OK) {
57 } 56 }
58 57
59 SyncTaskManager::~SyncTaskManager() { 58 SyncTaskManager::~SyncTaskManager() {
60 client_.reset(); 59 client_.reset();
61 token_.reset(); 60 token_.reset();
62 } 61 }
63 62
64 void SyncTaskManager::Initialize(SyncStatusCode status) { 63 void SyncTaskManager::Initialize(SyncStatusCode status) {
65 DCHECK(!token_); 64 DCHECK(!token_);
66 NotifyTaskDone(make_scoped_ptr(new TaskToken(AsWeakPtr())), 65 NotifyTaskDone(make_scoped_ptr(new TaskToken(AsWeakPtr())),
67 SyncStatusCallback(),
68 status); 66 status);
69 } 67 }
70 68
71 void SyncTaskManager::ScheduleTask( 69 void SyncTaskManager::ScheduleTask(
72 const Task& task, 70 const Task& task,
73 const SyncStatusCallback& callback) { 71 const SyncStatusCallback& callback) {
74 scoped_ptr<TaskToken> token(GetToken(FROM_HERE)); 72 scoped_ptr<TaskToken> token(GetToken(FROM_HERE));
75 if (!token) { 73 if (!token) {
76 pending_tasks_.push_back(base::Bind( 74 pending_tasks_.push_back(base::Bind(
77 &SyncTaskManager::ScheduleTask, AsWeakPtr(), task, callback)); 75 &SyncTaskManager::ScheduleTask, AsWeakPtr(), task, callback));
(...skipping 29 matching lines...) Expand all
107 if (!token) 105 if (!token)
108 return; 106 return;
109 DCHECK(!running_task_); 107 DCHECK(!running_task_);
110 running_task_ = task.Pass(); 108 running_task_ = task.Pass();
111 running_task_->Run(CreateCompletionCallback(token.Pass(), 109 running_task_->Run(CreateCompletionCallback(token.Pass(),
112 SyncStatusCallback())); 110 SyncStatusCallback()));
113 } 111 }
114 112
115 void SyncTaskManager::NotifyTaskDone( 113 void SyncTaskManager::NotifyTaskDone(
116 scoped_ptr<TaskToken> token, 114 scoped_ptr<TaskToken> token,
117 const SyncStatusCallback& callback,
118 SyncStatusCode status) { 115 SyncStatusCode status) {
119 DCHECK(token); 116 DCHECK(token);
120 last_operation_status_ = status; 117 last_operation_status_ = status;
121 token_ = token.Pass(); 118 token_ = token.Pass();
122 scoped_ptr<SyncTask> task = running_task_.Pass(); 119 scoped_ptr<SyncTask> task = running_task_.Pass();
123 TRACE_EVENT_ASYNC_END0("Sync FileSystem", "GetToken", this); 120 TRACE_EVENT_ASYNC_END0("Sync FileSystem", "GetToken", this);
124 121
125 DVLOG(3) << "NotifyTaskDone: " << "finished with status=" << status 122 DVLOG(3) << "NotifyTaskDone: " << "finished with status=" << status
126 << " (" << SyncStatusCodeToString(status) << ")" 123 << " (" << SyncStatusCodeToString(status) << ")"
127 << " " << token_->location().ToString(); 124 << " " << token_->location().ToString();
128 125
129 if (client_) 126 if (client_)
130 client_->NotifyLastOperationStatus(last_operation_status_); 127 client_->NotifyLastOperationStatus(last_operation_status_);
131 128
132 if (!callback.is_null()) 129 if (!current_callback_.is_null())
133 callback.Run(status); 130 current_callback_.Run(status);
131 current_callback_.Reset();
134 132
135 if (!pending_tasks_.empty()) { 133 if (!pending_tasks_.empty()) {
136 base::Closure closure = pending_tasks_.front(); 134 base::Closure closure = pending_tasks_.front();
137 pending_tasks_.pop_front(); 135 pending_tasks_.pop_front();
138 closure.Run(); 136 closure.Run();
139 return; 137 return;
140 } 138 }
141 139
142 if (client_) 140 if (client_)
143 client_->MaybeScheduleNextTask(); 141 client_->MaybeScheduleNextTask();
144 } 142 }
145 143
146 scoped_ptr<SyncTaskManager::TaskToken> SyncTaskManager::GetToken( 144 scoped_ptr<SyncTaskManager::TaskToken> SyncTaskManager::GetToken(
147 const tracked_objects::Location& from_here) { 145 const tracked_objects::Location& from_here) {
148 if (!token_) 146 if (!token_)
149 return scoped_ptr<TaskToken>(); 147 return scoped_ptr<TaskToken>();
150 TRACE_EVENT_ASYNC_BEGIN1("Sync FileSystem", "GetToken", this, 148 TRACE_EVENT_ASYNC_BEGIN1("Sync FileSystem", "GetToken", this,
151 "where", from_here.ToString()); 149 "where", from_here.ToString());
152 token_->UpdateTask(from_here); 150 token_->UpdateTask(from_here);
153 return token_.Pass(); 151 return token_.Pass();
154 } 152 }
155 153
156 SyncStatusCallback SyncTaskManager::CreateCompletionCallback( 154 SyncStatusCallback SyncTaskManager::CreateCompletionCallback(
157 scoped_ptr<TaskToken> token, 155 scoped_ptr<TaskToken> token,
158 const SyncStatusCallback& callback) { 156 const SyncStatusCallback& callback) {
159 DCHECK(token); 157 DCHECK(token);
158 DCHECK(current_callback_.is_null());
159 current_callback_ = callback;
160 return base::Bind(&SyncTaskManager::NotifyTaskDone, 160 return base::Bind(&SyncTaskManager::NotifyTaskDone,
161 AsWeakPtr(), base::Passed(&token), callback); 161 AsWeakPtr(), base::Passed(&token));
162 } 162 }
163 163
164 } // namespace sync_file_system 164 } // namespace sync_file_system
OLDNEW
« no previous file with comments | « chrome/browser/sync_file_system/sync_task_manager.h ('k') | chrome/browser/sync_file_system/sync_task_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698