Skip to content

Commit

Permalink
Use 'cobalt' instead of 'content_shell' for logging and paths.
Browse files Browse the repository at this point in the history
This changes the paths and the default log file to 'cobalt' instead of
'content_shell'.

With this PR, the local storage for the `cobalt` target on linux will be
`~/.config/cobalt`

b/374191454
  • Loading branch information
jellefoks committed Oct 23, 2024
1 parent a993738 commit fdf7de8
Show file tree
Hide file tree
Showing 6 changed files with 169 additions and 0 deletions.
8 changes: 8 additions & 0 deletions base/threading/thread_restrictions.h
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,11 @@ namespace chrome_cleaner {
class ResetShortcutsComponent;
class SystemReportComponent;
} // namespace chrome_cleaner
#if BUILDFLAG(USE_STARBOARD)
namespace cobalt {
class CobaltPathProvider;
}
#endif // BUILDFLAG(USE_STARBOARD)
namespace content {
class BrowserGpuChannelHostFactory;
class BrowserMainLoop;
Expand Down Expand Up @@ -601,6 +606,9 @@ class BASE_EXPORT [[maybe_unused, nodiscard]] ScopedAllowBlocking {
friend class base::win::ScopedAllowBlockingForUserAccountControl;
friend class blink::DiskDataAllocator;
friend class chromecast::CrashUtil;
#if BUILDFLAG(USE_STARBOARD)
friend class cobalt::CobaltPathProvider;
#endif // BUILDFLAG(USE_STARBOARD)
friend class content::BrowserProcessIOThread;
friend class content::DWriteFontProxyImpl;
friend class content::NetworkServiceInstancePrivate;
Expand Down
2 changes: 2 additions & 0 deletions cobalt/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ if (!is_android) {
"cobalt_content_browser_client.h",
"cobalt_main_delegate.cc",
"cobalt_main_delegate.h",
"cobalt_paths.cc",
"cobalt_paths.h",
]

defines = []
Expand Down
58 changes: 58 additions & 0 deletions cobalt/cobalt_main_delegate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,41 @@
// limitations under the License.

#include "cobalt/cobalt_main_delegate.h"

#include <iostream>

#include "base/path_service.h"
#include "cobalt/cobalt_content_browser_client.h"
#include "cobalt/cobalt_paths.h"
#include "content/public/common/content_switches.h"
#include "content/shell/common/shell_switches.h"

#if !BUILDFLAG(IS_ANDROID)
#include "content/web_test/browser/web_test_browser_main_runner.h" // nogncheck
#include "content/web_test/browser/web_test_content_browser_client.h" // nogncheck
#include "content/web_test/renderer/web_test_content_renderer_client.h" // nogncheck
#endif

namespace {

void InitLogging(const base::CommandLine& command_line) {
base::FilePath log_filename =
command_line.GetSwitchValuePath(switches::kLogFile);
if (log_filename.empty()) {
base::PathService::Get(base::DIR_EXE, &log_filename);
log_filename = log_filename.AppendASCII("cobalt.log");
}

logging::LoggingSettings settings;
settings.logging_dest = logging::LOG_TO_ALL;
settings.log_file_path = log_filename.value().c_str();
settings.delete_old = logging::DELETE_OLD_LOG_FILE;
logging::InitLogging(settings);
logging::SetLogItems(true /* Process ID */, true /* Thread ID */,
true /* Timestamp */, false /* Tick count */);
}

} // namespace

namespace cobalt {

Expand All @@ -22,6 +56,30 @@ CobaltMainDelegate::CobaltMainDelegate(bool is_content_browsertests)

CobaltMainDelegate::~CobaltMainDelegate() {}

absl::optional<int> CobaltMainDelegate::BasicStartupComplete() {
base::CommandLine& command_line = *base::CommandLine::ForCurrentProcess();
#if BUILDFLAG(IS_ANDROID)
content::Compositor::Initialize();
#endif

InitLogging(command_line);

#if !BUILDFLAG(IS_ANDROID)
if (switches::IsRunWebTestsSwitchPresent()) {
const bool browser_process =
command_line.GetSwitchValueASCII(switches::kProcessType).empty();
if (browser_process) {
web_test_runner_ = std::make_unique<content::WebTestBrowserMainRunner>();
web_test_runner_->Initialize();
}
}
#endif

RegisterCobaltPathProvider();

return absl::nullopt;
}

content::ContentBrowserClient*
CobaltMainDelegate::CreateContentBrowserClient() {
browser_client_ = std::make_unique<CobaltContentBrowserClient>();
Expand Down
1 change: 1 addition & 0 deletions cobalt/cobalt_main_delegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class CobaltMainDelegate : public content::ShellMainDelegate {
CobaltMainDelegate& operator=(const CobaltMainDelegate&) = delete;

// ContentMainDelegate implementation:
absl::optional<int> BasicStartupComplete() override;
content::ContentBrowserClient* CreateContentBrowserClient() override;

~CobaltMainDelegate() override;
Expand Down
71 changes: 71 additions & 0 deletions cobalt/cobalt_paths.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
// Copyright 2021 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "cobalt/cobalt_paths.h"

#include "base/base_paths.h"
#include "base/environment.h"
#include "base/files/file_util.h"
#include "base/path_service.h"
#include "base/threading/thread_restrictions.h"
#include "build/build_config.h"

#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
#include "base/nix/xdg_util.h"
#endif

namespace cobalt {

namespace {

bool GetDefaultUserDataDirectory(base::FilePath* result) {
#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
std::unique_ptr<base::Environment> env(base::Environment::Create());
base::FilePath config_dir(base::nix::GetXDGDirectory(
env.get(), base::nix::kXdgConfigHomeEnvVar, base::nix::kDotConfigDir));
*result = config_dir.Append("cobalt");
#elif BUILDFLAG(IS_ANDROID)
CHECK(base::PathService::Get(base::DIR_ANDROID_APP_DATA, result));
*result = result->Append(FILE_PATH_LITERAL("cobalt"));
#else
NOTIMPLEMENTED();
return false;
#endif
return true;
}

} // namespace

class CobaltPathProvider {
public:
static void CreateDir(const base::FilePath& path) {
base::ScopedAllowBlocking allow_io;
if (!base::PathExists(path)) {
base::CreateDirectory(path);
}
}
};

bool CobaltPathProvider(int key, base::FilePath* result) {
base::FilePath cur;

switch (key) {
case SHELL_DIR_USER_DATA: {
bool rv = GetDefaultUserDataDirectory(result);
if (rv) {
CobaltPathProvider::CreateDir(*result);
}
return rv;
}
default:
return false;
}
}

void RegisterCobaltPathProvider() {
base::PathService::RegisterProvider(CobaltPathProvider, SHELL_PATH_START,
SHELL_PATH_END);
}

} // namespace cobalt
29 changes: 29 additions & 0 deletions cobalt/cobalt_paths.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Copyright 2021 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CONTENT_SHELL_BROWSER_SHELL_PATHS_H_
#define CONTENT_SHELL_BROWSER_SHELL_PATHS_H_

#include "build/build_config.h"

namespace cobalt {

enum {
SHELL_PATH_START = 12000,

// Directory where user data can be written.
SHELL_DIR_USER_DATA = SHELL_PATH_START,

// TODO(jam): move from content/common since it's test only.
// DIR_TEST_DATA,

SHELL_PATH_END
};

// Call once to register the provider for the path keys defined above.
void RegisterCobaltPathProvider();

} // namespace cobalt

#endif // CONTENT_SHELL_BROWSER_SHELL_PATHS_H_

0 comments on commit fdf7de8

Please sign in to comment.