OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 "chrome/browser/sessions/base_session_service.h" | 5 #include "chrome/browser/sessions/base_session_service.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/threading/thread.h" | 8 #include "base/threading/thread.h" |
9 #include "chrome/browser/sessions/base_session_service_delegate.h" | 9 #include "chrome/browser/sessions/base_session_service_delegate.h" |
10 #include "chrome/browser/sessions/session_backend.h" | 10 #include "chrome/browser/sessions/session_backend.h" |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 | 60 |
61 BaseSessionService::~BaseSessionService() { | 61 BaseSessionService::~BaseSessionService() { |
62 } | 62 } |
63 | 63 |
64 void BaseSessionService::DeleteLastSession() { | 64 void BaseSessionService::DeleteLastSession() { |
65 RunTaskOnBackendThread( | 65 RunTaskOnBackendThread( |
66 FROM_HERE, | 66 FROM_HERE, |
67 base::Bind(&SessionBackend::DeleteLastSession, backend())); | 67 base::Bind(&SessionBackend::DeleteLastSession, backend())); |
68 } | 68 } |
69 | 69 |
70 void BaseSessionService::ScheduleCommand(SessionCommand* command) { | 70 void BaseSessionService::ScheduleCommand(scoped_ptr<SessionCommand> command) { |
71 DCHECK(command); | 71 DCHECK(command); |
72 commands_since_reset_++; | 72 commands_since_reset_++; |
73 pending_commands_.push_back(command); | 73 pending_commands_.push_back(command.release()); |
74 StartSaveTimer(); | 74 StartSaveTimer(); |
75 } | 75 } |
76 | 76 |
77 void BaseSessionService::StartSaveTimer() { | 77 void BaseSessionService::StartSaveTimer() { |
78 // Don't start a timer when testing. | 78 // Don't start a timer when testing. |
79 if (delegate_->ShouldUseDelayedSave() && base::MessageLoop::current() && | 79 if (delegate_->ShouldUseDelayedSave() && base::MessageLoop::current() && |
80 !weak_factory_.HasWeakPtrs()) { | 80 !weak_factory_.HasWeakPtrs()) { |
81 base::MessageLoop::current()->PostDelayedTask( | 81 base::MessageLoop::current()->PostDelayedTask( |
82 FROM_HERE, | 82 FROM_HERE, |
83 base::Bind(&BaseSessionService::Save, weak_factory_.GetWeakPtr()), | 83 base::Bind(&BaseSessionService::Save, weak_factory_.GetWeakPtr()), |
84 base::TimeDelta::FromMilliseconds(kSaveDelayMS)); | 84 base::TimeDelta::FromMilliseconds(kSaveDelayMS)); |
85 } | 85 } |
86 } | 86 } |
87 | 87 |
88 void BaseSessionService::Save() { | 88 void BaseSessionService::Save() { |
89 DCHECK(backend()); | 89 DCHECK(backend()); |
90 | 90 |
91 if (pending_commands_.empty()) | 91 if (pending_commands_.empty()) |
92 return; | 92 return; |
93 | 93 |
| 94 // We create a new ScopedVector which will receive all elements from the |
| 95 // current commands. This will also clear the current list. |
94 RunTaskOnBackendThread( | 96 RunTaskOnBackendThread( |
95 FROM_HERE, | 97 FROM_HERE, |
96 base::Bind(&SessionBackend::AppendCommands, backend(), | 98 base::Bind(&SessionBackend::AppendCommands, backend(), |
97 new std::vector<SessionCommand*>(pending_commands_), | 99 new ScopedVector<SessionCommand>(pending_commands_.Pass()), |
98 pending_reset_)); | 100 pending_reset_)); |
99 | 101 |
100 // Backend took ownership of commands. | |
101 pending_commands_.clear(); | |
102 | |
103 if (pending_reset_) { | 102 if (pending_reset_) { |
104 commands_since_reset_ = 0; | 103 commands_since_reset_ = 0; |
105 pending_reset_ = false; | 104 pending_reset_ = false; |
106 } | 105 } |
107 } | 106 } |
108 | 107 |
109 bool BaseSessionService::ShouldTrackEntry(const GURL& url) { | 108 bool BaseSessionService::ShouldTrackEntry(const GURL& url) { |
110 return url.is_valid() && delegate_->ShouldTrackEntry(url); | 109 return url.is_valid() && delegate_->ShouldTrackEntry(url); |
111 } | 110 } |
112 | 111 |
(...skipping 25 matching lines...) Expand all Loading... |
138 base::SequencedWorkerPool* pool = delegate_->GetBlockingPool(); | 137 base::SequencedWorkerPool* pool = delegate_->GetBlockingPool(); |
139 if (!pool->IsShutdownInProgress()) { | 138 if (!pool->IsShutdownInProgress()) { |
140 pool->PostSequencedWorkerTask(sequence_token_, from_here, task); | 139 pool->PostSequencedWorkerTask(sequence_token_, from_here, task); |
141 } else { | 140 } else { |
142 // Fall back to executing on the main thread if the sequence | 141 // Fall back to executing on the main thread if the sequence |
143 // worker pool has been requested to shutdown (around shutdown | 142 // worker pool has been requested to shutdown (around shutdown |
144 // time). | 143 // time). |
145 task.Run(); | 144 task.Run(); |
146 } | 145 } |
147 } | 146 } |
OLD | NEW |