#include "android_webview/nonembedded/webview_apk_process.h"
#include "android_webview/common/aw_paths.h"
#include "base/android/library_loader/library_loader_hooks.h"
#include "base/base_paths_android.h"
#include "base/command_line.h"
#include "base/message_loop/message_pump_type.h"
#include "base/path_service.h"
#include "base/task/single_thread_task_executor.h"
#include "base/task/thread_pool/thread_pool_instance.h"
#include "components/component_updater/component_updater_paths.h"
#include "components/prefs/json_pref_store.h"
#include "components/prefs/pref_registry_simple.h"
#include "components/prefs/pref_service.h"
#include "components/prefs/pref_service_factory.h"
#include "components/update_client/protocol_serializer_json.h"
#include "components/update_client/update_client.h"
namespace android_webview {
namespace {
static WebViewApkProcess* g_webview_apk_process = nullptr;
}
WebViewApkProcess* WebViewApkProcess::GetInstance() {
DCHECK(g_webview_apk_process);
return g_webview_apk_process;
}
void WebViewApkProcess::Init() {
DCHECK(!g_webview_apk_process);
g_webview_apk_process = new WebViewApkProcess();
}
WebViewApkProcess::WebViewApkProcess() {
base::ThreadPoolInstance::CreateAndStartWithDefaultParams(
"WebViewApkProcess");
main_task_executor_ = std::make_unique<base::SingleThreadTaskExecutor>(
base::MessagePumpType::JAVA);
base::CommandLine::ForCurrentProcess()->AppendSwitch(
update_client::switches::kComponentUpdaterCompatProtocols);
RegisterPathProvider();
component_updater::RegisterPathProvider(
android_webview::DIR_COMPONENTS_ROOT,
android_webview::DIR_COMPONENTS_ROOT,
android_webview::DIR_COMPONENTS_ROOT);
CreatePrefService();
}
WebViewApkProcess::~WebViewApkProcess() = default;
PrefService* WebViewApkProcess::GetPrefService() const {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
return pref_service_.get();
}
void WebViewApkProcess::CreatePrefService() {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
auto pref_registry = base::MakeRefCounted<PrefRegistrySimple>();
PrefServiceFactory pref_service_factory;
RegisterPrefs(pref_registry.get());
base::FilePath app_data_dir;
base::PathService::Get(base::DIR_ANDROID_APP_DATA, &app_data_dir);
pref_service_factory.set_user_prefs(
base::MakeRefCounted<JsonPrefStore>(app_data_dir.Append(
FILE_PATH_LITERAL("WebView Nonembedded Preferences"))));
pref_service_ = pref_service_factory.Create(pref_registry);
}
void WebViewApkProcess::RegisterPrefs(PrefRegistrySimple* pref_registry) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
update_client::RegisterPrefs(pref_registry);
}
}