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" |
| 11 #include "base/scoped_vector.h" | 11 #include "base/scoped_vector.h" |
| 12 #include "net/base/file_stream.h" | 12 #include "net/base/file_stream.h" |
| 13 #include "net/base/net_errors.h" | |
| 13 | 14 |
| 14 using base::TimeTicks; | 15 using base::TimeTicks; |
| 15 | 16 |
| 16 // File version number. | 17 // File version number. |
| 17 static const int32 kFileCurrentVersion = 1; | 18 static const int32 kFileCurrentVersion = 1; |
| 18 | 19 |
| 19 // The signature at the beginning of the file = SSNS (Sessions). | 20 // The signature at the beginning of the file = SSNS (Sessions). |
| 20 static const int32 kFileSignature = 0x53534E53; | 21 static const int32 kFileSignature = 0x53534E53; |
| 21 | 22 |
| 22 namespace { | 23 namespace { |
| (...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 358 current_session_file_.reset(NULL); | 359 current_session_file_.reset(NULL); |
| 359 } | 360 } |
| 360 if (!current_session_file_.get()) | 361 if (!current_session_file_.get()) |
| 361 current_session_file_.reset(OpenAndWriteHeader(GetCurrentSessionPath())); | 362 current_session_file_.reset(OpenAndWriteHeader(GetCurrentSessionPath())); |
| 362 empty_file_ = true; | 363 empty_file_ = true; |
| 363 } | 364 } |
| 364 | 365 |
| 365 net::FileStream* SessionBackend::OpenAndWriteHeader(const FilePath& path) { | 366 net::FileStream* SessionBackend::OpenAndWriteHeader(const FilePath& path) { |
| 366 DCHECK(!path.empty()); | 367 DCHECK(!path.empty()); |
| 367 scoped_ptr<net::FileStream> file(new net::FileStream()); | 368 scoped_ptr<net::FileStream> file(new net::FileStream()); |
| 368 file->Open(path, base::PLATFORM_FILE_CREATE_ALWAYS | | 369 if(file->Open(path, base::PLATFORM_FILE_CREATE_ALWAYS | |
|
Lei Zhang
2011/03/11 01:45:11
nit: "if(" -> "if ("
Sheridan Rawlins
2011/03/11 01:49:59
Done.
| |
| 369 base::PLATFORM_FILE_WRITE | base::PLATFORM_FILE_EXCLUSIVE_WRITE | | 370 base::PLATFORM_FILE_WRITE | base::PLATFORM_FILE_EXCLUSIVE_WRITE | |
| 370 base::PLATFORM_FILE_EXCLUSIVE_READ); | 371 base::PLATFORM_FILE_EXCLUSIVE_READ) != net::OK) |
| 371 if (!file->IsOpen()) | |
| 372 return NULL; | 372 return NULL; |
| 373 FileHeader header; | 373 FileHeader header; |
| 374 header.signature = kFileSignature; | 374 header.signature = kFileSignature; |
| 375 header.version = kFileCurrentVersion; | 375 header.version = kFileCurrentVersion; |
| 376 int wrote = file->Write(reinterpret_cast<char*>(&header), | 376 int wrote = file->Write(reinterpret_cast<char*>(&header), |
| 377 sizeof(header), NULL); | 377 sizeof(header), NULL); |
| 378 if (wrote != sizeof(header)) | 378 if (wrote != sizeof(header)) |
| 379 return NULL; | 379 return NULL; |
| 380 return file.release(); | 380 return file.release(); |
| 381 } | 381 } |
| 382 | 382 |
| 383 FilePath SessionBackend::GetLastSessionPath() { | 383 FilePath SessionBackend::GetLastSessionPath() { |
| 384 FilePath path = path_to_dir_; | 384 FilePath path = path_to_dir_; |
| 385 if (type_ == BaseSessionService::TAB_RESTORE) | 385 if (type_ == BaseSessionService::TAB_RESTORE) |
| 386 path = path.AppendASCII(kLastTabSessionFileName); | 386 path = path.AppendASCII(kLastTabSessionFileName); |
| 387 else | 387 else |
| 388 path = path.AppendASCII(kLastSessionFileName); | 388 path = path.AppendASCII(kLastSessionFileName); |
| 389 return path; | 389 return path; |
| 390 } | 390 } |
| 391 | 391 |
| 392 FilePath SessionBackend::GetCurrentSessionPath() { | 392 FilePath SessionBackend::GetCurrentSessionPath() { |
| 393 FilePath path = path_to_dir_; | 393 FilePath path = path_to_dir_; |
| 394 if (type_ == BaseSessionService::TAB_RESTORE) | 394 if (type_ == BaseSessionService::TAB_RESTORE) |
| 395 path = path.AppendASCII(kCurrentTabSessionFileName); | 395 path = path.AppendASCII(kCurrentTabSessionFileName); |
| 396 else | 396 else |
| 397 path = path.AppendASCII(kCurrentSessionFileName); | 397 path = path.AppendASCII(kCurrentSessionFileName); |
| 398 return path; | 398 return path; |
| 399 } | 399 } |
| OLD | NEW |