| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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 "components/sessions/core/session_backend.h" | 5 #include "components/sessions/core/session_backend.h" |
| 6 | 6 |
| 7 #include <stdint.h> |
| 8 |
| 7 #include <limits> | 9 #include <limits> |
| 8 | 10 |
| 9 #include "base/files/file.h" | 11 #include "base/files/file.h" |
| 10 #include "base/files/file_util.h" | 12 #include "base/files/file_util.h" |
| 13 #include "base/macros.h" |
| 11 #include "base/memory/scoped_vector.h" | 14 #include "base/memory/scoped_vector.h" |
| 12 #include "base/metrics/histogram.h" | 15 #include "base/metrics/histogram.h" |
| 13 #include "base/threading/thread_restrictions.h" | 16 #include "base/threading/thread_restrictions.h" |
| 17 #include "build/build_config.h" |
| 14 | 18 |
| 15 using base::TimeTicks; | 19 using base::TimeTicks; |
| 16 | 20 |
| 17 namespace sessions { | 21 namespace sessions { |
| 18 | 22 |
| 19 // File version number. | 23 // File version number. |
| 20 static const int32 kFileCurrentVersion = 1; | 24 static const int32_t kFileCurrentVersion = 1; |
| 21 | 25 |
| 22 // The signature at the beginning of the file = SSNS (Sessions). | 26 // The signature at the beginning of the file = SSNS (Sessions). |
| 23 static const int32 kFileSignature = 0x53534E53; | 27 static const int32_t kFileSignature = 0x53534E53; |
| 24 | 28 |
| 25 namespace { | 29 namespace { |
| 26 | 30 |
| 27 // The file header is the first bytes written to the file, | 31 // The file header is the first bytes written to the file, |
| 28 // and is used to identify the file as one written by us. | 32 // and is used to identify the file as one written by us. |
| 29 struct FileHeader { | 33 struct FileHeader { |
| 30 int32 signature; | 34 int32_t signature; |
| 31 int32 version; | 35 int32_t version; |
| 32 }; | 36 }; |
| 33 | 37 |
| 34 // SessionFileReader ---------------------------------------------------------- | 38 // SessionFileReader ---------------------------------------------------------- |
| 35 | 39 |
| 36 // SessionFileReader is responsible for reading the set of SessionCommands that | 40 // SessionFileReader is responsible for reading the set of SessionCommands that |
| 37 // describe a Session back from a file. SessionFileRead does minimal error | 41 // describe a Session back from a file. SessionFileRead does minimal error |
| 38 // checking on the file (pretty much only that the header is valid). | 42 // checking on the file (pretty much only that the header is valid). |
| 39 | 43 |
| 40 class SessionFileReader { | 44 class SessionFileReader { |
| 41 public: | 45 public: |
| (...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 267 | 271 |
| 268 void SessionBackend::MoveCurrentSessionToLastSession() { | 272 void SessionBackend::MoveCurrentSessionToLastSession() { |
| 269 Init(); | 273 Init(); |
| 270 current_session_file_.reset(NULL); | 274 current_session_file_.reset(NULL); |
| 271 | 275 |
| 272 const base::FilePath current_session_path = GetCurrentSessionPath(); | 276 const base::FilePath current_session_path = GetCurrentSessionPath(); |
| 273 const base::FilePath last_session_path = GetLastSessionPath(); | 277 const base::FilePath last_session_path = GetLastSessionPath(); |
| 274 if (base::PathExists(last_session_path)) | 278 if (base::PathExists(last_session_path)) |
| 275 base::DeleteFile(last_session_path, false); | 279 base::DeleteFile(last_session_path, false); |
| 276 if (base::PathExists(current_session_path)) { | 280 if (base::PathExists(current_session_path)) { |
| 277 int64 file_size; | 281 int64_t file_size; |
| 278 if (base::GetFileSize(current_session_path, &file_size)) { | 282 if (base::GetFileSize(current_session_path, &file_size)) { |
| 279 if (type_ == sessions::BaseSessionService::TAB_RESTORE) { | 283 if (type_ == sessions::BaseSessionService::TAB_RESTORE) { |
| 280 UMA_HISTOGRAM_COUNTS("TabRestore.last_session_file_size", | 284 UMA_HISTOGRAM_COUNTS("TabRestore.last_session_file_size", |
| 281 static_cast<int>(file_size / 1024)); | 285 static_cast<int>(file_size / 1024)); |
| 282 } else { | 286 } else { |
| 283 UMA_HISTOGRAM_COUNTS("SessionRestore.last_session_file_size", | 287 UMA_HISTOGRAM_COUNTS("SessionRestore.last_session_file_size", |
| 284 static_cast<int>(file_size / 1024)); | 288 static_cast<int>(file_size / 1024)); |
| 285 } | 289 } |
| 286 } | 290 } |
| 287 last_session_valid_ = base::Move(current_session_path, last_session_path); | 291 last_session_valid_ = base::Move(current_session_path, last_session_path); |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 398 base::FilePath SessionBackend::GetCurrentSessionPath() { | 402 base::FilePath SessionBackend::GetCurrentSessionPath() { |
| 399 base::FilePath path = path_to_dir_; | 403 base::FilePath path = path_to_dir_; |
| 400 if (type_ == sessions::BaseSessionService::TAB_RESTORE) | 404 if (type_ == sessions::BaseSessionService::TAB_RESTORE) |
| 401 path = path.AppendASCII(kCurrentTabSessionFileName); | 405 path = path.AppendASCII(kCurrentTabSessionFileName); |
| 402 else | 406 else |
| 403 path = path.AppendASCII(kCurrentSessionFileName); | 407 path = path.AppendASCII(kCurrentSessionFileName); |
| 404 return path; | 408 return path; |
| 405 } | 409 } |
| 406 | 410 |
| 407 } // namespace sessions | 411 } // namespace sessions |
| OLD | NEW |