Commit b14132f4 authored by Luke Halliwell's avatar Luke Halliwell Committed by Commit Bot

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

This reverts commit c513d32f.

Reason for revert: See internal b/124450506
Ultimately, this code gets bitten by these horrors:
https://codesearch.chromium.org/chromium/src/services/service_manager/embedder/set_process_title_linux.cc?q=process_title&sq=package:chromium&g=0&l=114

Original change's description:
> [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: Wez <wez@chromium.org>
> Reviewed-by: Yuchen Liu <yucliu@chromium.org>
> Reviewed-by: Sergey Volk <servolk@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#625457}

TBR=wez@chromium.org,servolk@chromium.org,yucliu@chromium.org,awolter@chromium.org

# Not skipping CQ checks because original CL landed > 1 day ago.

Bug: b/122267826
Change-Id: I5ce28fa732ac6f1af8f3e19a51d66bceab081681
Reviewed-on: https://chromium-review.googlesource.com/c/1482135Reviewed-by: default avatarLuke Halliwell <halliwell@chromium.org>
Reviewed-by: default avatarYuchen Liu <yucliu@chromium.org>
Commit-Queue: Luke Halliwell <halliwell@chromium.org>
Cr-Commit-Position: refs/heads/master@{#634513}
parent d62ac714
...@@ -98,10 +98,7 @@ cast_source_set("unittests") { ...@@ -98,10 +98,7 @@ cast_source_set("unittests") {
"//testing/gtest", "//testing/gtest",
] ]
if (is_fuchsia) { if (!is_fuchsia) {
sources += [ "cast_main_delegate_unittest.cc" ]
deps += [ ":app" ]
} else {
deps += [ deps += [
# TODO(crbug.com/753619): Enable crash reporting on Fuchsia. # TODO(crbug.com/753619): Enable crash reporting on Fuchsia.
":cast_crash_client", ":cast_crash_client",
......
...@@ -23,7 +23,6 @@ JNI_EXPORT jint JNI_OnLoad(JavaVM* vm, void* reserved) { ...@@ -23,7 +23,6 @@ JNI_EXPORT jint JNI_OnLoad(JavaVM* vm, void* reserved) {
return false; return false;
content::Compositor::Initialize(); content::Compositor::Initialize();
content::SetContentMainDelegate( content::SetContentMainDelegate(new chromecast::shell::CastMainDelegate);
new chromecast::shell::CastMainDelegate(0, nullptr));
return JNI_VERSION_1_4; return JNI_VERSION_1_4;
} }
...@@ -6,9 +6,9 @@ ...@@ -6,9 +6,9 @@
#include "content/public/app/content_main.h" #include "content/public/app/content_main.h"
int main(int argc, const char** argv) { int main(int argc, const char** argv) {
chromecast::shell::CastMainDelegate delegate(argc, argv); chromecast::shell::CastMainDelegate delegate;
content::ContentMainParams params(&delegate); content::ContentMainParams params(&delegate);
params.argc = delegate.argc(); params.argc = argc;
params.argv = delegate.argv(); params.argv = argv;
return content::ContentMain(params); return content::ContentMain(params);
} }
...@@ -10,15 +10,14 @@ ...@@ -10,15 +10,14 @@
#include "base/command_line.h" #include "base/command_line.h"
#include "base/cpu.h" #include "base/cpu.h"
#include "base/files/file.h"
#include "base/files/file_enumerator.h" #include "base/files/file_enumerator.h"
#include "base/files/file_path.h"
#include "base/files/file_util.h" #include "base/files/file_util.h"
#include "base/logging.h" #include "base/logging.h"
#include "base/metrics/field_trial.h" #include "base/metrics/field_trial.h"
#include "base/no_destructor.h" #include "base/no_destructor.h"
#include "base/path_service.h" #include "base/path_service.h"
#include "base/posix/global_descriptors.h" #include "base/posix/global_descriptors.h"
#include "base/strings/string_tokenizer.h"
#include "build/build_config.h" #include "build/build_config.h"
#include "chromecast/base/cast_paths.h" #include "chromecast/base/cast_paths.h"
#include "chromecast/base/chromecast_switches.h" #include "chromecast/base/chromecast_switches.h"
...@@ -45,10 +44,6 @@ ...@@ -45,10 +44,6 @@
#include "services/service_manager/sandbox/switches.h" #include "services/service_manager/sandbox/switches.h"
#endif // defined(OS_LINUX) #endif // defined(OS_LINUX)
#if defined(OS_FUCHSIA)
#include "base/base_paths_fuchsia.h"
#endif
namespace { namespace {
#if defined(OS_LINUX) #if defined(OS_LINUX)
...@@ -63,43 +58,12 @@ chromecast::CastCrashReporterClient* GetCastCrashReporter() { ...@@ -63,43 +58,12 @@ chromecast::CastCrashReporterClient* GetCastCrashReporter() {
const int kMaxCrashFiles = 10; const int kMaxCrashFiles = 10;
#endif // defined(OS_ANDROID) #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
namespace chromecast { namespace chromecast {
namespace shell { namespace shell {
CastMainDelegate::CastMainDelegate(int argc, const char** argv) CastMainDelegate::CastMainDelegate() {}
: 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() {} CastMainDelegate::~CastMainDelegate() {}
......
...@@ -6,10 +6,7 @@ ...@@ -6,10 +6,7 @@
#define CHROMECAST_APP_CAST_MAIN_DELEGATE_H_ #define CHROMECAST_APP_CAST_MAIN_DELEGATE_H_
#include <memory> #include <memory>
#include <string>
#include <vector>
#include "base/files/file_path.h"
#include "base/macros.h" #include "base/macros.h"
#include "build/build_config.h" #include "build/build_config.h"
#include "chromecast/common/cast_content_client.h" #include "chromecast/common/cast_content_client.h"
...@@ -36,7 +33,7 @@ class CastContentUtilityClient; ...@@ -36,7 +33,7 @@ class CastContentUtilityClient;
class CastMainDelegate : public content::ContentMainDelegate { class CastMainDelegate : public content::ContentMainDelegate {
public: public:
CastMainDelegate(int argc, const char** argv); CastMainDelegate();
~CastMainDelegate() override; ~CastMainDelegate() override;
// content::ContentMainDelegate implementation: // content::ContentMainDelegate implementation:
...@@ -54,16 +51,7 @@ class CastMainDelegate : public content::ContentMainDelegate { ...@@ -54,16 +51,7 @@ class CastMainDelegate : public content::ContentMainDelegate {
content::ContentRendererClient* CreateContentRendererClient() override; content::ContentRendererClient* CreateContentRendererClient() override;
content::ContentUtilityClient* CreateContentUtilityClient() override; content::ContentUtilityClient* CreateContentUtilityClient() override;
int argc() const { return argv_.size(); }
const char** argv() const { return const_cast<const char**>(argv_.data()); }
private: private:
friend class CastMainDelegateTest;
// Used for testing.
CastMainDelegate(int argc,
const char** argv,
base::FilePath command_line_path);
void InitializeResourceBundle(); void InitializeResourceBundle();
std::unique_ptr<CastContentBrowserClient> browser_client_; std::unique_ptr<CastContentBrowserClient> browser_client_;
...@@ -84,11 +72,6 @@ class CastMainDelegate : public content::ContentMainDelegate { ...@@ -84,11 +72,6 @@ class CastMainDelegate : public content::ContentMainDelegate {
std::unique_ptr<CastFeatureListCreator> cast_feature_list_creator_; 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); 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 { ...@@ -35,7 +35,7 @@ class CastTestLauncherDelegate : public content::TestLauncherDelegate {
protected: protected:
content::ContentMainDelegate* CreateContentMainDelegate() override { content::ContentMainDelegate* CreateContentMainDelegate() override {
return new CastMainDelegate(0, nullptr); return new CastMainDelegate();
} }
private: private:
......
...@@ -21,6 +21,5 @@ ...@@ -21,6 +21,5 @@
"fuchsia.ui.scenic.Scenic", "fuchsia.ui.scenic.Scenic",
"fuchsia.vulkan.loader.Loader", "fuchsia.vulkan.loader.Loader",
"fuchsia.wlan.service.Wlan" "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