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

Side by Side Diff: chrome/browser/chromeos/logging.cc

Issue 2901173002: Move RedirectChromeLogging to src/chromeos. (Closed)
Patch Set: Rebase Created 3 years, 6 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
OLDNEW
(Empty)
1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/browser/chromeos/logging.h"
6
7 #include "base/bind.h"
8 #include "base/command_line.h"
9 #include "base/files/file_path.h"
10 #include "base/logging.h"
11 #include "base/task_scheduler/post_task.h"
12 #include "chrome/common/logging_chrome.h"
13 #include "content/public/browser/browser_thread.h"
14
15 namespace logging {
16
17 namespace {
18
19 // This should be true for exactly the period between the end of
20 // InitChromeLogging() and the beginning of CleanupChromeLogging().
21 bool chrome_logging_redirected_ = false;
22
23 void SymlinkSetUp(const base::CommandLine& command_line,
24 const base::FilePath& log_path,
25 const base::FilePath& target_path) {
26 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
27
28 // ChromeOS always logs through the symlink, so it shouldn't be
29 // deleted if it already exists.
30 logging::LoggingSettings settings;
31 settings.logging_dest = DetermineLoggingDestination(command_line);
32 settings.log_file = log_path.value().c_str();
33 if (!logging::InitLogging(settings)) {
34 DLOG(ERROR) << "Unable to initialize logging to " << log_path.value();
35 base::PostTaskWithTraits(
36 FROM_HERE, {base::MayBlock()},
37 base::Bind(&RemoveSymlinkAndLog, log_path, target_path));
38 } else {
39 chrome_logging_redirected_ = true;
40 }
41 }
42
43 } // namespace
44
45 void RedirectChromeLogging(const base::CommandLine& command_line) {
46 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
47
48 if (chrome_logging_redirected_) {
49 // TODO: Support multiple active users. http://crbug.com/230345
50 LOG(WARNING) << "NOT redirecting logging for multi-profiles case.";
51 return;
52 }
53
54 DCHECK(!chrome_logging_redirected_)
55 << "Attempted to redirect logging when it was already initialized.";
56
57 // Redirect logs to the session log directory, if set. Otherwise
58 // defaults to the profile dir.
59 const base::FilePath log_path = GetSessionLogFile(command_line);
60
61 // Always force a new symlink when redirecting.
62 base::PostTaskWithTraitsAndReplyWithResult(
63 FROM_HERE, {base::MayBlock()},
64 base::BindOnce(&SetUpSymlinkIfNeeded, log_path, true),
65 base::BindOnce(&SymlinkSetUp, command_line, log_path));
66 }
67
68 } // namespace logging
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/logging.h ('k') | chrome/browser/chromeos/login/session/user_session_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698