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_impl.h" | |
6 | |
7 #include "base/command_line.h" | |
8 #include "base/path_service.h" | |
9 #include "base/tracked_objects.h" | |
10 #include "components/flags_ui/pref_service_flags_storage.h" | |
11 #include "components/net_log/chrome_net_log.h" | |
12 #include "components/prefs/json_pref_store.h" | |
13 #include "components/prefs/pref_registry_simple.h" | |
14 #include "components/prefs/pref_service.h" | |
15 #include "components/prefs/pref_service_factory.h" | |
16 #include "components/proxy_config/pref_proxy_config_tracker_impl.h" | |
17 #include "components/ssl_config/ssl_config_service_manager.h" | |
18 #include "components/translate/core/browser/translate_download_manager.h" | |
19 #include "ios/web/public/web_thread.h" | |
20 #include "ios/web_view/internal/app/web_view_io_thread.h" | |
21 #include "net/socket/client_socket_pool_manager.h" | |
22 | |
23 base::FilePath ApplicationContextImpl::LocalStatePath() { | |
Eugene But (OOO till 7-30)
2017/05/18 23:54:55
Do you want to reorder the method to follow the or
michaeldo
2017/05/23 22:38:36
Done.
| |
24 base::FilePath local_state_path; | |
25 PathService::Get(base::DIR_APP_DATA, &local_state_path); | |
26 local_state_path = | |
27 local_state_path.Append(FILE_PATH_LITERAL("ChromeWebView")); | |
28 local_state_path = local_state_path.Append(FILE_PATH_LITERAL("Local State")); | |
29 return local_state_path; | |
30 } | |
31 | |
32 ApplicationContextImpl::ApplicationContextImpl( | |
33 const base::CommandLine& command_line, | |
34 const std::string& locale) | |
35 : local_state_task_runner_(JsonPrefStore::GetTaskRunnerForFile( | |
36 LocalStatePath(), | |
37 web::WebThread::GetBlockingPool())), | |
38 created_local_state_(false) { | |
39 DCHECK(!GetApplicationContext()); | |
40 SetApplicationContext(this); | |
41 | |
42 net_log_.reset(new net_log::ChromeNetLog( | |
43 base::FilePath(), net::NetLogCaptureMode::Default(), | |
44 command_line.GetCommandLineString(), std::string())); | |
45 | |
46 SetApplicationLocale(locale); | |
47 } | |
48 | |
49 ApplicationContextImpl::~ApplicationContextImpl() { | |
50 DCHECK_EQ(this, GetApplicationContext()); | |
51 tracked_objects::ThreadData::EnsureCleanupWasCalled(4); | |
Hiroshi Ichikawa
2017/05/19 02:37:51
Why is this 4?
michaeldo
2017/05/23 22:38:36
The 4 is for the threads that get spun up, but the
Hiroshi Ichikawa
2017/05/24 07:25:46
Thanks! Feel free to go ahead without waiting for
| |
52 SetApplicationContext(nullptr); | |
53 } | |
54 | |
55 void ApplicationContextImpl::PreCreateThreads() { | |
56 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_); | |
57 web_view_io_thread_.reset(new WebViewIOThread(GetLocalState(), GetNetLog())); | |
Eugene But (OOO till 7-30)
2017/05/18 23:54:55
s/new/MakeUnique ?
michaeldo
2017/05/23 22:38:36
Done.
| |
58 } | |
59 | |
60 void ApplicationContextImpl::StartTearDown() { | |
61 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_); | |
62 // TODO(crbug.com/723854): Commit prefs when entering background. | |
63 if (local_state_) { | |
64 local_state_->CommitPendingWrite(); | |
65 } | |
66 } | |
67 | |
68 void ApplicationContextImpl::PostDestroyThreads() { | |
69 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_); | |
70 // Resets associated state right after actual thread is stopped as | |
71 // WebViewIOThread::Globals cleanup happens in CleanUp on the IO | |
72 // thread, i.e. as the thread exits its message loop. | |
73 // | |
74 // This is important because in various places, the WebViewIOThread | |
75 // object being NULL is considered synonymous with the IO thread | |
Eugene But (OOO till 7-30)
2017/05/18 23:54:55
nit: s/NULL/null
michaeldo
2017/05/23 22:38:36
Done.
| |
76 // having stopped. | |
77 web_view_io_thread_.reset(); | |
78 } | |
79 | |
80 PrefService* ApplicationContextImpl::GetLocalState() { | |
81 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_); | |
82 if (!created_local_state_) | |
83 CreateLocalState(); | |
Eugene But (OOO till 7-30)
2017/05/18 23:54:54
Do you want to fold |CreateLocalState| into this m
michaeldo
2017/05/23 22:38:36
Yes, I had the same thought. Done.
| |
84 return local_state_.get(); | |
85 } | |
86 | |
87 net::URLRequestContextGetter* | |
88 ApplicationContextImpl::GetSystemURLRequestContext() { | |
89 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_); | |
90 return web_view_io_thread_->system_url_request_context_getter(); | |
91 } | |
92 | |
93 const std::string& ApplicationContextImpl::GetApplicationLocale() { | |
94 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_); | |
95 DCHECK(!application_locale_.empty()); | |
96 return application_locale_; | |
97 } | |
98 | |
99 net_log::ChromeNetLog* ApplicationContextImpl::GetNetLog() { | |
100 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_); | |
101 return net_log_.get(); | |
102 } | |
103 | |
104 WebViewIOThread* ApplicationContextImpl::GetWebViewIOThread() { | |
105 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_); | |
106 DCHECK(web_view_io_thread_.get()); | |
107 return web_view_io_thread_.get(); | |
108 } | |
109 | |
110 void ApplicationContextImpl::SetApplicationLocale(const std::string& locale) { | |
111 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_); | |
112 application_locale_ = locale; | |
113 translate::TranslateDownloadManager::GetInstance()->set_application_locale( | |
114 application_locale_); | |
115 } | |
116 | |
117 void ApplicationContextImpl::CreateLocalState() { | |
118 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_); | |
119 DCHECK(!created_local_state_ && !local_state_); | |
120 created_local_state_ = true; | |
121 | |
122 // Register local state preferences. | |
123 scoped_refptr<PrefRegistrySimple> pref_registry(new PrefRegistrySimple); | |
Eugene But (OOO till 7-30)
2017/05/18 23:54:55
s/new/MakeUnique ?
michaeldo
2017/05/23 22:38:36
I can't use MakeUnique because the destructor is p
| |
124 flags_ui::PrefServiceFlagsStorage::RegisterPrefs(pref_registry.get()); | |
125 PrefProxyConfigTrackerImpl::RegisterPrefs(pref_registry.get()); | |
126 ssl_config::SSLConfigServiceManager::RegisterPrefs(pref_registry.get()); | |
127 | |
128 scoped_refptr<PersistentPrefStore> user_pref_store = | |
129 new JsonPrefStore(LocalStatePath(), local_state_task_runner_, nullptr); | |
130 | |
131 PrefServiceFactory factory; | |
132 factory.set_user_prefs(user_pref_store); | |
133 local_state_ = factory.Create(pref_registry.get()); | |
134 | |
135 net::ClientSocketPoolManager::set_max_sockets_per_proxy_server( | |
136 net::HttpNetworkSession::NORMAL_SOCKET_POOL, | |
137 std::max(std::min<int>(net::kDefaultMaxSocketsPerProxyServer, 99), | |
Hiroshi Ichikawa
2017/05/19 02:37:51
Any reason to cap this value with 99? Maybe define
michaeldo
2017/05/23 22:38:36
No reason except consistency, which I agree is a b
Hiroshi Ichikawa
2017/05/24 07:25:46
Can you maybe just leave a comment saying this is
| |
138 net::ClientSocketPoolManager::max_sockets_per_group( | |
139 net::HttpNetworkSession::NORMAL_SOCKET_POOL))); | |
140 } | |
OLD | NEW |