Commit c513d32f authored by Aidan Wolter's avatar Aidan Wolter Committed by Commit Bot

[fuchsia] Read the command-line from /data/cast/

The command-line will now be populated from
/data/cast/castagent-command-line.

Bug: b/122267826
Test: Add command-line to show verbose logging, cast_shell_unittests
Change-Id: I741a1a32e59bea07a2ce857d24df57712cf32761
Reviewed-on: https://chromium-review.googlesource.com/c/1396135
Commit-Queue: Aidan Wolter <awolter@chromium.org>
Reviewed-by: default avatarWez <wez@chromium.org>
Reviewed-by: default avatarYuchen Liu <yucliu@chromium.org>
Reviewed-by: default avatarSergey Volk <servolk@chromium.org>
Cr-Commit-Position: refs/heads/master@{#625457}
parent 9222b4fc
......@@ -98,7 +98,10 @@ cast_source_set("unittests") {
"//testing/gtest",
]
if (!is_fuchsia) {
if (is_fuchsia) {
sources += [ "cast_main_delegate_unittest.cc" ]
deps += [ ":app" ]
} else {
deps += [
# TODO(crbug.com/753619): Enable crash reporting on Fuchsia.
":cast_crash_client",
......
......@@ -23,6 +23,7 @@ JNI_EXPORT jint JNI_OnLoad(JavaVM* vm, void* reserved) {
return false;
content::Compositor::Initialize();
content::SetContentMainDelegate(new chromecast::shell::CastMainDelegate);
content::SetContentMainDelegate(
new chromecast::shell::CastMainDelegate(0, nullptr));
return JNI_VERSION_1_4;
}
......@@ -6,9 +6,9 @@
#include "content/public/app/content_main.h"
int main(int argc, const char** argv) {
chromecast::shell::CastMainDelegate delegate;
chromecast::shell::CastMainDelegate delegate(argc, argv);
content::ContentMainParams params(&delegate);
params.argc = argc;
params.argv = argv;
params.argc = delegate.argc();
params.argv = delegate.argv();
return content::ContentMain(params);
}
......@@ -10,14 +10,15 @@
#include "base/command_line.h"
#include "base/cpu.h"
#include "base/files/file.h"
#include "base/files/file_enumerator.h"
#include "base/files/file_path.h"
#include "base/files/file_util.h"
#include "base/logging.h"
#include "base/metrics/field_trial.h"
#include "base/no_destructor.h"
#include "base/path_service.h"
#include "base/posix/global_descriptors.h"
#include "base/strings/string_tokenizer.h"
#include "build/build_config.h"
#include "chromecast/base/cast_paths.h"
#include "chromecast/base/chromecast_switches.h"
......@@ -44,6 +45,10 @@
#include "services/service_manager/sandbox/switches.h"
#endif // defined(OS_LINUX)
#if defined(OS_FUCHSIA)
#include "base/base_paths_fuchsia.h"
#endif
namespace {
#if defined(OS_LINUX)
......@@ -58,12 +63,43 @@ chromecast::CastCrashReporterClient* GetCastCrashReporter() {
const int kMaxCrashFiles = 10;
#endif // defined(OS_ANDROID)
base::FilePath GetDefaultCommandLineFile() {
#if defined(OS_FUCHSIA)
base::FilePath command_line_dir;
base::PathService::Get(base::DIR_APP_DATA, &command_line_dir);
return command_line_dir.Append("cast/castagent-command-line");
#else
return base::FilePath();
#endif
}
} // namespace
namespace chromecast {
namespace shell {
CastMainDelegate::CastMainDelegate() {}
CastMainDelegate::CastMainDelegate(int argc, const char** argv)
: CastMainDelegate(argc, argv, GetDefaultCommandLineFile()) {}
CastMainDelegate::CastMainDelegate(int argc,
const char** argv,
base::FilePath command_line_path)
: argv_(argv, argv + argc) {
#if defined(OS_FUCHSIA)
// Read the command-line from the filesystem.
std::string command_line_str;
if (base::ReadFileToString(command_line_path, &command_line_str)) {
LOG(INFO) << "Appending command-line args from " << command_line_path;
base::StringTokenizer tokenizer(command_line_str, "\n");
while (tokenizer.GetNext())
argv_strs_.push_back(tokenizer.token());
for (int i = 0; i < static_cast<int>(argv_strs_.size()); ++i)
argv_.push_back(argv_strs_[i].c_str());
} else {
LOG(INFO) << "Unable to read command-line args from " << command_line_path;
}
#endif // defined(OS_FUCHSIA)
}
CastMainDelegate::~CastMainDelegate() {}
......
......@@ -6,7 +6,10 @@
#define CHROMECAST_APP_CAST_MAIN_DELEGATE_H_
#include <memory>
#include <string>
#include <vector>
#include "base/files/file_path.h"
#include "base/macros.h"
#include "build/build_config.h"
#include "chromecast/common/cast_content_client.h"
......@@ -33,7 +36,7 @@ class CastContentUtilityClient;
class CastMainDelegate : public content::ContentMainDelegate {
public:
CastMainDelegate();
CastMainDelegate(int argc, const char** argv);
~CastMainDelegate() override;
// content::ContentMainDelegate implementation:
......@@ -51,7 +54,16 @@ class CastMainDelegate : public content::ContentMainDelegate {
content::ContentRendererClient* CreateContentRendererClient() override;
content::ContentUtilityClient* CreateContentUtilityClient() override;
int argc() const { return argv_.size(); }
const char** argv() const { return const_cast<const char**>(argv_.data()); }
private:
friend class CastMainDelegateTest;
// Used for testing.
CastMainDelegate(int argc,
const char** argv,
base::FilePath command_line_path);
void InitializeResourceBundle();
std::unique_ptr<CastContentBrowserClient> browser_client_;
......@@ -72,6 +84,11 @@ class CastMainDelegate : public content::ContentMainDelegate {
std::unique_ptr<CastFeatureListCreator> cast_feature_list_creator_;
// Combined list of args passed through the main function, and a specified
// command-line file.
std::vector<std::string> argv_strs_;
std::vector<const char*> argv_;
DISALLOW_COPY_AND_ASSIGN(CastMainDelegate);
};
......
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <memory>
#include <string>
#include "base/files/file.h"
#include "base/memory/ptr_util.h"
#include "chromecast/app/cast_main_delegate.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace chromecast {
namespace shell {
namespace {
const char kTestCommandLineContents[] = "--file1\n--file2\n";
const char kTestCommandLinePath[] = "/tmp/test-command-line";
void WriteTestCommandLine() {
base::File command_line(
base::FilePath(kTestCommandLinePath),
base::File::FLAG_CREATE_ALWAYS | base::File::FLAG_WRITE);
ASSERT_GE(command_line.Write(0, kTestCommandLineContents,
sizeof(kTestCommandLineContents) - 1),
0);
}
} // namespace
class CastMainDelegateTest : public testing::Test {
public:
CastMainDelegateTest() { WriteTestCommandLine(); }
~CastMainDelegateTest() override {}
// testing::Test implementation:
void SetUp() override {
test_argv_strs_.push_back("--main1");
test_argv_strs_.push_back("--main2");
test_argv_.push_back(test_argv_strs_[0].c_str());
test_argv_.push_back(test_argv_strs_[1].c_str());
}
void CreateCastMainDelegate(int argc,
const char** argv,
std::string command_line_path) {
delegate_ = base::WrapUnique(
new CastMainDelegate(argc, argv, base::FilePath(command_line_path)));
}
protected:
std::unique_ptr<CastMainDelegate> delegate_;
std::vector<std::string> test_argv_strs_;
std::vector<const char*> test_argv_;
};
TEST_F(CastMainDelegateTest, AddsArgsFromFile) {
CreateCastMainDelegate(0, nullptr, kTestCommandLinePath);
EXPECT_EQ(2, delegate_->argc());
EXPECT_EQ("--file1", std::string(delegate_->argv()[0]));
EXPECT_EQ("--file2", std::string(delegate_->argv()[1]));
}
TEST_F(CastMainDelegateTest, AddsArgsFromMain) {
CreateCastMainDelegate(test_argv_.size(), &test_argv_[0], "");
EXPECT_EQ(2, delegate_->argc());
EXPECT_EQ("--main1", std::string(delegate_->argv()[0]));
EXPECT_EQ("--main2", std::string(delegate_->argv()[1]));
}
TEST_F(CastMainDelegateTest, MergesArgsFromFileAndMain) {
CreateCastMainDelegate(test_argv_.size(), &test_argv_[0],
kTestCommandLinePath);
EXPECT_EQ(4, delegate_->argc());
EXPECT_EQ("--main1", std::string(delegate_->argv()[0]));
EXPECT_EQ("--main2", std::string(delegate_->argv()[1]));
EXPECT_EQ("--file1", std::string(delegate_->argv()[2]));
EXPECT_EQ("--file2", std::string(delegate_->argv()[3]));
}
} // namespace shell
} // namespace chromecast
......@@ -35,7 +35,7 @@ class CastTestLauncherDelegate : public content::TestLauncherDelegate {
protected:
content::ContentMainDelegate* CreateContentMainDelegate() override {
return new CastMainDelegate();
return new CastMainDelegate(0, nullptr);
}
private:
......
......@@ -19,5 +19,6 @@
"fuchsia.ui.viewsv1.ViewManager",
"fuchsia.vulkan.loader.Loader",
"fuchsia.wlan.service.Wlan"
]
],
"system": [ "data/cast" ]
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment