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

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

Issue 10875027: Restart running apps when chrome restarts. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: typo Created 8 years, 3 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/command_line.h" 9 #include "base/command_line.h"
10 #include "base/file_util.h" 10 #include "base/file_util.h"
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 } 195 }
196 196
197 } // namespace 197 } // namespace
198 198
199 // SessionBackend ------------------------------------------------------------- 199 // SessionBackend -------------------------------------------------------------
200 200
201 // File names (current and previous) for a type of TAB. 201 // File names (current and previous) for a type of TAB.
202 static const char* kCurrentTabSessionFileName = "Current Tabs"; 202 static const char* kCurrentTabSessionFileName = "Current Tabs";
203 static const char* kLastTabSessionFileName = "Last Tabs"; 203 static const char* kLastTabSessionFileName = "Last Tabs";
204 204
205 // File names (current and previous) for a type of APP.
206 static const char* kCurrentAppSessionFileName = "Current Apps";
207 static const char* kLastAppSessionFileName = "Last Apps";
208
205 // File names (current and previous) for a type of SESSION. 209 // File names (current and previous) for a type of SESSION.
206 static const char* kCurrentSessionFileName = "Current Session"; 210 static const char* kCurrentSessionFileName = "Current Session";
207 static const char* kLastSessionFileName = "Last Session"; 211 static const char* kLastSessionFileName = "Last Session";
208 212
209 // static 213 // static
210 const int SessionBackend::kFileReadBufferSize = 1024; 214 const int SessionBackend::kFileReadBufferSize = 1024;
211 215
212 SessionBackend::SessionBackend(BaseSessionService::SessionType type, 216 SessionBackend::SessionBackend(BaseSessionService::SessionType type,
213 const FilePath& path_to_dir) 217 const FilePath& path_to_dir)
214 : type_(type), 218 : type_(type),
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
399 sizeof(header)); 403 sizeof(header));
400 if (wrote != sizeof(header)) 404 if (wrote != sizeof(header))
401 return NULL; 405 return NULL;
402 return file.release(); 406 return file.release();
403 } 407 }
404 408
405 FilePath SessionBackend::GetLastSessionPath() { 409 FilePath SessionBackend::GetLastSessionPath() {
406 FilePath path = path_to_dir_; 410 FilePath path = path_to_dir_;
407 if (type_ == BaseSessionService::TAB_RESTORE) 411 if (type_ == BaseSessionService::TAB_RESTORE)
408 path = path.AppendASCII(kLastTabSessionFileName); 412 path = path.AppendASCII(kLastTabSessionFileName);
413 else if (type_ == BaseSessionService::APP_RESTORE)
414 path = path.AppendASCII(kLastAppSessionFileName);
409 else 415 else
410 path = path.AppendASCII(kLastSessionFileName); 416 path = path.AppendASCII(kLastSessionFileName);
411 return path; 417 return path;
412 } 418 }
413 419
414 FilePath SessionBackend::GetCurrentSessionPath() { 420 FilePath SessionBackend::GetCurrentSessionPath() {
415 FilePath path = path_to_dir_; 421 FilePath path = path_to_dir_;
416 if (type_ == BaseSessionService::TAB_RESTORE) 422 if (type_ == BaseSessionService::TAB_RESTORE)
417 path = path.AppendASCII(kCurrentTabSessionFileName); 423 path = path.AppendASCII(kCurrentTabSessionFileName);
424 else if (type_ == BaseSessionService::APP_RESTORE)
425 path = path.AppendASCII(kCurrentAppSessionFileName);
418 else 426 else
419 path = path.AppendASCII(kCurrentSessionFileName); 427 path = path.AppendASCII(kCurrentSessionFileName);
420 return path; 428 return path;
421 } 429 }
422 430
423 void SessionBackend::WriteDebugData() { 431 void SessionBackend::WriteDebugData() {
424 PrefService* prefs = g_browser_process->local_state(); 432 PrefService* prefs = g_browser_process->local_state();
425 if (!prefs) 433 if (!prefs)
426 return; 434 return;
427 ListPrefUpdate update(prefs, prefs::kSessionRestoreFilesCycled); 435 ListPrefUpdate update(prefs, prefs::kSessionRestoreFilesCycled);
428 ListValue* list = update.Get(); 436 ListValue* list = update.Get();
429 while (list->GetSize() > 10) 437 while (list->GetSize() > 10)
430 list->Remove(0, NULL); 438 list->Remove(0, NULL);
431 char time_string[32]; 439 char time_string[32];
432 time_t now = base::Time::Now().ToTimeT(); 440 time_t now = base::Time::Now().ToTimeT();
433 strftime(time_string, 32, "%d.%m.%Y %H:%M:%S", localtime(&now)); 441 strftime(time_string, 32, "%d.%m.%Y %H:%M:%S", localtime(&now));
434 list->Append(new StringValue( 442 list->Append(new StringValue(
435 #if defined(OS_POSIX) 443 #if defined(OS_POSIX)
436 base::IntToString(getpid()) + " " + 444 base::IntToString(getpid()) + " " +
437 #endif 445 #endif
438 std::string(time_string) + " " + 446 std::string(time_string) + " " +
439 #if defined(OS_WIN) 447 #if defined(OS_WIN)
440 WideToUTF8(path_to_dir_.BaseName().value()) + " " + 448 WideToUTF8(path_to_dir_.BaseName().value()) + " " +
441 WideToUTF8(CommandLine::ForCurrentProcess()->GetCommandLineString()))); 449 WideToUTF8(CommandLine::ForCurrentProcess()->GetCommandLineString())));
442 #else 450 #else
443 path_to_dir_.BaseName().value() + " " + 451 path_to_dir_.BaseName().value() + " " +
444 CommandLine::ForCurrentProcess()->GetCommandLineString())); 452 CommandLine::ForCurrentProcess()->GetCommandLineString()));
445 #endif 453 #endif
446 } 454 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698