| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ios/web_view/internal/web_view_browser_state.h" | 5 #include "ios/web_view/internal/web_view_browser_state.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "base/base_paths.h" | 9 #include "base/base_paths.h" |
| 10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 #endif | 27 #endif |
| 28 | 28 |
| 29 namespace { | 29 namespace { |
| 30 const char kPreferencesFilename[] = FILE_PATH_LITERAL("Preferences"); | 30 const char kPreferencesFilename[] = FILE_PATH_LITERAL("Preferences"); |
| 31 } | 31 } |
| 32 | 32 |
| 33 namespace ios_web_view { | 33 namespace ios_web_view { |
| 34 | 34 |
| 35 WebViewBrowserState::WebViewBrowserState(bool off_the_record) | 35 WebViewBrowserState::WebViewBrowserState(bool off_the_record) |
| 36 : web::BrowserState(), off_the_record_(off_the_record) { | 36 : web::BrowserState(), off_the_record_(off_the_record) { |
| 37 // IO access is required to setup the browser state. In Chrome, this is |
| 38 // already allowed during thread startup. However, startup time of |
| 39 // ChromeWebView is not predetermined, so IO access is temporarily allowed. |
| 40 bool wasIOAllowed = base::ThreadRestrictions::SetIOAllowed(true); |
| 41 |
| 37 CHECK(PathService::Get(base::DIR_APP_DATA, &path_)); | 42 CHECK(PathService::Get(base::DIR_APP_DATA, &path_)); |
| 38 | 43 |
| 39 request_context_getter_ = new WebViewURLRequestContextGetter( | 44 request_context_getter_ = new WebViewURLRequestContextGetter( |
| 40 GetStatePath(), | 45 GetStatePath(), |
| 41 web::WebThread::GetTaskRunnerForThread(web::WebThread::IO), | 46 web::WebThread::GetTaskRunnerForThread(web::WebThread::IO), |
| 42 web::WebThread::GetTaskRunnerForThread(web::WebThread::FILE), | 47 web::WebThread::GetTaskRunnerForThread(web::WebThread::FILE), |
| 43 web::WebThread::GetTaskRunnerForThread(web::WebThread::CACHE)); | 48 web::WebThread::GetTaskRunnerForThread(web::WebThread::CACHE)); |
| 44 | 49 |
| 45 // Initialize prefs. | 50 // Initialize prefs. |
| 46 scoped_refptr<user_prefs::PrefRegistrySyncable> pref_registry = | 51 scoped_refptr<user_prefs::PrefRegistrySyncable> pref_registry = |
| 47 new user_prefs::PrefRegistrySyncable; | 52 new user_prefs::PrefRegistrySyncable; |
| 48 RegisterPrefs(pref_registry.get()); | 53 RegisterPrefs(pref_registry.get()); |
| 49 scoped_refptr<base::SequencedTaskRunner> sequenced_task_runner = | 54 scoped_refptr<base::SequencedTaskRunner> sequenced_task_runner = |
| 50 JsonPrefStore::GetTaskRunnerForFile(path_, | 55 JsonPrefStore::GetTaskRunnerForFile(path_, |
| 51 web::WebThread::GetBlockingPool()); | 56 web::WebThread::GetBlockingPool()); |
| 52 | 57 |
| 53 scoped_refptr<PersistentPrefStore> user_pref_store = new JsonPrefStore( | 58 scoped_refptr<PersistentPrefStore> user_pref_store = new JsonPrefStore( |
| 54 path_.Append(kPreferencesFilename), sequenced_task_runner, nullptr); | 59 path_.Append(kPreferencesFilename), sequenced_task_runner, nullptr); |
| 55 | 60 |
| 56 PrefServiceFactory factory; | 61 PrefServiceFactory factory; |
| 57 factory.set_user_prefs(user_pref_store); | 62 factory.set_user_prefs(user_pref_store); |
| 58 prefs_ = factory.Create(pref_registry.get()); | 63 prefs_ = factory.Create(pref_registry.get()); |
| 64 |
| 65 base::ThreadRestrictions::SetIOAllowed(wasIOAllowed); |
| 59 } | 66 } |
| 60 | 67 |
| 61 WebViewBrowserState::~WebViewBrowserState() = default; | 68 WebViewBrowserState::~WebViewBrowserState() = default; |
| 62 | 69 |
| 63 PrefService* WebViewBrowserState::GetPrefs() { | 70 PrefService* WebViewBrowserState::GetPrefs() { |
| 64 DCHECK(prefs_); | 71 DCHECK(prefs_); |
| 65 return prefs_.get(); | 72 return prefs_.get(); |
| 66 } | 73 } |
| 67 | 74 |
| 68 // static | 75 // static |
| (...skipping 19 matching lines...) Expand all Loading... |
| 88 // TODO(crbug.com/679895): Find a good value for the kAcceptLanguages pref. | 95 // TODO(crbug.com/679895): Find a good value for the kAcceptLanguages pref. |
| 89 // TODO(crbug.com/679895): Pass this value to the network stack somehow, for | 96 // TODO(crbug.com/679895): Pass this value to the network stack somehow, for |
| 90 // the HTTP header. | 97 // the HTTP header. |
| 91 pref_registry->RegisterStringPref(prefs::kAcceptLanguages, | 98 pref_registry->RegisterStringPref(prefs::kAcceptLanguages, |
| 92 l10n_util::GetLocaleOverride()); | 99 l10n_util::GetLocaleOverride()); |
| 93 pref_registry->RegisterBooleanPref(prefs::kEnableTranslate, true); | 100 pref_registry->RegisterBooleanPref(prefs::kEnableTranslate, true); |
| 94 translate::TranslatePrefs::RegisterProfilePrefs(pref_registry); | 101 translate::TranslatePrefs::RegisterProfilePrefs(pref_registry); |
| 95 } | 102 } |
| 96 | 103 |
| 97 } // namespace ios_web_view | 104 } // namespace ios_web_view |
| OLD | NEW |