| OLD | NEW |
| 1 // Copyright (c) 2011 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" |
| 11 #include "base/metrics/histogram.h" | 11 #include "base/metrics/histogram.h" |
| (...skipping 26 matching lines...) Expand all Loading... |
| 38 class SessionFileReader { | 38 class SessionFileReader { |
| 39 public: | 39 public: |
| 40 typedef SessionCommand::id_type id_type; | 40 typedef SessionCommand::id_type id_type; |
| 41 typedef SessionCommand::size_type size_type; | 41 typedef SessionCommand::size_type size_type; |
| 42 | 42 |
| 43 explicit SessionFileReader(const FilePath& path) | 43 explicit SessionFileReader(const FilePath& path) |
| 44 : errored_(false), | 44 : errored_(false), |
| 45 buffer_(SessionBackend::kFileReadBufferSize, 0), | 45 buffer_(SessionBackend::kFileReadBufferSize, 0), |
| 46 buffer_position_(0), | 46 buffer_position_(0), |
| 47 available_count_(0) { | 47 available_count_(0) { |
| 48 file_.reset(new net::FileStream()); | 48 file_.reset(new net::FileStream(NULL)); |
| 49 if (file_util::PathExists(path)) | 49 if (file_util::PathExists(path)) |
| 50 file_->Open(path, base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_READ); | 50 file_->Open(path, base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_READ); |
| 51 } | 51 } |
| 52 // Reads the contents of the file specified in the constructor, returning | 52 // Reads the contents of the file specified in the constructor, returning |
| 53 // true on success. It is up to the caller to free all SessionCommands | 53 // true on success. It is up to the caller to free all SessionCommands |
| 54 // added to commands. | 54 // added to commands. |
| 55 bool Read(BaseSessionService::SessionType type, | 55 bool Read(BaseSessionService::SessionType type, |
| 56 std::vector<SessionCommand*>* commands); | 56 std::vector<SessionCommand*>* commands); |
| 57 | 57 |
| 58 private: | 58 private: |
| (...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 356 if (current_session_file_->Truncate(header_size) != header_size) | 356 if (current_session_file_->Truncate(header_size) != header_size) |
| 357 current_session_file_.reset(NULL); | 357 current_session_file_.reset(NULL); |
| 358 } | 358 } |
| 359 if (!current_session_file_.get()) | 359 if (!current_session_file_.get()) |
| 360 current_session_file_.reset(OpenAndWriteHeader(GetCurrentSessionPath())); | 360 current_session_file_.reset(OpenAndWriteHeader(GetCurrentSessionPath())); |
| 361 empty_file_ = true; | 361 empty_file_ = true; |
| 362 } | 362 } |
| 363 | 363 |
| 364 net::FileStream* SessionBackend::OpenAndWriteHeader(const FilePath& path) { | 364 net::FileStream* SessionBackend::OpenAndWriteHeader(const FilePath& path) { |
| 365 DCHECK(!path.empty()); | 365 DCHECK(!path.empty()); |
| 366 scoped_ptr<net::FileStream> file(new net::FileStream()); | 366 scoped_ptr<net::FileStream> file(new net::FileStream(NULL)); |
| 367 if (file->Open(path, base::PLATFORM_FILE_CREATE_ALWAYS | | 367 if (file->Open(path, base::PLATFORM_FILE_CREATE_ALWAYS | |
| 368 base::PLATFORM_FILE_WRITE | base::PLATFORM_FILE_EXCLUSIVE_WRITE | | 368 base::PLATFORM_FILE_WRITE | base::PLATFORM_FILE_EXCLUSIVE_WRITE | |
| 369 base::PLATFORM_FILE_EXCLUSIVE_READ) != net::OK) | 369 base::PLATFORM_FILE_EXCLUSIVE_READ) != net::OK) |
| 370 return NULL; | 370 return NULL; |
| 371 FileHeader header; | 371 FileHeader header; |
| 372 header.signature = kFileSignature; | 372 header.signature = kFileSignature; |
| 373 header.version = kFileCurrentVersion; | 373 header.version = kFileCurrentVersion; |
| 374 int wrote = file->Write(reinterpret_cast<char*>(&header), | 374 int wrote = file->Write(reinterpret_cast<char*>(&header), |
| 375 sizeof(header), net::CompletionCallback()); | 375 sizeof(header), net::CompletionCallback()); |
| 376 if (wrote != sizeof(header)) | 376 if (wrote != sizeof(header)) |
| (...skipping 11 matching lines...) Expand all Loading... |
| 388 } | 388 } |
| 389 | 389 |
| 390 FilePath SessionBackend::GetCurrentSessionPath() { | 390 FilePath SessionBackend::GetCurrentSessionPath() { |
| 391 FilePath path = path_to_dir_; | 391 FilePath path = path_to_dir_; |
| 392 if (type_ == BaseSessionService::TAB_RESTORE) | 392 if (type_ == BaseSessionService::TAB_RESTORE) |
| 393 path = path.AppendASCII(kCurrentTabSessionFileName); | 393 path = path.AppendASCII(kCurrentTabSessionFileName); |
| 394 else | 394 else |
| 395 path = path.AppendASCII(kCurrentSessionFileName); | 395 path = path.AppendASCII(kCurrentSessionFileName); |
| 396 return path; | 396 return path; |
| 397 } | 397 } |
| OLD | NEW |