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

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

Issue 11446033: Convert SessionService to use new CancelableTaskTracker (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years 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 | Annotate | Revision Log
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/session_backend.h" 5 #include "chrome/browser/sessions/session_backend.h"
6 6
7 #include <limits> 7 #include <limits>
8 8
9 #include "base/file_util.h" 9 #include "base/file_util.h"
10 #include "base/memory/scoped_vector.h" 10 #include "base/memory/scoped_vector.h"
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after
237 if (current_session_file_.get() && current_session_file_->IsOpen() && 237 if (current_session_file_.get() && current_session_file_->IsOpen() &&
238 !AppendCommandsToFile(current_session_file_.get(), *commands)) { 238 !AppendCommandsToFile(current_session_file_.get(), *commands)) {
239 current_session_file_.reset(NULL); 239 current_session_file_.reset(NULL);
240 } 240 }
241 empty_file_ = false; 241 empty_file_ = false;
242 STLDeleteElements(commands); 242 STLDeleteElements(commands);
243 delete commands; 243 delete commands;
244 } 244 }
245 245
246 void SessionBackend::ReadLastSessionCommands( 246 void SessionBackend::ReadLastSessionCommands(
247 scoped_refptr<BaseSessionService::InternalGetCommandsRequest> request) { 247 const CancelableTaskTracker::IsCanceledCallback& is_canceled,
248 if (request->canceled()) 248 const BaseSessionService::InternalGetCommandsCallback& callback) {
249 if (is_canceled.Run())
249 return; 250 return;
251
250 Init(); 252 Init();
251 ReadLastSessionCommandsImpl(&(request->commands)); 253
252 request->ForwardResult(request->handle(), request); 254 ScopedVector<SessionCommand> commands;
255 ReadLastSessionCommandsImpl(&(commands.get()));
256 callback.Run(commands.Pass());
253 } 257 }
254 258
255 bool SessionBackend::ReadLastSessionCommandsImpl( 259 bool SessionBackend::ReadLastSessionCommandsImpl(
256 std::vector<SessionCommand*>* commands) { 260 std::vector<SessionCommand*>* commands) {
257 Init(); 261 Init();
258 SessionFileReader file_reader(GetLastSessionPath()); 262 SessionFileReader file_reader(GetLastSessionPath());
259 return file_reader.Read(type_, commands); 263 return file_reader.Read(type_, commands);
260 } 264 }
261 265
262 void SessionBackend::DeleteLastSession() { 266 void SessionBackend::DeleteLastSession() {
(...skipping 24 matching lines...) Expand all
287 last_session_path); 291 last_session_path);
288 } 292 }
289 293
290 if (file_util::PathExists(current_session_path)) 294 if (file_util::PathExists(current_session_path))
291 file_util::Delete(current_session_path, false); 295 file_util::Delete(current_session_path, false);
292 296
293 // Create and open the file for the current session. 297 // Create and open the file for the current session.
294 ResetFile(); 298 ResetFile();
295 } 299 }
296 300
297 void SessionBackend::ReadCurrentSessionCommands(
298 scoped_refptr<BaseSessionService::InternalGetCommandsRequest> request) {
299 if (request->canceled())
300 return;
301 Init();
302 ReadCurrentSessionCommandsImpl(&(request->commands));
303 request->ForwardResult(request->handle(), request);
304 }
305
306 bool SessionBackend::ReadCurrentSessionCommandsImpl( 301 bool SessionBackend::ReadCurrentSessionCommandsImpl(
307 std::vector<SessionCommand*>* commands) { 302 std::vector<SessionCommand*>* commands) {
308 Init(); 303 Init();
309 SessionFileReader file_reader(GetCurrentSessionPath()); 304 SessionFileReader file_reader(GetCurrentSessionPath());
310 return file_reader.Read(type_, commands); 305 return file_reader.Read(type_, commands);
311 } 306 }
312 307
313 bool SessionBackend::AppendCommandsToFile(net::FileStream* file, 308 bool SessionBackend::AppendCommandsToFile(net::FileStream* file,
314 const std::vector<SessionCommand*>& commands) { 309 const std::vector<SessionCommand*>& commands) {
315 for (std::vector<SessionCommand*>::const_iterator i = commands.begin(); 310 for (std::vector<SessionCommand*>::const_iterator i = commands.begin();
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
399 } 394 }
400 395
401 FilePath SessionBackend::GetCurrentSessionPath() { 396 FilePath SessionBackend::GetCurrentSessionPath() {
402 FilePath path = path_to_dir_; 397 FilePath path = path_to_dir_;
403 if (type_ == BaseSessionService::TAB_RESTORE) 398 if (type_ == BaseSessionService::TAB_RESTORE)
404 path = path.AppendASCII(kCurrentTabSessionFileName); 399 path = path.AppendASCII(kCurrentTabSessionFileName);
405 else 400 else
406 path = path.AppendASCII(kCurrentSessionFileName); 401 path = path.AppendASCII(kCurrentSessionFileName);
407 return path; 402 return path;
408 } 403 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698