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

Side by Side Diff: chrome/browser/sessions/base_session_service.cc

Issue 685133004: Handling |SessionCommand|s as scoped_ptr's (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 1 month 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 (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
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.
96 ScopedVector<SessionCommand>* passed = new ScopedVector<SessionCommand>();
sky 2014/10/30 22:51:07 ScopedVector supports move semantics. Can't you su
Mr4D (OOO till 08-26) 2014/10/30 23:31:21 Aha. ScopedVector.passed() works. Interesting. Don
97 passed->swap(pending_commands_);
98 DCHECK(pending_commands_.empty());
94 RunTaskOnBackendThread( 99 RunTaskOnBackendThread(
95 FROM_HERE, 100 FROM_HERE,
96 base::Bind(&SessionBackend::AppendCommands, backend(), 101 base::Bind(&SessionBackend::AppendCommands, backend(),
97 new std::vector<SessionCommand*>(pending_commands_), 102 passed,
98 pending_reset_)); 103 pending_reset_));
99 104
100 // Backend took ownership of commands.
101 pending_commands_.clear();
102
103 if (pending_reset_) { 105 if (pending_reset_) {
104 commands_since_reset_ = 0; 106 commands_since_reset_ = 0;
105 pending_reset_ = false; 107 pending_reset_ = false;
106 } 108 }
107 } 109 }
108 110
109 bool BaseSessionService::ShouldTrackEntry(const GURL& url) { 111 bool BaseSessionService::ShouldTrackEntry(const GURL& url) {
110 return url.is_valid() && delegate_->ShouldTrackEntry(url); 112 return url.is_valid() && delegate_->ShouldTrackEntry(url);
111 } 113 }
112 114
(...skipping 25 matching lines...) Expand all
138 base::SequencedWorkerPool* pool = delegate_->GetBlockingPool(); 140 base::SequencedWorkerPool* pool = delegate_->GetBlockingPool();
139 if (!pool->IsShutdownInProgress()) { 141 if (!pool->IsShutdownInProgress()) {
140 pool->PostSequencedWorkerTask(sequence_token_, from_here, task); 142 pool->PostSequencedWorkerTask(sequence_token_, from_here, task);
141 } else { 143 } else {
142 // Fall back to executing on the main thread if the sequence 144 // Fall back to executing on the main thread if the sequence
143 // worker pool has been requested to shutdown (around shutdown 145 // worker pool has been requested to shutdown (around shutdown
144 // time). 146 // time).
145 task.Run(); 147 task.Run();
146 } 148 }
147 } 149 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698