| Index: ios/web_view/internal/app/application_context_impl.cc
|
| diff --git a/ios/web_view/internal/app/application_context_impl.cc b/ios/web_view/internal/app/application_context_impl.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..5533ae5c50673f3b5959ac696e2d2754baccd3f2
|
| --- /dev/null
|
| +++ b/ios/web_view/internal/app/application_context_impl.cc
|
| @@ -0,0 +1,144 @@
|
| +// Copyright 2017 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 "ios/web_view/internal/app/application_context_impl.h"
|
| +
|
| +#include "base/command_line.h"
|
| +#include "base/path_service.h"
|
| +#include "base/tracked_objects.h"
|
| +#include "components/flags_ui/pref_service_flags_storage.h"
|
| +#include "components/net_log/chrome_net_log.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/proxy_config/pref_proxy_config_tracker_impl.h"
|
| +#include "components/ssl_config/ssl_config_service_manager.h"
|
| +#include "components/translate/core/browser/translate_download_manager.h"
|
| +#include "ios/web/public/web_thread.h"
|
| +#include "ios/web_view/internal/app/web_view_io_thread.h"
|
| +#include "net/socket/client_socket_pool_manager.h"
|
| +
|
| +namespace ios_web_view {
|
| +
|
| +base::FilePath ApplicationContextImpl::GetLocalStatePath() {
|
| + base::FilePath local_state_path;
|
| + PathService::Get(base::DIR_APP_DATA, &local_state_path);
|
| + local_state_path =
|
| + local_state_path.Append(FILE_PATH_LITERAL("ChromeWebView"));
|
| + local_state_path = local_state_path.Append(FILE_PATH_LITERAL("Local State"));
|
| + return local_state_path;
|
| +}
|
| +
|
| +ApplicationContextImpl::ApplicationContextImpl(
|
| + const base::CommandLine& command_line,
|
| + const std::string& locale)
|
| + : local_state_task_runner_(JsonPrefStore::GetTaskRunnerForFile(
|
| + GetLocalStatePath(),
|
| + web::WebThread::GetBlockingPool())),
|
| + created_local_state_(false) {
|
| + DCHECK(!GetApplicationContext());
|
| + SetApplicationContext(this);
|
| +
|
| + net_log_.reset(new net_log::ChromeNetLog(
|
| + base::FilePath(), net::NetLogCaptureMode::Default(),
|
| + command_line.GetCommandLineString(), std::string()));
|
| +
|
| + SetApplicationLocale(locale);
|
| +}
|
| +
|
| +ApplicationContextImpl::~ApplicationContextImpl() {
|
| + DCHECK_EQ(this, GetApplicationContext());
|
| + tracked_objects::ThreadData::EnsureCleanupWasCalled(4);
|
| + SetApplicationContext(nullptr);
|
| +}
|
| +
|
| +void ApplicationContextImpl::PreCreateThreads() {
|
| + DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
|
| + web_view_io_thread_.reset(new WebViewIOThread(GetLocalState(), GetNetLog()));
|
| +}
|
| +
|
| +void ApplicationContextImpl::SaveState() {
|
| + DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
|
| + // TODO(crbug.com/723854): Commit prefs when entering background.
|
| + if (local_state_) {
|
| + local_state_->CommitPendingWrite();
|
| + }
|
| +}
|
| +
|
| +void ApplicationContextImpl::PostDestroyThreads() {
|
| + DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
|
| + // Resets associated state right after actual thread is stopped as
|
| + // WebViewIOThread::Globals cleanup happens in CleanUp on the IO
|
| + // thread, i.e. as the thread exits its message loop.
|
| + //
|
| + // This is important because in various places, the WebViewIOThread
|
| + // object being NULL is considered synonymous with the IO thread
|
| + // having stopped.
|
| + web_view_io_thread_.reset();
|
| +}
|
| +
|
| +PrefService* ApplicationContextImpl::GetLocalState() {
|
| + DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
|
| + if (!created_local_state_)
|
| + CreateLocalState();
|
| + return local_state_.get();
|
| +}
|
| +
|
| +net::URLRequestContextGetter*
|
| +ApplicationContextImpl::GetSystemURLRequestContext() {
|
| + DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
|
| + return web_view_io_thread_->system_url_request_context_getter();
|
| +}
|
| +
|
| +const std::string& ApplicationContextImpl::GetApplicationLocale() {
|
| + DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
|
| + DCHECK(!application_locale_.empty());
|
| + return application_locale_;
|
| +}
|
| +
|
| +net_log::ChromeNetLog* ApplicationContextImpl::GetNetLog() {
|
| + DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
|
| + return net_log_.get();
|
| +}
|
| +
|
| +WebViewIOThread* ApplicationContextImpl::GetWebViewIOThread() {
|
| + DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
|
| + DCHECK(web_view_io_thread_.get());
|
| + return web_view_io_thread_.get();
|
| +}
|
| +
|
| +void ApplicationContextImpl::SetApplicationLocale(const std::string& locale) {
|
| + DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
|
| + application_locale_ = locale;
|
| + translate::TranslateDownloadManager::GetInstance()->set_application_locale(
|
| + application_locale_);
|
| +}
|
| +
|
| +void ApplicationContextImpl::CreateLocalState() {
|
| + DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
|
| + DCHECK(!created_local_state_ && !local_state_);
|
| + created_local_state_ = true;
|
| +
|
| + // Register local state preferences.
|
| + scoped_refptr<PrefRegistrySimple> pref_registry(new PrefRegistrySimple);
|
| + flags_ui::PrefServiceFlagsStorage::RegisterPrefs(pref_registry.get());
|
| + PrefProxyConfigTrackerImpl::RegisterPrefs(pref_registry.get());
|
| + ssl_config::SSLConfigServiceManager::RegisterPrefs(pref_registry.get());
|
| +
|
| + scoped_refptr<PersistentPrefStore> user_pref_store =
|
| + new JsonPrefStore(GetLocalStatePath(), local_state_task_runner_, nullptr);
|
| +
|
| + PrefServiceFactory factory;
|
| + factory.set_user_prefs(user_pref_store);
|
| + local_state_ = factory.Create(pref_registry.get());
|
| +
|
| + net::ClientSocketPoolManager::set_max_sockets_per_proxy_server(
|
| + net::HttpNetworkSession::NORMAL_SOCKET_POOL,
|
| + std::max(std::min<int>(net::kDefaultMaxSocketsPerProxyServer, 99),
|
| + net::ClientSocketPoolManager::max_sockets_per_group(
|
| + net::HttpNetworkSession::NORMAL_SOCKET_POOL)));
|
| +}
|
| +
|
| +} // namespace ios_web_view
|
|
|