Chromium Code Reviews| 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/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
| (...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 358 current_session_file_.reset(NULL); | 358 current_session_file_.reset(NULL); |
| 359 } | 359 } |
| 360 if (!current_session_file_.get()) | 360 if (!current_session_file_.get()) |
| 361 current_session_file_.reset(OpenAndWriteHeader(GetCurrentSessionPath())); | 361 current_session_file_.reset(OpenAndWriteHeader(GetCurrentSessionPath())); |
| 362 empty_file_ = true; | 362 empty_file_ = true; |
| 363 } | 363 } |
| 364 | 364 |
| 365 net::FileStream* SessionBackend::OpenAndWriteHeader(const FilePath& path) { | 365 net::FileStream* SessionBackend::OpenAndWriteHeader(const FilePath& path) { |
| 366 DCHECK(!path.empty()); | 366 DCHECK(!path.empty()); |
| 367 scoped_ptr<net::FileStream> file(new net::FileStream()); | 367 scoped_ptr<net::FileStream> file(new net::FileStream()); |
| 368 file->Open(path, base::PLATFORM_FILE_CREATE_ALWAYS | | 368 if(file->Open(path, base::PLATFORM_FILE_CREATE_ALWAYS | |
| 369 base::PLATFORM_FILE_WRITE | base::PLATFORM_FILE_EXCLUSIVE_WRITE | | 369 base::PLATFORM_FILE_WRITE | base::PLATFORM_FILE_EXCLUSIVE_WRITE | |
| 370 base::PLATFORM_FILE_EXCLUSIVE_READ); | 370 base::PLATFORM_FILE_EXCLUSIVE_READ) != 0) |
|
Lei Zhang
2011/03/11 01:09:35
don't check for 0, check for OK.
Sheridan Rawlins
2011/03/11 01:39:49
Done.
| |
| 371 if (!file->IsOpen()) | |
| 372 return NULL; | 371 return NULL; |
| 373 FileHeader header; | 372 FileHeader header; |
| 374 header.signature = kFileSignature; | 373 header.signature = kFileSignature; |
| 375 header.version = kFileCurrentVersion; | 374 header.version = kFileCurrentVersion; |
| 376 int wrote = file->Write(reinterpret_cast<char*>(&header), | 375 int wrote = file->Write(reinterpret_cast<char*>(&header), |
| 377 sizeof(header), NULL); | 376 sizeof(header), NULL); |
| 378 if (wrote != sizeof(header)) | 377 if (wrote != sizeof(header)) |
| 379 return NULL; | 378 return NULL; |
| 380 return file.release(); | 379 return file.release(); |
| 381 } | 380 } |
| 382 | 381 |
| 383 FilePath SessionBackend::GetLastSessionPath() { | 382 FilePath SessionBackend::GetLastSessionPath() { |
| 384 FilePath path = path_to_dir_; | 383 FilePath path = path_to_dir_; |
| 385 if (type_ == BaseSessionService::TAB_RESTORE) | 384 if (type_ == BaseSessionService::TAB_RESTORE) |
| 386 path = path.AppendASCII(kLastTabSessionFileName); | 385 path = path.AppendASCII(kLastTabSessionFileName); |
| 387 else | 386 else |
| 388 path = path.AppendASCII(kLastSessionFileName); | 387 path = path.AppendASCII(kLastSessionFileName); |
| 389 return path; | 388 return path; |
| 390 } | 389 } |
| 391 | 390 |
| 392 FilePath SessionBackend::GetCurrentSessionPath() { | 391 FilePath SessionBackend::GetCurrentSessionPath() { |
| 393 FilePath path = path_to_dir_; | 392 FilePath path = path_to_dir_; |
| 394 if (type_ == BaseSessionService::TAB_RESTORE) | 393 if (type_ == BaseSessionService::TAB_RESTORE) |
| 395 path = path.AppendASCII(kCurrentTabSessionFileName); | 394 path = path.AppendASCII(kCurrentTabSessionFileName); |
| 396 else | 395 else |
| 397 path = path.AppendASCII(kCurrentSessionFileName); | 396 path = path.AppendASCII(kCurrentSessionFileName); |
| 398 return path; | 397 return path; |
| 399 } | 398 } |
| OLD | NEW |