Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "ios/web_view/internal/app/application_context.h" | |
| 6 | |
| 7 #include "base/command_line.h" | |
| 8 #include "base/memory/ptr_util.h" | |
| 9 #include "base/memory/singleton.h" | |
| 10 #include "base/path_service.h" | |
| 11 #include "base/tracked_objects.h" | |
| 12 #include "components/flags_ui/pref_service_flags_storage.h" | |
| 13 #include "components/net_log/chrome_net_log.h" | |
| 14 #include "components/prefs/json_pref_store.h" | |
| 15 #include "components/prefs/pref_registry_simple.h" | |
| 16 #include "components/prefs/pref_service.h" | |
| 17 #include "components/prefs/pref_service_factory.h" | |
| 18 #include "components/proxy_config/pref_proxy_config_tracker_impl.h" | |
| 19 #include "components/ssl_config/ssl_config_service_manager.h" | |
| 20 #include "components/translate/core/browser/translate_download_manager.h" | |
| 21 #include "ios/web/public/web_thread.h" | |
| 22 #include "ios/web_view/internal/app/web_view_io_thread.h" | |
| 23 #include "net/socket/client_socket_pool_manager.h" | |
| 24 #include "ui/base/l10n/l10n_util_mac.h" | |
| 25 | |
| 26 namespace ios_web_view { | |
| 27 | |
| 28 ApplicationContext* ApplicationContext::GetInstance() { | |
| 29 return base::Singleton<ApplicationContext>::get(); | |
| 30 } | |
| 31 | |
| 32 ApplicationContext::ApplicationContext() | |
| 33 : local_state_task_runner_(JsonPrefStore::GetTaskRunnerForFile( | |
| 34 GetLocalStatePath(), | |
| 35 web::WebThread::GetBlockingPool())) { | |
| 36 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | |
| 37 | |
| 38 net_log_ = base::MakeUnique<net_log::ChromeNetLog>( | |
| 39 base::FilePath(), net::NetLogCaptureMode::Default(), | |
| 40 command_line->GetCommandLineString(), std::string()); | |
| 41 | |
| 42 SetApplicationLocale(l10n_util::GetLocaleOverride()); | |
| 43 } | |
| 44 | |
| 45 ApplicationContext::~ApplicationContext() { | |
| 46 tracked_objects::ThreadData::EnsureCleanupWasCalled(4); | |
|
Eugene But (OOO till 7-30)
2017/05/31 16:25:33
Could you please create a constant for "4" with ex
michaeldo
2017/05/31 21:03:42
I deleted this instead. There is no sense in addin
| |
| 47 } | |
| 48 | |
| 49 void ApplicationContext::PreCreateThreads() { | |
| 50 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_); | |
| 51 web_view_io_thread_ = | |
| 52 base::MakeUnique<WebViewIOThread>(GetLocalState(), GetNetLog()); | |
| 53 } | |
| 54 | |
| 55 void ApplicationContext::SaveState() { | |
| 56 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_); | |
| 57 // TODO(crbug.com/723854): Commit prefs when entering background. | |
| 58 if (local_state_) { | |
|
Eugene But (OOO till 7-30)
2017/05/31 16:25:33
Should we create local_state_ instead of having no
michaeldo
2017/05/31 21:03:42
I don't think so. No reason to create Local state
| |
| 59 local_state_->CommitPendingWrite(); | |
| 60 } | |
| 61 } | |
| 62 | |
| 63 void ApplicationContext::PostDestroyThreads() { | |
| 64 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_); | |
| 65 // Resets associated state right after actual thread is stopped as | |
| 66 // WebViewIOThread::Globals cleanup happens in CleanUp on the IO | |
| 67 // thread, i.e. as the thread exits its message loop. | |
| 68 // | |
| 69 // This is important because in various places, the WebViewIOThread | |
| 70 // object being null is considered synonymous with the IO thread | |
| 71 // having stopped. | |
| 72 web_view_io_thread_.reset(); | |
| 73 } | |
| 74 | |
| 75 PrefService* ApplicationContext::GetLocalState() { | |
| 76 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_); | |
| 77 if (!local_state_) { | |
| 78 // Register local state preferences. | |
| 79 scoped_refptr<PrefRegistrySimple> pref_registry(new PrefRegistrySimple); | |
| 80 flags_ui::PrefServiceFlagsStorage::RegisterPrefs(pref_registry.get()); | |
| 81 PrefProxyConfigTrackerImpl::RegisterPrefs(pref_registry.get()); | |
| 82 ssl_config::SSLConfigServiceManager::RegisterPrefs(pref_registry.get()); | |
| 83 | |
| 84 scoped_refptr<PersistentPrefStore> user_pref_store = new JsonPrefStore( | |
| 85 GetLocalStatePath(), local_state_task_runner_, nullptr); | |
| 86 | |
| 87 PrefServiceFactory factory; | |
| 88 factory.set_user_prefs(user_pref_store); | |
| 89 local_state_ = factory.Create(pref_registry.get()); | |
| 90 | |
| 91 int max_normal_socket_pool_count = | |
| 92 net::ClientSocketPoolManager::max_sockets_per_group( | |
| 93 net::HttpNetworkSession::NORMAL_SOCKET_POOL); | |
| 94 int socket_count = | |
| 95 std::max(std::min<int>(net::kDefaultMaxSocketsPerProxyServer, 99), | |
|
Eugene But (OOO till 7-30)
2017/05/31 16:25:34
Do we know why we limit to 99 sockets?
michaeldo
2017/05/31 21:03:42
Unfortunately, I have no idea. I don't think it's
Hiroshi Ichikawa
2017/06/01 02:25:59
Can you at least add a comment which points to whe
michaeldo
2017/06/01 21:20:38
I started to add a comment, but then looked into t
| |
| 96 max_normal_socket_pool_count); | |
| 97 net::ClientSocketPoolManager::set_max_sockets_per_proxy_server( | |
| 98 net::HttpNetworkSession::NORMAL_SOCKET_POOL, socket_count); | |
| 99 } | |
| 100 return local_state_.get(); | |
| 101 } | |
| 102 | |
| 103 net::URLRequestContextGetter* ApplicationContext::GetSystemURLRequestContext() { | |
| 104 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_); | |
| 105 return web_view_io_thread_->system_url_request_context_getter(); | |
| 106 } | |
| 107 | |
| 108 const std::string& ApplicationContext::GetApplicationLocale() { | |
| 109 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_); | |
| 110 DCHECK(!application_locale_.empty()); | |
| 111 return application_locale_; | |
| 112 } | |
| 113 | |
| 114 net_log::ChromeNetLog* ApplicationContext::GetNetLog() { | |
| 115 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_); | |
| 116 return net_log_.get(); | |
| 117 } | |
| 118 | |
| 119 WebViewIOThread* ApplicationContext::GetWebViewIOThread() { | |
| 120 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_); | |
| 121 DCHECK(web_view_io_thread_.get()); | |
| 122 return web_view_io_thread_.get(); | |
| 123 } | |
| 124 | |
| 125 base::FilePath ApplicationContext::GetLocalStatePath() { | |
| 126 base::FilePath local_state_path; | |
| 127 PathService::Get(base::DIR_APP_DATA, &local_state_path); | |
| 128 local_state_path = | |
| 129 local_state_path.Append(FILE_PATH_LITERAL("ChromeWebView")); | |
| 130 local_state_path = local_state_path.Append(FILE_PATH_LITERAL("Local State")); | |
| 131 return local_state_path; | |
| 132 } | |
| 133 | |
| 134 void ApplicationContext::SetApplicationLocale(const std::string& locale) { | |
| 135 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_); | |
| 136 application_locale_ = locale; | |
| 137 translate::TranslateDownloadManager::GetInstance()->set_application_locale( | |
| 138 application_locale_); | |
| 139 } | |
| 140 | |
| 141 } // namespace ios_web_view | |
| OLD | NEW |