| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/histogram.h" | 10 #include "base/histogram.h" |
| 11 #include "base/scoped_vector.h" | 11 #include "base/scoped_vector.h" |
| 12 #include "net/base/file_stream.h" | |
| 13 | 12 |
| 14 using base::TimeTicks; | 13 using base::TimeTicks; |
| 15 | 14 |
| 16 // File version number. | 15 // File version number. |
| 17 static const int32 kFileCurrentVersion = 1; | 16 static const int32 kFileCurrentVersion = 1; |
| 18 | 17 |
| 19 // The signature at the beginning of the file = SSNS (Sessions). | 18 // The signature at the beginning of the file = SSNS (Sessions). |
| 20 static const int32 kFileSignature = 0x53534E53; | 19 static const int32 kFileSignature = 0x53534E53; |
| 21 | 20 |
| 22 namespace { | 21 namespace { |
| (...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 329 content_size, NULL); | 328 content_size, NULL); |
| 330 if (wrote != content_size) { | 329 if (wrote != content_size) { |
| 331 NOTREACHED() << "error writing"; | 330 NOTREACHED() << "error writing"; |
| 332 return false; | 331 return false; |
| 333 } | 332 } |
| 334 } | 333 } |
| 335 } | 334 } |
| 336 return true; | 335 return true; |
| 337 } | 336 } |
| 338 | 337 |
| 339 SessionBackend::~SessionBackend() { | |
| 340 } | |
| 341 | |
| 342 void SessionBackend::ResetFile() { | 338 void SessionBackend::ResetFile() { |
| 343 DCHECK(inited_); | 339 DCHECK(inited_); |
| 344 if (current_session_file_.get()) { | 340 if (current_session_file_.get()) { |
| 345 // File is already open, truncate it. We truncate instead of closing and | 341 // File is already open, truncate it. We truncate instead of closing and |
| 346 // reopening to avoid the possibility of scanners locking the file out | 342 // reopening to avoid the possibility of scanners locking the file out |
| 347 // from under us once we close it. If truncation fails, we'll try to | 343 // from under us once we close it. If truncation fails, we'll try to |
| 348 // recreate. | 344 // recreate. |
| 349 if (current_session_file_->Truncate(sizeof_header()) != sizeof_header()) | 345 if (current_session_file_->Truncate(sizeof_header()) != sizeof_header()) |
| 350 current_session_file_.reset(NULL); | 346 current_session_file_.reset(NULL); |
| 351 } | 347 } |
| (...skipping 30 matching lines...) Expand all Loading... |
| 382 } | 378 } |
| 383 | 379 |
| 384 FilePath SessionBackend::GetCurrentSessionPath() { | 380 FilePath SessionBackend::GetCurrentSessionPath() { |
| 385 FilePath path = path_to_dir_; | 381 FilePath path = path_to_dir_; |
| 386 if (type_ == BaseSessionService::TAB_RESTORE) | 382 if (type_ == BaseSessionService::TAB_RESTORE) |
| 387 path = path.AppendASCII(kCurrentTabSessionFileName); | 383 path = path.AppendASCII(kCurrentTabSessionFileName); |
| 388 else | 384 else |
| 389 path = path.AppendASCII(kCurrentSessionFileName); | 385 path = path.AppendASCII(kCurrentSessionFileName); |
| 390 return path; | 386 return path; |
| 391 } | 387 } |
| OLD | NEW |