| 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/chrome/browser/translate/chrome_ios_translate_client.h" | 5 #include "ios/chrome/browser/translate/chrome_ios_translate_client.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/memory/ptr_util.h" | 11 #include "base/memory/ptr_util.h" |
| 12 #include "components/infobars/core/infobar.h" | 12 #include "components/infobars/core/infobar.h" |
| 13 #include "components/prefs/pref_service.h" | 13 #include "components/prefs/pref_service.h" |
| 14 #include "components/translate/core/browser/page_translated_details.h" | 14 #include "components/translate/core/browser/page_translated_details.h" |
| 15 #include "components/translate/core/browser/translate_accept_languages.h" | 15 #include "components/translate/core/browser/translate_accept_languages.h" |
| 16 #include "components/translate/core/browser/translate_infobar_delegate.h" | 16 #include "components/translate/core/browser/translate_infobar_delegate.h" |
| 17 #include "components/translate/core/browser/translate_manager.h" | 17 #include "components/translate/core/browser/translate_manager.h" |
| 18 #include "components/translate/core/browser/translate_prefs.h" | 18 #include "components/translate/core/browser/translate_prefs.h" |
| 19 #include "components/translate/core/browser/translate_step.h" | 19 #include "components/translate/core/browser/translate_step.h" |
| 20 #include "ios/chrome/browser/browser_state/chrome_browser_state.h" | 20 #include "ios/chrome/browser/browser_state/chrome_browser_state.h" |
| 21 #include "ios/chrome/browser/infobars/infobar.h" | 21 #include "ios/chrome/browser/infobars/infobar.h" |
| 22 #include "ios/chrome/browser/infobars/infobar_controller.h" | 22 #include "ios/chrome/browser/infobars/infobar_controller.h" |
| 23 #include "ios/chrome/browser/infobars/infobar_manager_impl.h" | 23 #include "ios/chrome/browser/infobars/infobar_manager_impl.h" |
| 24 #include "ios/chrome/browser/pref_names.h" | 24 #include "ios/chrome/browser/pref_names.h" |
| 25 #import "ios/chrome/browser/translate/after_translate_infobar_controller.h" | 25 #import "ios/chrome/browser/translate/after_translate_infobar_controller.h" |
| 26 #import "ios/chrome/browser/translate/before_translate_infobar_controller.h" | 26 #import "ios/chrome/browser/translate/before_translate_infobar_controller.h" |
| 27 #include "ios/chrome/browser/translate/language_model_factory.h" |
| 27 #import "ios/chrome/browser/translate/never_translate_infobar_controller.h" | 28 #import "ios/chrome/browser/translate/never_translate_infobar_controller.h" |
| 28 #include "ios/chrome/browser/translate/translate_accept_languages_factory.h" | 29 #include "ios/chrome/browser/translate/translate_accept_languages_factory.h" |
| 29 #import "ios/chrome/browser/translate/translate_message_infobar_controller.h" | 30 #import "ios/chrome/browser/translate/translate_message_infobar_controller.h" |
| 30 #include "ios/chrome/browser/translate/translate_ranker_factory.h" | 31 #include "ios/chrome/browser/translate/translate_ranker_factory.h" |
| 31 #include "ios/chrome/browser/translate/translate_service_ios.h" | 32 #include "ios/chrome/browser/translate/translate_service_ios.h" |
| 32 #include "ios/chrome/grit/ios_theme_resources.h" | 33 #include "ios/chrome/grit/ios_theme_resources.h" |
| 33 #include "ios/web/public/browser_state.h" | 34 #include "ios/web/public/browser_state.h" |
| 34 #include "ios/web/public/web_state/web_state.h" | 35 #include "ios/web/public/web_state/web_state.h" |
| 35 #include "url/gurl.h" | 36 #include "url/gurl.h" |
| 36 | 37 |
| 37 DEFINE_WEB_STATE_USER_DATA_KEY(ChromeIOSTranslateClient); | 38 DEFINE_WEB_STATE_USER_DATA_KEY(ChromeIOSTranslateClient); |
| 38 | 39 |
| 39 ChromeIOSTranslateClient::ChromeIOSTranslateClient(web::WebState* web_state) | 40 ChromeIOSTranslateClient::ChromeIOSTranslateClient(web::WebState* web_state) |
| 40 : web::WebStateObserver(web_state), | 41 : web::WebStateObserver(web_state), |
| 41 translate_manager_(base::MakeUnique<translate::TranslateManager>( | 42 translate_manager_(base::MakeUnique<translate::TranslateManager>( |
| 42 this, | 43 this, |
| 43 translate::TranslateRankerFactory::GetForBrowserState( | 44 translate::TranslateRankerFactory::GetForBrowserState( |
| 44 ios::ChromeBrowserState::FromBrowserState( | 45 ios::ChromeBrowserState::FromBrowserState( |
| 45 web_state->GetBrowserState())), | 46 web_state->GetBrowserState())), |
| 46 prefs::kAcceptLanguages)), | 47 prefs::kAcceptLanguages)), |
| 47 translate_driver_(web_state, | 48 translate_driver_(web_state, |
| 48 web_state->GetNavigationManager(), | 49 web_state->GetNavigationManager(), |
| 49 translate_manager_.get()) {} | 50 translate_manager_.get(), |
| 51 LanguageModelFactory::GetForBrowserState( |
| 52 ios::ChromeBrowserState::FromBrowserState( |
| 53 web_state->GetBrowserState()))) {} |
| 50 | 54 |
| 51 ChromeIOSTranslateClient::~ChromeIOSTranslateClient() { | 55 ChromeIOSTranslateClient::~ChromeIOSTranslateClient() { |
| 52 } | 56 } |
| 53 | 57 |
| 54 // static | 58 // static |
| 55 std::unique_ptr<translate::TranslatePrefs> | 59 std::unique_ptr<translate::TranslatePrefs> |
| 56 ChromeIOSTranslateClient::CreateTranslatePrefs(PrefService* prefs) { | 60 ChromeIOSTranslateClient::CreateTranslatePrefs(PrefService* prefs) { |
| 57 return std::unique_ptr<translate::TranslatePrefs>( | 61 return std::unique_ptr<translate::TranslatePrefs>( |
| 58 new translate::TranslatePrefs(prefs, prefs::kAcceptLanguages, nullptr)); | 62 new translate::TranslatePrefs(prefs, prefs::kAcceptLanguages, nullptr)); |
| 59 } | 63 } |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 154 const GURL& report_url) { | 158 const GURL& report_url) { |
| 155 NOTREACHED(); | 159 NOTREACHED(); |
| 156 } | 160 } |
| 157 | 161 |
| 158 void ChromeIOSTranslateClient::WebStateDestroyed() { | 162 void ChromeIOSTranslateClient::WebStateDestroyed() { |
| 159 // Translation process can be interrupted. | 163 // Translation process can be interrupted. |
| 160 // Destroying the TranslateManager now guarantees that it never has to deal | 164 // Destroying the TranslateManager now guarantees that it never has to deal |
| 161 // with nullptr WebState. | 165 // with nullptr WebState. |
| 162 translate_manager_.reset(); | 166 translate_manager_.reset(); |
| 163 } | 167 } |
| OLD | NEW |