Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(232)

Side by Side Diff: ios/web_view/internal/criwv_browser_state.mm

Issue 2715043002: Replace prefix of ios/web_view C++ classes. (Closed)
Patch Set: Respond to comments. Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "ios/web_view/internal/criwv_browser_state.h"
6
7 #include <memory>
8
9 #include "base/base_paths.h"
10 #include "base/files/file_path.h"
11 #include "base/message_loop/message_loop.h"
12 #include "base/path_service.h"
13 #include "base/threading/thread_restrictions.h"
14 #include "components/pref_registry/pref_registry_syncable.h"
15 #include "components/prefs/json_pref_store.h"
16 #include "components/prefs/pref_filter.h"
17 #include "components/prefs/pref_service_factory.h"
18 #include "components/translate/core/browser/translate_prefs.h"
19 #include "components/translate/core/common/translate_pref_names.h"
20 #include "ios/web/public/web_thread.h"
21 #include "ios/web_view/internal/criwv_url_request_context_getter.h"
22 #include "ios/web_view/internal/pref_names.h"
23 #include "ui/base/l10n/l10n_util_mac.h"
24
25 #if !defined(__has_feature) || !__has_feature(objc_arc)
26 #error "This file requires ARC support."
27 #endif
28
29 namespace {
30 const char kPreferencesFilename[] = FILE_PATH_LITERAL("Preferences");
31 }
32
33 namespace ios_web_view {
34
35 CRIWVBrowserState::CRIWVBrowserState(bool off_the_record)
36 : web::BrowserState(), off_the_record_(off_the_record) {
37 CHECK(PathService::Get(base::DIR_APP_DATA, &path_));
38
39 request_context_getter_ = new CRIWVURLRequestContextGetter(
40 GetStatePath(),
41 web::WebThread::GetTaskRunnerForThread(web::WebThread::IO),
42 web::WebThread::GetTaskRunnerForThread(web::WebThread::FILE),
43 web::WebThread::GetTaskRunnerForThread(web::WebThread::CACHE));
44
45 // Initialize prefs.
46 scoped_refptr<user_prefs::PrefRegistrySyncable> pref_registry =
47 new user_prefs::PrefRegistrySyncable;
48 RegisterPrefs(pref_registry.get());
49 scoped_refptr<base::SequencedTaskRunner> sequenced_task_runner =
50 JsonPrefStore::GetTaskRunnerForFile(path_,
51 web::WebThread::GetBlockingPool());
52
53 scoped_refptr<PersistentPrefStore> user_pref_store = new JsonPrefStore(
54 path_.Append(kPreferencesFilename), sequenced_task_runner, nullptr);
55
56 PrefServiceFactory factory;
57 factory.set_user_prefs(user_pref_store);
58 prefs_ = factory.Create(pref_registry.get());
59 }
60
61 CRIWVBrowserState::~CRIWVBrowserState() {}
62
63 PrefService* CRIWVBrowserState::GetPrefs() {
64 DCHECK(prefs_);
65 return prefs_.get();
66 }
67
68 // static
69 CRIWVBrowserState* CRIWVBrowserState::FromBrowserState(
70 web::BrowserState* browser_state) {
71 return static_cast<CRIWVBrowserState*>(browser_state);
72 }
73
74 bool CRIWVBrowserState::IsOffTheRecord() const {
75 return off_the_record_;
76 }
77
78 base::FilePath CRIWVBrowserState::GetStatePath() const {
79 return path_;
80 }
81
82 net::URLRequestContextGetter* CRIWVBrowserState::GetRequestContext() {
83 return request_context_getter_.get();
84 }
85
86 void CRIWVBrowserState::RegisterPrefs(
87 user_prefs::PrefRegistrySyncable* pref_registry) {
88 // 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
90 // the HTTP header.
91 pref_registry->RegisterStringPref(prefs::kAcceptLanguages,
92 l10n_util::GetLocaleOverride());
93 pref_registry->RegisterBooleanPref(prefs::kEnableTranslate, true);
94 translate::TranslatePrefs::RegisterProfilePrefs(pref_registry);
95 }
96
97 } // namespace ios_web_view
OLDNEW
« no previous file with comments | « ios/web_view/internal/criwv_browser_state.h ('k') | ios/web_view/internal/criwv_network_delegate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698