| 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" |
| (...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 345 if (current_session_file_->Truncate(sizeof_header()) != sizeof_header()) | 345 if (current_session_file_->Truncate(sizeof_header()) != sizeof_header()) |
| 346 current_session_file_.reset(NULL); | 346 current_session_file_.reset(NULL); |
| 347 } | 347 } |
| 348 if (!current_session_file_.get()) | 348 if (!current_session_file_.get()) |
| 349 current_session_file_.reset(OpenAndWriteHeader(GetCurrentSessionPath())); | 349 current_session_file_.reset(OpenAndWriteHeader(GetCurrentSessionPath())); |
| 350 empty_file_ = true; | 350 empty_file_ = true; |
| 351 } | 351 } |
| 352 | 352 |
| 353 net::FileStream* SessionBackend::OpenAndWriteHeader(const FilePath& path) { | 353 net::FileStream* SessionBackend::OpenAndWriteHeader(const FilePath& path) { |
| 354 DCHECK(!path.empty()); | 354 DCHECK(!path.empty()); |
| 355 net::FileStream* file = new net::FileStream(); | 355 scoped_ptr<net::FileStream> file(new net::FileStream()); |
| 356 file->Open(path, base::PLATFORM_FILE_CREATE_ALWAYS | | 356 file->Open(path, base::PLATFORM_FILE_CREATE_ALWAYS | |
| 357 base::PLATFORM_FILE_WRITE | base::PLATFORM_FILE_EXCLUSIVE_WRITE | | 357 base::PLATFORM_FILE_WRITE | base::PLATFORM_FILE_EXCLUSIVE_WRITE | |
| 358 base::PLATFORM_FILE_EXCLUSIVE_READ); | 358 base::PLATFORM_FILE_EXCLUSIVE_READ); |
| 359 if (!file->IsOpen()) | 359 if (!file->IsOpen()) |
| 360 return NULL; | 360 return NULL; |
| 361 int32 header[2]; | 361 int32 header[2]; |
| 362 header[0] = kFileSignature; | 362 header[0] = kFileSignature; |
| 363 header[1] = kFileCurrentVersion; | 363 header[1] = kFileCurrentVersion; |
| 364 int wrote = file->Write(reinterpret_cast<char*>(&header), | 364 int wrote = file->Write(reinterpret_cast<char*>(&header), |
| 365 sizeof(header), NULL); | 365 sizeof(header), NULL); |
| 366 if (wrote != sizeof_header()) | 366 if (wrote != sizeof_header()) |
| 367 return NULL; | 367 return NULL; |
| 368 return file; | 368 return file.release(); |
| 369 } | 369 } |
| 370 | 370 |
| 371 FilePath SessionBackend::GetLastSessionPath() { | 371 FilePath SessionBackend::GetLastSessionPath() { |
| 372 FilePath path = path_to_dir_; | 372 FilePath path = path_to_dir_; |
| 373 if (type_ == BaseSessionService::TAB_RESTORE) | 373 if (type_ == BaseSessionService::TAB_RESTORE) |
| 374 path = path.AppendASCII(kLastTabSessionFileName); | 374 path = path.AppendASCII(kLastTabSessionFileName); |
| 375 else | 375 else |
| 376 path = path.AppendASCII(kLastSessionFileName); | 376 path = path.AppendASCII(kLastSessionFileName); |
| 377 return path; | 377 return path; |
| 378 } | 378 } |
| 379 | 379 |
| 380 FilePath SessionBackend::GetCurrentSessionPath() { | 380 FilePath SessionBackend::GetCurrentSessionPath() { |
| 381 FilePath path = path_to_dir_; | 381 FilePath path = path_to_dir_; |
| 382 if (type_ == BaseSessionService::TAB_RESTORE) | 382 if (type_ == BaseSessionService::TAB_RESTORE) |
| 383 path = path.AppendASCII(kCurrentTabSessionFileName); | 383 path = path.AppendASCII(kCurrentTabSessionFileName); |
| 384 else | 384 else |
| 385 path = path.AppendASCII(kCurrentSessionFileName); | 385 path = path.AppendASCII(kCurrentSessionFileName); |
| 386 return path; | 386 return path; |
| 387 } | 387 } |
| OLD | NEW |