OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 header[1] != kFileCurrentVersion) | 90 header[1] != kFileCurrentVersion) |
91 return false; | 91 return false; |
92 | 92 |
93 ScopedVector<SessionCommand> read_commands; | 93 ScopedVector<SessionCommand> read_commands; |
94 SessionCommand* command; | 94 SessionCommand* command; |
95 while ((command = ReadCommand()) && !errored_) | 95 while ((command = ReadCommand()) && !errored_) |
96 read_commands->push_back(command); | 96 read_commands->push_back(command); |
97 if (!errored_) | 97 if (!errored_) |
98 read_commands->swap(*commands); | 98 read_commands->swap(*commands); |
99 if (type == BaseSessionService::TAB_RESTORE) { | 99 if (type == BaseSessionService::TAB_RESTORE) { |
100 UMA_HISTOGRAM_TIMES(L"TabRestore.read_session_file_time", | 100 UMA_HISTOGRAM_TIMES("TabRestore.read_session_file_time", |
101 TimeTicks::Now() - start_time); | 101 TimeTicks::Now() - start_time); |
102 } else { | 102 } else { |
103 UMA_HISTOGRAM_TIMES(L"SessionRestore.read_session_file_time", | 103 UMA_HISTOGRAM_TIMES("SessionRestore.read_session_file_time", |
104 TimeTicks::Now() - start_time); | 104 TimeTicks::Now() - start_time); |
105 } | 105 } |
106 return !errored_; | 106 return !errored_; |
107 } | 107 } |
108 | 108 |
109 SessionCommand* SessionFileReader::ReadCommand() { | 109 SessionCommand* SessionFileReader::ReadCommand() { |
110 // Make sure there is enough in the buffer for the size of the next command. | 110 // Make sure there is enough in the buffer for the size of the next command. |
111 if (available_count_ < sizeof(size_type)) { | 111 if (available_count_ < sizeof(size_type)) { |
112 if (!FillBuffer()) | 112 if (!FillBuffer()) |
113 return NULL; | 113 return NULL; |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
252 current_session_file_.reset(NULL); | 252 current_session_file_.reset(NULL); |
253 | 253 |
254 const FilePath current_session_path = GetCurrentSessionPath(); | 254 const FilePath current_session_path = GetCurrentSessionPath(); |
255 const FilePath last_session_path = GetLastSessionPath(); | 255 const FilePath last_session_path = GetLastSessionPath(); |
256 if (file_util::PathExists(last_session_path)) | 256 if (file_util::PathExists(last_session_path)) |
257 file_util::Delete(last_session_path, false); | 257 file_util::Delete(last_session_path, false); |
258 if (file_util::PathExists(current_session_path)) { | 258 if (file_util::PathExists(current_session_path)) { |
259 int64 file_size; | 259 int64 file_size; |
260 if (file_util::GetFileSize(current_session_path, &file_size)) { | 260 if (file_util::GetFileSize(current_session_path, &file_size)) { |
261 if (type_ == BaseSessionService::TAB_RESTORE) { | 261 if (type_ == BaseSessionService::TAB_RESTORE) { |
262 UMA_HISTOGRAM_COUNTS(L"TabRestore.last_session_file_size", | 262 UMA_HISTOGRAM_COUNTS("TabRestore.last_session_file_size", |
263 static_cast<int>(file_size / 1024)); | 263 static_cast<int>(file_size / 1024)); |
264 } else { | 264 } else { |
265 UMA_HISTOGRAM_COUNTS(L"SessionRestore.last_session_file_size", | 265 UMA_HISTOGRAM_COUNTS("SessionRestore.last_session_file_size", |
266 static_cast<int>(file_size / 1024)); | 266 static_cast<int>(file_size / 1024)); |
267 } | 267 } |
268 } | 268 } |
269 last_session_valid_ = file_util::Move(current_session_path, | 269 last_session_valid_ = file_util::Move(current_session_path, |
270 last_session_path); | 270 last_session_path); |
271 } | 271 } |
272 | 272 |
273 if (file_util::PathExists(current_session_path)) | 273 if (file_util::PathExists(current_session_path)) |
274 file_util::Delete(current_session_path, false); | 274 file_util::Delete(current_session_path, false); |
275 | 275 |
276 // Create and open the file for the current session. | 276 // Create and open the file for the current session. |
277 ResetFile(); | 277 ResetFile(); |
278 } | 278 } |
279 | 279 |
280 bool SessionBackend::AppendCommandsToFile(net::FileStream* file, | 280 bool SessionBackend::AppendCommandsToFile(net::FileStream* file, |
281 const std::vector<SessionCommand*>& commands) { | 281 const std::vector<SessionCommand*>& commands) { |
282 for (std::vector<SessionCommand*>::const_iterator i = commands.begin(); | 282 for (std::vector<SessionCommand*>::const_iterator i = commands.begin(); |
283 i != commands.end(); ++i) { | 283 i != commands.end(); ++i) { |
284 int wrote; | 284 int wrote; |
285 const size_type content_size = static_cast<size_type>((*i)->size()); | 285 const size_type content_size = static_cast<size_type>((*i)->size()); |
286 const size_type total_size = content_size + sizeof(id_type); | 286 const size_type total_size = content_size + sizeof(id_type); |
287 if (type_ == BaseSessionService::TAB_RESTORE) | 287 if (type_ == BaseSessionService::TAB_RESTORE) |
288 UMA_HISTOGRAM_COUNTS(L"TabRestore.command_size", total_size); | 288 UMA_HISTOGRAM_COUNTS("TabRestore.command_size", total_size); |
289 else | 289 else |
290 UMA_HISTOGRAM_COUNTS(L"SessionRestore.command_size", total_size); | 290 UMA_HISTOGRAM_COUNTS("SessionRestore.command_size", total_size); |
291 wrote = file->Write(reinterpret_cast<const char*>(&total_size), | 291 wrote = file->Write(reinterpret_cast<const char*>(&total_size), |
292 sizeof(total_size), NULL); | 292 sizeof(total_size), NULL); |
293 if (wrote != sizeof(total_size)) { | 293 if (wrote != sizeof(total_size)) { |
294 NOTREACHED() << "error writing"; | 294 NOTREACHED() << "error writing"; |
295 return false; | 295 return false; |
296 } | 296 } |
297 id_type command_id = (*i)->id(); | 297 id_type command_id = (*i)->id(); |
298 wrote = file->Write(reinterpret_cast<char*>(&command_id), | 298 wrote = file->Write(reinterpret_cast<char*>(&command_id), |
299 sizeof(command_id), NULL); | 299 sizeof(command_id), NULL); |
300 if (wrote != sizeof(command_id)) { | 300 if (wrote != sizeof(command_id)) { |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
344 } | 344 } |
345 | 345 |
346 FilePath SessionBackend::GetCurrentSessionPath() { | 346 FilePath SessionBackend::GetCurrentSessionPath() { |
347 FilePath path = path_to_dir_; | 347 FilePath path = path_to_dir_; |
348 if (type_ == BaseSessionService::TAB_RESTORE) | 348 if (type_ == BaseSessionService::TAB_RESTORE) |
349 path = path.AppendASCII(kCurrentTabSessionFileName); | 349 path = path.AppendASCII(kCurrentTabSessionFileName); |
350 else | 350 else |
351 path = path.AppendASCII(kCurrentSessionFileName); | 351 path = path.AppendASCII(kCurrentSessionFileName); |
352 return path; | 352 return path; |
353 } | 353 } |
OLD | NEW |