| 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/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 331 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 342 return false; | 342 return false; |
| 343 } | 343 } |
| 344 } | 344 } |
| 345 } | 345 } |
| 346 file->FlushSync(); | 346 file->FlushSync(); |
| 347 return true; | 347 return true; |
| 348 } | 348 } |
| 349 | 349 |
| 350 SessionBackend::~SessionBackend() { | 350 SessionBackend::~SessionBackend() { |
| 351 if (current_session_file_.get()) { | 351 if (current_session_file_.get()) { |
| 352 // Close() performs file IO. crbug.com/112512. | 352 // Destructor performs file IO because file is open in sync mode. |
| 353 // crbug.com/112512. |
| 353 base::ThreadRestrictions::ScopedAllowIO allow_io; | 354 base::ThreadRestrictions::ScopedAllowIO allow_io; |
| 354 current_session_file_->CloseSync(); | 355 current_session_file_.reset(); |
| 355 } | 356 } |
| 356 } | 357 } |
| 357 | 358 |
| 358 void SessionBackend::ResetFile() { | 359 void SessionBackend::ResetFile() { |
| 359 DCHECK(inited_); | 360 DCHECK(inited_); |
| 360 if (current_session_file_.get()) { | 361 if (current_session_file_.get()) { |
| 361 // File is already open, truncate it. We truncate instead of closing and | 362 // File is already open, truncate it. We truncate instead of closing and |
| 362 // reopening to avoid the possibility of scanners locking the file out | 363 // reopening to avoid the possibility of scanners locking the file out |
| 363 // from under us once we close it. If truncation fails, we'll try to | 364 // from under us once we close it. If truncation fails, we'll try to |
| 364 // recreate. | 365 // recreate. |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 398 } | 399 } |
| 399 | 400 |
| 400 FilePath SessionBackend::GetCurrentSessionPath() { | 401 FilePath SessionBackend::GetCurrentSessionPath() { |
| 401 FilePath path = path_to_dir_; | 402 FilePath path = path_to_dir_; |
| 402 if (type_ == BaseSessionService::TAB_RESTORE) | 403 if (type_ == BaseSessionService::TAB_RESTORE) |
| 403 path = path.AppendASCII(kCurrentTabSessionFileName); | 404 path = path.AppendASCII(kCurrentTabSessionFileName); |
| 404 else | 405 else |
| 405 path = path.AppendASCII(kCurrentSessionFileName); | 406 path = path.AppendASCII(kCurrentSessionFileName); |
| 406 return path; | 407 return path; |
| 407 } | 408 } |
| OLD | NEW |