#include "chromecast/external_mojo/public/cpp/common.h"
#include <string_view>
#include "base/check.h"
#include "base/command_line.h"
#include "base/files/file_path.h"
#include "base/path_service.h"
#include "build/build_config.h"
#include "chromecast/base/chromecast_switches.h"
namespace chromecast {
namespace external_mojo {
namespace {
#if !BUILDFLAG(IS_ANDROID)
constexpr std::string_view kDefaultBrokerPath("/tmp/cast_mojo_broker");
#endif
}
std::string GetBrokerPath() {
std::string broker_path;
base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
if (command_line->HasSwitch(switches::kCastMojoBrokerPath)) {
broker_path =
command_line->GetSwitchValueASCII(switches::kCastMojoBrokerPath);
} else {
#if BUILDFLAG(IS_ANDROID)
base::FilePath socket_path;
CHECK(base::PathService::Get(base::DIR_ANDROID_APP_DATA, &socket_path));
socket_path = socket_path.AppendASCII(FILE_PATH_LITERAL("cast_mojo_broker"));
broker_path = socket_path.MaybeAsASCII();
#else
broker_path = std::string(kDefaultBrokerPath);
#endif
}
return broker_path;
}
}
}