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

Side by Side Diff: chrome/browser/sync_file_system/drive_backend/sync_task_token.cc

Issue 1873683002: Convert //chrome/browser/sync_file_system from scoped_ptr to std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 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/drive_backend/sync_task_token.h" 5 #include "chrome/browser/sync_file_system/drive_backend/sync_task_token.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/memory/ptr_util.h"
10 #include "base/thread_task_runner_handle.h" 11 #include "base/thread_task_runner_handle.h"
11 #include "base/trace_event/trace_event.h" 12 #include "base/trace_event/trace_event.h"
12 #include "chrome/browser/sync_file_system/drive_backend/sync_task_manager.h" 13 #include "chrome/browser/sync_file_system/drive_backend/sync_task_manager.h"
13 #include "chrome/browser/sync_file_system/drive_backend/task_dependency_manager. h" 14 #include "chrome/browser/sync_file_system/drive_backend/task_dependency_manager. h"
14 15
15 namespace sync_file_system { 16 namespace sync_file_system {
16 namespace drive_backend { 17 namespace drive_backend {
17 18
18 const int64_t SyncTaskToken::kTestingTaskTokenID = -1; 19 const int64_t SyncTaskToken::kTestingTaskTokenID = -1;
19 const int64_t SyncTaskToken::kForegroundTaskTokenID = 0; 20 const int64_t SyncTaskToken::kForegroundTaskTokenID = 0;
20 const int64_t SyncTaskToken::kMinimumBackgroundTaskTokenID = 1; 21 const int64_t SyncTaskToken::kMinimumBackgroundTaskTokenID = 1;
21 22
22 // static 23 // static
23 scoped_ptr<SyncTaskToken> SyncTaskToken::CreateForTesting( 24 std::unique_ptr<SyncTaskToken> SyncTaskToken::CreateForTesting(
24 const SyncStatusCallback& callback) { 25 const SyncStatusCallback& callback) {
25 return make_scoped_ptr(new SyncTaskToken( 26 return base::WrapUnique(new SyncTaskToken(base::WeakPtr<SyncTaskManager>(),
26 base::WeakPtr<SyncTaskManager>(), 27 base::ThreadTaskRunnerHandle::Get(),
27 base::ThreadTaskRunnerHandle::Get(), 28 kTestingTaskTokenID,
28 kTestingTaskTokenID, 29 nullptr, // task_blocker
29 nullptr, // task_blocker 30 callback));
30 callback));
31 } 31 }
32 32
33 // static 33 // static
34 scoped_ptr<SyncTaskToken> SyncTaskToken::CreateForForegroundTask( 34 std::unique_ptr<SyncTaskToken> SyncTaskToken::CreateForForegroundTask(
35 const base::WeakPtr<SyncTaskManager>& manager, 35 const base::WeakPtr<SyncTaskManager>& manager,
36 base::SequencedTaskRunner* task_runner) { 36 base::SequencedTaskRunner* task_runner) {
37 return make_scoped_ptr(new SyncTaskToken( 37 return base::WrapUnique(new SyncTaskToken(manager, task_runner,
38 manager, 38 kForegroundTaskTokenID,
39 task_runner, 39 nullptr, // task_blocker
40 kForegroundTaskTokenID, 40 SyncStatusCallback()));
41 nullptr, // task_blocker
42 SyncStatusCallback()));
43 } 41 }
44 42
45 // static 43 // static
46 scoped_ptr<SyncTaskToken> SyncTaskToken::CreateForBackgroundTask( 44 std::unique_ptr<SyncTaskToken> SyncTaskToken::CreateForBackgroundTask(
47 const base::WeakPtr<SyncTaskManager>& manager, 45 const base::WeakPtr<SyncTaskManager>& manager,
48 base::SequencedTaskRunner* task_runner, 46 base::SequencedTaskRunner* task_runner,
49 int64_t token_id, 47 int64_t token_id,
50 scoped_ptr<TaskBlocker> task_blocker) { 48 std::unique_ptr<TaskBlocker> task_blocker) {
51 return make_scoped_ptr(new SyncTaskToken(manager, task_runner, token_id, 49 return base::WrapUnique(new SyncTaskToken(manager, task_runner, token_id,
52 std::move(task_blocker), 50 std::move(task_blocker),
53 SyncStatusCallback())); 51 SyncStatusCallback()));
54 } 52 }
55 53
56 void SyncTaskToken::UpdateTask(const tracked_objects::Location& location, 54 void SyncTaskToken::UpdateTask(const tracked_objects::Location& location,
57 const SyncStatusCallback& callback) { 55 const SyncStatusCallback& callback) {
58 DCHECK(callback_.is_null()); 56 DCHECK(callback_.is_null());
59 location_ = location; 57 location_ = location;
60 callback_ = callback; 58 callback_ = callback;
61 DVLOG(2) << "Token updated: " << location_.ToString(); 59 DVLOG(2) << "Token updated: " << location_.ToString();
62 } 60 }
63 61
64 SyncTaskToken::~SyncTaskToken() { 62 SyncTaskToken::~SyncTaskToken() {
65 // All task on Client must hold TaskToken instance to ensure 63 // All task on Client must hold TaskToken instance to ensure
66 // no other tasks are running. Also, as soon as a task finishes to work, 64 // no other tasks are running. Also, as soon as a task finishes to work,
67 // it must return the token to TaskManager. 65 // it must return the token to TaskManager.
68 // Destroying a token with valid |client| indicates the token was 66 // Destroying a token with valid |client| indicates the token was
69 // dropped by a task without returning. 67 // dropped by a task without returning.
70 if (task_runner_.get() && task_runner_->RunsTasksOnCurrentThread() && 68 if (task_runner_.get() && task_runner_->RunsTasksOnCurrentThread() &&
71 manager_ && manager_->IsRunningTask(token_id_)) { 69 manager_ && manager_->IsRunningTask(token_id_)) {
72 if (!manager_->ShouldTrackTaskToken()) 70 if (!manager_->ShouldTrackTaskToken())
73 return; 71 return;
74 72
75 NOTREACHED() 73 NOTREACHED()
76 << "Unexpected TaskToken deletion from: " << location_.ToString(); 74 << "Unexpected TaskToken deletion from: " << location_.ToString();
77 75
78 // Reinitializes the token. 76 // Reinitializes the token.
79 SyncTaskManager::NotifyTaskDone( 77 SyncTaskManager::NotifyTaskDone(
80 make_scoped_ptr(new SyncTaskToken(manager_, task_runner_.get(), 78 base::WrapUnique(new SyncTaskToken(manager_, task_runner_.get(),
81 token_id_, std::move(task_blocker_), 79 token_id_, std::move(task_blocker_),
82 SyncStatusCallback())), 80 SyncStatusCallback())),
83 SYNC_STATUS_OK); 81 SYNC_STATUS_OK);
84 } 82 }
85 } 83 }
86 84
87 // static 85 // static
88 SyncStatusCallback SyncTaskToken::WrapToCallback( 86 SyncStatusCallback SyncTaskToken::WrapToCallback(
89 scoped_ptr<SyncTaskToken> token) { 87 std::unique_ptr<SyncTaskToken> token) {
90 return base::Bind(&SyncTaskManager::NotifyTaskDone, base::Passed(&token)); 88 return base::Bind(&SyncTaskManager::NotifyTaskDone, base::Passed(&token));
91 } 89 }
92 90
93 void SyncTaskToken::set_task_blocker( 91 void SyncTaskToken::set_task_blocker(
94 scoped_ptr<TaskBlocker> task_blocker) { 92 std::unique_ptr<TaskBlocker> task_blocker) {
95 task_blocker_ = std::move(task_blocker); 93 task_blocker_ = std::move(task_blocker);
96 } 94 }
97 95
98 const TaskBlocker* SyncTaskToken::task_blocker() const { 96 const TaskBlocker* SyncTaskToken::task_blocker() const {
99 return task_blocker_.get(); 97 return task_blocker_.get();
100 } 98 }
101 99
102 void SyncTaskToken::clear_task_blocker() { 100 void SyncTaskToken::clear_task_blocker() {
103 task_blocker_.reset(); 101 task_blocker_.reset();
104 } 102 }
(...skipping 18 matching lines...) Expand all
123 DCHECK(task_log_); 121 DCHECK(task_log_);
124 task_log_->result_description = result_description; 122 task_log_->result_description = result_description;
125 task_log_->end_time = base::TimeTicks::Now(); 123 task_log_->end_time = base::TimeTicks::Now();
126 } 124 }
127 125
128 void SyncTaskToken::RecordLog(const std::string& message) { 126 void SyncTaskToken::RecordLog(const std::string& message) {
129 DCHECK(task_log_); 127 DCHECK(task_log_);
130 task_log_->details.push_back(message); 128 task_log_->details.push_back(message);
131 } 129 }
132 130
133 void SyncTaskToken::SetTaskLog(scoped_ptr<TaskLogger::TaskLog> task_log) { 131 void SyncTaskToken::SetTaskLog(std::unique_ptr<TaskLogger::TaskLog> task_log) {
134 task_log_ = std::move(task_log); 132 task_log_ = std::move(task_log);
135 } 133 }
136 134
137 scoped_ptr<TaskLogger::TaskLog> SyncTaskToken::PassTaskLog() { 135 std::unique_ptr<TaskLogger::TaskLog> SyncTaskToken::PassTaskLog() {
138 return std::move(task_log_); 136 return std::move(task_log_);
139 } 137 }
140 138
141 SyncTaskToken::SyncTaskToken( 139 SyncTaskToken::SyncTaskToken(
142 const base::WeakPtr<SyncTaskManager>& manager, 140 const base::WeakPtr<SyncTaskManager>& manager,
143 const scoped_refptr<base::SequencedTaskRunner>& task_runner, 141 const scoped_refptr<base::SequencedTaskRunner>& task_runner,
144 int64_t token_id, 142 int64_t token_id,
145 scoped_ptr<TaskBlocker> task_blocker, 143 std::unique_ptr<TaskBlocker> task_blocker,
146 const SyncStatusCallback& callback) 144 const SyncStatusCallback& callback)
147 : manager_(manager), 145 : manager_(manager),
148 task_runner_(task_runner), 146 task_runner_(task_runner),
149 token_id_(token_id), 147 token_id_(token_id),
150 callback_(callback), 148 callback_(callback),
151 task_blocker_(std::move(task_blocker)) {} 149 task_blocker_(std::move(task_blocker)) {}
152 150
153 } // namespace drive_backend 151 } // namespace drive_backend
154 } // namespace sync_file_system 152 } // namespace sync_file_system
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698