diff options
-rw-r--r-- | chrome/browser/browser_main.cc | 12 | ||||
-rw-r--r-- | chrome/browser/chromeos/login/login_utils.cc | 4 | ||||
-rw-r--r-- | chrome/common/env_vars.cc | 3 | ||||
-rw-r--r-- | chrome/common/env_vars.h | 1 | ||||
-rw-r--r-- | chrome/common/logging_chrome.cc | 38 | ||||
-rw-r--r-- | chrome/common/logging_chrome.h | 7 | ||||
-rw-r--r-- | chrome/test/in_process_browser_test.cc | 5 |
7 files changed, 49 insertions, 21 deletions
diff --git a/chrome/browser/browser_main.cc b/chrome/browser/browser_main.cc index f22a6ed..9e33f68 100644 --- a/chrome/browser/browser_main.cc +++ b/chrome/browser/browser_main.cc @@ -1223,16 +1223,8 @@ int BrowserMain(const MainFunctionParams& parameters) { VLOG(1) << "Relaunching browser for user: " << username; chromeos::UserManager::Get()->UserLoggedIn(username); - // Redirect logs. - FilePath user_data_dir; - PathService::Get(chrome::DIR_USER_DATA, &user_data_dir); - ProfileManager* profile_manager = g_browser_process->profile_manager(); - // The default profile will have been changed because the ProfileManager - // will process the notification that the UserManager sends out. - - logging::RedirectChromeLogging( - user_data_dir.Append(profile_manager->GetCurrentProfileDir()), - *(CommandLine::ForCurrentProcess())); + // Redirects Chrome logging to the user data dir. + logging::RedirectChromeLogging(parsed_command_line); } #endif diff --git a/chrome/browser/chromeos/login/login_utils.cc b/chrome/browser/chromeos/login/login_utils.cc index f872733..8136645 100644 --- a/chrome/browser/chromeos/login/login_utils.cc +++ b/chrome/browser/chromeos/login/login_utils.cc @@ -143,9 +143,7 @@ void LoginUtilsImpl::CompleteLogin( ProfileManager* profile_manager = g_browser_process->profile_manager(); // Switch log file as soon as possible. - logging::RedirectChromeLogging( - user_data_dir.Append(profile_manager->GetCurrentProfileDir()), - *(CommandLine::ForCurrentProcess())); + logging::RedirectChromeLogging(*(CommandLine::ForCurrentProcess())); btl->AddLoginTimeMarker("LoggingRedirected", false); // The default profile will have been changed because the ProfileManager diff --git a/chrome/common/env_vars.cc b/chrome/common/env_vars.cc index dc2648c..f63d3e4 100644 --- a/chrome/common/env_vars.cc +++ b/chrome/common/env_vars.cc @@ -14,6 +14,9 @@ const char kHeadless[] = "CHROME_HEADLESS"; // The name of the log file. const char kLogFileName[] = "CHROME_LOG_FILE"; +// The name of the session log directory when logged in to ChromeOS. +const char kSessionLogDir[] = "CHROMEOS_SESSION_LOG_DIR"; + // If this environment variable is set, Chrome on Windows will log // to Event Tracing for Windows. const char kEtwLogging[] = "CHROME_ETW_LOGGING"; diff --git a/chrome/common/env_vars.h b/chrome/common/env_vars.h index e9984d2a..320a0b4 100644 --- a/chrome/common/env_vars.h +++ b/chrome/common/env_vars.h @@ -12,6 +12,7 @@ namespace env_vars { extern const char kHeadless[]; extern const char kLogFileName[]; +extern const char kSessionLogDir[]; extern const char kEtwLogging[]; extern const char kShowRestart[]; extern const char kRestartInfo[]; diff --git a/chrome/common/logging_chrome.cc b/chrome/common/logging_chrome.cc index 6106e43..48bcc37 100644 --- a/chrome/common/logging_chrome.cc +++ b/chrome/common/logging_chrome.cc @@ -158,12 +158,13 @@ FilePath SetUpSymlinkIfNeeded(const FilePath& symlink_path, bool new_log) { // starting a new log, then delete the old symlink and make a new // one to a fresh log file. FilePath target_path; - if (new_log || !file_util::PathExists(symlink_path)) { + bool symlink_exists = file_util::PathExists(symlink_path); + if (new_log || !symlink_exists) { target_path = GenerateTimestampedName(symlink_path, base::Time::Now()); // We don't care if the unlink fails; we're going to continue anyway. if (unlink(symlink_path.value().c_str()) == -1) { - if (new_log) // only warn if we might expect it to succeed. + if (symlink_exists) // only warn if we might expect it to succeed. PLOG(WARNING) << "Unable to unlink " << symlink_path.value(); } if (symlink(target_path.value().c_str(), @@ -193,12 +194,29 @@ void RemoveSymlinkAndLog(const FilePath& link_path, } // anonymous namespace -void RedirectChromeLogging(const FilePath& new_log_dir, - const CommandLine& command_line) { +FilePath GetSessionLogFile(const CommandLine& command_line) { + FilePath log_dir; + std::string log_dir_str; + scoped_ptr<base::Environment> env(base::Environment::Create()); + if (env->GetVar(env_vars::kSessionLogDir, &log_dir_str) && + !log_dir_str.empty()) { + log_dir = FilePath(log_dir_str); + } else { + PathService::Get(chrome::DIR_USER_DATA, &log_dir); + FilePath login_profile = + command_line.GetSwitchValuePath(switches::kLoginProfile); + log_dir = log_dir.Append(login_profile); + } + return log_dir.Append(GetLogFileName().BaseName()); +} + +void RedirectChromeLogging(const CommandLine& command_line) { DCHECK(!chrome_logging_redirected_) << "Attempted to redirect logging when it was already initialized."; - FilePath orig_log_path = GetLogFileName(); - FilePath log_path = new_log_dir.Append(orig_log_path.BaseName()); + + // Redirect logs to the session log directory, if set. Otherwise + // defaults to the profile dir. + FilePath log_path = GetSessionLogFile(command_line); // Always force a new symlink when redirecting. FilePath target_path = SetUpSymlinkIfNeeded(log_path, true); @@ -215,6 +233,8 @@ void RedirectChromeLogging(const FilePath& new_log_dir, chrome_logging_redirected_ = true; } } + + #endif void InitChromeLogging(const CommandLine& command_line, @@ -229,6 +249,12 @@ void InitChromeLogging(const CommandLine& command_line, FilePath log_path = GetLogFileName(); #if defined(OS_CHROMEOS) + // For BWSI (Incognito) logins, we want to put the logs in the user + // profile directory that is created for the temporary session instead + // of in the system log directory, for privacy reasons. + if (command_line.HasSwitch(switches::kGuestSession)) + log_path = GetSessionLogFile(command_line); + // On ChromeOS we log to the symlink. We force creation of a new // symlink if we've been asked to delete the old log, since that // indicates the start of a new session. diff --git a/chrome/common/logging_chrome.h b/chrome/common/logging_chrome.h index c8dac42..6fc1389 100644 --- a/chrome/common/logging_chrome.h +++ b/chrome/common/logging_chrome.h @@ -37,8 +37,11 @@ void InitChromeLogging(const CommandLine& command_line, OldFileDeletionState delete_old_log_file); #if defined(OS_CHROMEOS) -void RedirectChromeLogging(const FilePath& new_log_dir, - const CommandLine& command_line); +// Get the log file location. +FilePath GetSessionLogFile(const CommandLine& command_line); + +// Redirects chrome logging to the appropriate session log dir. +void RedirectChromeLogging(const CommandLine& command_line); #endif // Call when done using logging for Chrome. diff --git a/chrome/test/in_process_browser_test.cc b/chrome/test/in_process_browser_test.cc index 8275fd6..e8efda8 100644 --- a/chrome/test/in_process_browser_test.cc +++ b/chrome/test/in_process_browser_test.cc @@ -29,6 +29,7 @@ #include "chrome/common/chrome_constants.h" #include "chrome/common/chrome_paths.h" #include "chrome/common/chrome_switches.h" +#include "chrome/common/logging_chrome.h" #include "chrome/common/main_function_params.h" #include "chrome/common/notification_registrar.h" #include "chrome/common/notification_type.h" @@ -190,6 +191,10 @@ void InProcessBrowserTest::SetUp() { #if defined(OS_CHROMEOS) chromeos::CrosLibrary::Get()->GetTestApi()->SetUseStubImpl(); + + // Make sure that the log directory exists. + FilePath log_dir = logging::GetSessionLogFile(*command_line).DirName(); + file_util::CreateDirectory(log_dir); #endif // defined(OS_CHROMEOS) SandboxInitWrapper sandbox_wrapper; |