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

Side by Side Diff: components/sessions/base_session_service.cc

Issue 1144153004: components: Remove use of MessageLoopProxy and deprecated MessageLoop APIs (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased. Created 5 years, 6 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 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2012 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 "components/sessions/base_session_service.h" 5 #include "components/sessions/base_session_service.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/location.h"
9 #include "base/single_thread_task_runner.h"
10 #include "base/thread_task_runner_handle.h"
8 #include "base/threading/thread.h" 11 #include "base/threading/thread.h"
9 #include "components/sessions/base_session_service_delegate.h" 12 #include "components/sessions/base_session_service_delegate.h"
10 #include "components/sessions/session_backend.h" 13 #include "components/sessions/session_backend.h"
11 14
12 // BaseSessionService --------------------------------------------------------- 15 // BaseSessionService ---------------------------------------------------------
13 16
14 namespace sessions { 17 namespace sessions {
15 namespace { 18 namespace {
16 19
17 // Helper used by ScheduleGetLastSessionCommands. It runs callback on TaskRunner 20 // Helper used by ScheduleGetLastSessionCommands. It runs callback on TaskRunner
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 } 108 }
106 109
107 void BaseSessionService::ClearPendingCommands() { 110 void BaseSessionService::ClearPendingCommands() {
108 pending_commands_.clear(); 111 pending_commands_.clear();
109 } 112 }
110 113
111 void BaseSessionService::StartSaveTimer() { 114 void BaseSessionService::StartSaveTimer() {
112 // Don't start a timer when testing. 115 // Don't start a timer when testing.
113 if (delegate_->ShouldUseDelayedSave() && base::MessageLoop::current() && 116 if (delegate_->ShouldUseDelayedSave() && base::MessageLoop::current() &&
114 !weak_factory_.HasWeakPtrs()) { 117 !weak_factory_.HasWeakPtrs()) {
115 base::MessageLoop::current()->PostDelayedTask( 118 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
116 FROM_HERE, 119 FROM_HERE,
117 base::Bind(&BaseSessionService::Save, 120 base::Bind(&BaseSessionService::Save, weak_factory_.GetWeakPtr()),
118 weak_factory_.GetWeakPtr()),
119 base::TimeDelta::FromMilliseconds(kSaveDelayMS)); 121 base::TimeDelta::FromMilliseconds(kSaveDelayMS));
120 } 122 }
121 } 123 }
122 124
123 void BaseSessionService::Save() { 125 void BaseSessionService::Save() {
124 // Inform the delegate that we will save the commands now, giving it the 126 // Inform the delegate that we will save the commands now, giving it the
125 // opportunity to append more commands. 127 // opportunity to append more commands.
126 delegate_->OnWillSaveCommands(); 128 delegate_->OnWillSaveCommands();
127 129
128 if (pending_commands_.empty()) 130 if (pending_commands_.empty())
(...skipping 21 matching lines...) Expand all
150 base::CancelableTaskTracker* tracker) { 152 base::CancelableTaskTracker* tracker) {
151 base::CancelableTaskTracker::IsCanceledCallback is_canceled; 153 base::CancelableTaskTracker::IsCanceledCallback is_canceled;
152 base::CancelableTaskTracker::TaskId id = 154 base::CancelableTaskTracker::TaskId id =
153 tracker->NewTrackedTaskId(&is_canceled); 155 tracker->NewTrackedTaskId(&is_canceled);
154 156
155 GetCommandsCallback run_if_not_canceled = 157 GetCommandsCallback run_if_not_canceled =
156 base::Bind(&RunIfNotCanceled, is_canceled, callback); 158 base::Bind(&RunIfNotCanceled, is_canceled, callback);
157 159
158 GetCommandsCallback callback_runner = 160 GetCommandsCallback callback_runner =
159 base::Bind(&PostOrRunInternalGetCommandsCallback, 161 base::Bind(&PostOrRunInternalGetCommandsCallback,
160 base::MessageLoopProxy::current(), run_if_not_canceled); 162 base::ThreadTaskRunnerHandle::Get(), run_if_not_canceled);
161 163
162 RunTaskOnBackendThread( 164 RunTaskOnBackendThread(
163 FROM_HERE, 165 FROM_HERE,
164 base::Bind(&SessionBackend::ReadLastSessionCommands, backend_, 166 base::Bind(&SessionBackend::ReadLastSessionCommands, backend_,
165 is_canceled, callback_runner)); 167 is_canceled, callback_runner));
166 return id; 168 return id;
167 } 169 }
168 170
169 void BaseSessionService::RunTaskOnBackendThread( 171 void BaseSessionService::RunTaskOnBackendThread(
170 const tracked_objects::Location& from_here, 172 const tracked_objects::Location& from_here,
171 const base::Closure& task) { 173 const base::Closure& task) {
172 base::SequencedWorkerPool* pool = delegate_->GetBlockingPool(); 174 base::SequencedWorkerPool* pool = delegate_->GetBlockingPool();
173 if (!pool->IsShutdownInProgress()) { 175 if (!pool->IsShutdownInProgress()) {
174 pool->PostSequencedWorkerTask(sequence_token_, from_here, task); 176 pool->PostSequencedWorkerTask(sequence_token_, from_here, task);
175 } else { 177 } else {
176 // Fall back to executing on the main thread if the sequence 178 // Fall back to executing on the main thread if the sequence
177 // worker pool has been requested to shutdown (around shutdown 179 // worker pool has been requested to shutdown (around shutdown
178 // time). 180 // time).
179 task.Run(); 181 task.Run();
180 } 182 }
181 } 183 }
182 184
183 } // namespace sessions 185 } // namespace sessions
OLDNEW
« no previous file with comments | « components/search_provider_logos/logo_tracker_unittest.cc ('k') | components/signin/core/browser/account_reconcilor.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698