Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(45)

Side by Side Diff: chrome/browser/sessions/session_backend.cc

Issue 18286004: Move PathExists to base namespace. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 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"
(...skipping 29 matching lines...) Expand all
40 public: 40 public:
41 typedef SessionCommand::id_type id_type; 41 typedef SessionCommand::id_type id_type;
42 typedef SessionCommand::size_type size_type; 42 typedef SessionCommand::size_type size_type;
43 43
44 explicit SessionFileReader(const base::FilePath& path) 44 explicit SessionFileReader(const base::FilePath& path)
45 : errored_(false), 45 : errored_(false),
46 buffer_(SessionBackend::kFileReadBufferSize, 0), 46 buffer_(SessionBackend::kFileReadBufferSize, 0),
47 buffer_position_(0), 47 buffer_position_(0),
48 available_count_(0) { 48 available_count_(0) {
49 file_.reset(new net::FileStream(NULL)); 49 file_.reset(new net::FileStream(NULL));
50 if (file_util::PathExists(path)) 50 if (base::PathExists(path))
51 file_->OpenSync(path, 51 file_->OpenSync(path,
52 base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_READ); 52 base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_READ);
53 } 53 }
54 // Reads the contents of the file specified in the constructor, returning 54 // Reads the contents of the file specified in the constructor, returning
55 // true on success. It is up to the caller to free all SessionCommands 55 // true on success. It is up to the caller to free all SessionCommands
56 // added to commands. 56 // added to commands.
57 bool Read(BaseSessionService::SessionType type, 57 bool Read(BaseSessionService::SessionType type,
58 std::vector<SessionCommand*>* commands); 58 std::vector<SessionCommand*>* commands);
59 59
60 private: 60 private:
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
267 Init(); 267 Init();
268 base::Delete(GetLastSessionPath(), false); 268 base::Delete(GetLastSessionPath(), false);
269 } 269 }
270 270
271 void SessionBackend::MoveCurrentSessionToLastSession() { 271 void SessionBackend::MoveCurrentSessionToLastSession() {
272 Init(); 272 Init();
273 current_session_file_.reset(NULL); 273 current_session_file_.reset(NULL);
274 274
275 const base::FilePath current_session_path = GetCurrentSessionPath(); 275 const base::FilePath current_session_path = GetCurrentSessionPath();
276 const base::FilePath last_session_path = GetLastSessionPath(); 276 const base::FilePath last_session_path = GetLastSessionPath();
277 if (file_util::PathExists(last_session_path)) 277 if (base::PathExists(last_session_path))
278 base::Delete(last_session_path, false); 278 base::Delete(last_session_path, false);
279 if (file_util::PathExists(current_session_path)) { 279 if (base::PathExists(current_session_path)) {
280 int64 file_size; 280 int64 file_size;
281 if (file_util::GetFileSize(current_session_path, &file_size)) { 281 if (file_util::GetFileSize(current_session_path, &file_size)) {
282 if (type_ == BaseSessionService::TAB_RESTORE) { 282 if (type_ == BaseSessionService::TAB_RESTORE) {
283 UMA_HISTOGRAM_COUNTS("TabRestore.last_session_file_size", 283 UMA_HISTOGRAM_COUNTS("TabRestore.last_session_file_size",
284 static_cast<int>(file_size / 1024)); 284 static_cast<int>(file_size / 1024));
285 } else { 285 } else {
286 UMA_HISTOGRAM_COUNTS("SessionRestore.last_session_file_size", 286 UMA_HISTOGRAM_COUNTS("SessionRestore.last_session_file_size",
287 static_cast<int>(file_size / 1024)); 287 static_cast<int>(file_size / 1024));
288 } 288 }
289 } 289 }
290 last_session_valid_ = base::Move(current_session_path, last_session_path); 290 last_session_valid_ = base::Move(current_session_path, last_session_path);
291 } 291 }
292 292
293 if (file_util::PathExists(current_session_path)) 293 if (base::PathExists(current_session_path))
294 base::Delete(current_session_path, false); 294 base::Delete(current_session_path, false);
295 295
296 // Create and open the file for the current session. 296 // Create and open the file for the current session.
297 ResetFile(); 297 ResetFile();
298 } 298 }
299 299
300 bool SessionBackend::ReadCurrentSessionCommandsImpl( 300 bool SessionBackend::ReadCurrentSessionCommandsImpl(
301 std::vector<SessionCommand*>* commands) { 301 std::vector<SessionCommand*>* commands) {
302 Init(); 302 Init();
303 SessionFileReader file_reader(GetCurrentSessionPath()); 303 SessionFileReader file_reader(GetCurrentSessionPath());
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
398 } 398 }
399 399
400 base::FilePath SessionBackend::GetCurrentSessionPath() { 400 base::FilePath SessionBackend::GetCurrentSessionPath() {
401 base::FilePath path = path_to_dir_; 401 base::FilePath path = path_to_dir_;
402 if (type_ == BaseSessionService::TAB_RESTORE) 402 if (type_ == BaseSessionService::TAB_RESTORE)
403 path = path.AppendASCII(kCurrentTabSessionFileName); 403 path = path.AppendASCII(kCurrentTabSessionFileName);
404 else 404 else
405 path = path.AppendASCII(kCurrentSessionFileName); 405 path = path.AppendASCII(kCurrentSessionFileName);
406 return path; 406 return path;
407 } 407 }
OLDNEW
« no previous file with comments | « chrome/browser/search_engines/template_url_parser_unittest.cc ('k') | chrome/browser/shell_integration.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698