| OLD | NEW |
| 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 Loading... |
| 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 Loading... |
| 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 |
| OLD | NEW |