cygprofile: increase timeouts to allow showing web contents
[chromium-blink-merge.git] / ios / chrome / browser / translate / translate_accept_languages_factory.cc
blob080f68f8f3c048cc86f2ef0d73bff7f483afd4ce
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.
5 #include "ios/chrome/browser/translate/translate_accept_languages_factory.h"
7 #include "base/prefs/pref_service.h"
8 #include "components/keyed_service/core/keyed_service.h"
9 #include "components/keyed_service/ios/browser_state_dependency_manager.h"
10 #include "components/translate/core/browser/translate_accept_languages.h"
11 #include "ios/chrome/browser/browser_state/browser_state_otr_helper.h"
12 #include "ios/chrome/browser/pref_names.h"
13 #include "ios/public/provider/chrome/browser/browser_state/chrome_browser_state.h"
15 namespace {
17 // TranslateAcceptLanguagesService is a thin container for
18 // TranslateAcceptLanguages to enable associating it with a BrowserState.
19 class TranslateAcceptLanguagesService : public KeyedService {
20 public:
21 explicit TranslateAcceptLanguagesService(PrefService* prefs);
22 ~TranslateAcceptLanguagesService() override;
24 // Returns the associated TranslateAcceptLanguages.
25 translate::TranslateAcceptLanguages& accept_languages() {
26 return accept_languages_;
29 private:
30 translate::TranslateAcceptLanguages accept_languages_;
32 DISALLOW_COPY_AND_ASSIGN(TranslateAcceptLanguagesService);
35 TranslateAcceptLanguagesService::TranslateAcceptLanguagesService(
36 PrefService* prefs)
37 : accept_languages_(prefs, ios::prefs::kAcceptLanguages) {
40 TranslateAcceptLanguagesService::~TranslateAcceptLanguagesService() {
43 } // namespace
45 // static
46 TranslateAcceptLanguagesFactory*
47 TranslateAcceptLanguagesFactory::GetInstance() {
48 return Singleton<TranslateAcceptLanguagesFactory>::get();
51 // static
52 translate::TranslateAcceptLanguages*
53 TranslateAcceptLanguagesFactory::GetForBrowserState(
54 ios::ChromeBrowserState* state) {
55 TranslateAcceptLanguagesService* service =
56 static_cast<TranslateAcceptLanguagesService*>(
57 GetInstance()->GetServiceForBrowserState(state, true));
58 return &service->accept_languages();
61 TranslateAcceptLanguagesFactory::TranslateAcceptLanguagesFactory()
62 : BrowserStateKeyedServiceFactory(
63 "TranslateAcceptLanguagesService",
64 BrowserStateDependencyManager::GetInstance()) {
67 TranslateAcceptLanguagesFactory::~TranslateAcceptLanguagesFactory() {
70 scoped_ptr<KeyedService>
71 TranslateAcceptLanguagesFactory::BuildServiceInstanceFor(
72 web::BrowserState* context) const {
73 ios::ChromeBrowserState* browser_state =
74 ios::ChromeBrowserState::FromBrowserState(context);
75 return make_scoped_ptr(
76 new TranslateAcceptLanguagesService(browser_state->GetPrefs()));
79 web::BrowserState* TranslateAcceptLanguagesFactory::GetBrowserStateToUse(
80 web::BrowserState* context) const {
81 return GetBrowserStateRedirectedInIncognito(context);