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

Side by Side Diff: ios/chrome/browser/translate/chrome_ios_translate_client.mm

Issue 2565873002: [translate] Add translate ranker model loader. (Closed)
Patch Set: comments from hamelphi Created 3 years, 11 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
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 "components/infobars/core/infobar.h" 11 #include "components/infobars/core/infobar.h"
12 #include "components/prefs/pref_service.h" 12 #include "components/prefs/pref_service.h"
13 #include "components/translate/core/browser/page_translated_details.h" 13 #include "components/translate/core/browser/page_translated_details.h"
14 #include "components/translate/core/browser/translate_accept_languages.h" 14 #include "components/translate/core/browser/translate_accept_languages.h"
15 #include "components/translate/core/browser/translate_infobar_delegate.h" 15 #include "components/translate/core/browser/translate_infobar_delegate.h"
16 #include "components/translate/core/browser/translate_manager.h" 16 #include "components/translate/core/browser/translate_manager.h"
17 #include "components/translate/core/browser/translate_prefs.h" 17 #include "components/translate/core/browser/translate_prefs.h"
18 #include "components/translate/core/browser/translate_step.h" 18 #include "components/translate/core/browser/translate_step.h"
19 #include "ios/chrome/browser/browser_state/chrome_browser_state.h" 19 #include "ios/chrome/browser/browser_state/chrome_browser_state.h"
20 #include "ios/chrome/browser/infobars/infobar.h" 20 #include "ios/chrome/browser/infobars/infobar.h"
21 #include "ios/chrome/browser/infobars/infobar_controller.h" 21 #include "ios/chrome/browser/infobars/infobar_controller.h"
22 #include "ios/chrome/browser/infobars/infobar_manager_impl.h" 22 #include "ios/chrome/browser/infobars/infobar_manager_impl.h"
23 #include "ios/chrome/browser/pref_names.h" 23 #include "ios/chrome/browser/pref_names.h"
24 #import "ios/chrome/browser/translate/after_translate_infobar_controller.h" 24 #import "ios/chrome/browser/translate/after_translate_infobar_controller.h"
25 #import "ios/chrome/browser/translate/before_translate_infobar_controller.h" 25 #import "ios/chrome/browser/translate/before_translate_infobar_controller.h"
26 #import "ios/chrome/browser/translate/never_translate_infobar_controller.h" 26 #import "ios/chrome/browser/translate/never_translate_infobar_controller.h"
27 #include "ios/chrome/browser/translate/translate_accept_languages_factory.h" 27 #include "ios/chrome/browser/translate/translate_accept_languages_factory.h"
28 #import "ios/chrome/browser/translate/translate_message_infobar_controller.h" 28 #import "ios/chrome/browser/translate/translate_message_infobar_controller.h"
29 #include "ios/chrome/browser/translate/translate_ranker_factory.h"
29 #include "ios/chrome/browser/translate/translate_service_ios.h" 30 #include "ios/chrome/browser/translate/translate_service_ios.h"
30 #include "ios/chrome/grit/ios_theme_resources.h" 31 #include "ios/chrome/grit/ios_theme_resources.h"
31 #include "ios/web/public/browser_state.h" 32 #include "ios/web/public/browser_state.h"
32 #include "ios/web/public/web_state/web_state.h" 33 #include "ios/web/public/web_state/web_state.h"
33 #include "url/gurl.h" 34 #include "url/gurl.h"
34 35
35 DEFINE_WEB_STATE_USER_DATA_KEY(ChromeIOSTranslateClient); 36 DEFINE_WEB_STATE_USER_DATA_KEY(ChromeIOSTranslateClient);
36 37
37 ChromeIOSTranslateClient::ChromeIOSTranslateClient(web::WebState* web_state) 38 ChromeIOSTranslateClient::ChromeIOSTranslateClient(web::WebState* web_state)
38 : web::WebStateObserver(web_state), 39 : web::WebStateObserver(web_state),
39 translate_manager_( 40 translate_manager_(new translate::TranslateManager(
40 new translate::TranslateManager(this, prefs::kAcceptLanguages)), 41 this,
42 translate::TranslateRankerFactory::GetInstance()->GetForBrowserState(
groby-ooo-7-16 2017/01/23 21:41:57 Will iOS actually utilize ranker?
Roger McFarlane (Chromium) 2017/02/08 23:08:14 That's the plan. Should it not?
43 ios::ChromeBrowserState::FromBrowserState(
44 web_state->GetBrowserState())),
45 prefs::kAcceptLanguages)),
41 translate_driver_(web_state, 46 translate_driver_(web_state,
42 web_state->GetNavigationManager(), 47 web_state->GetNavigationManager(),
43 translate_manager_.get()) {} 48 translate_manager_.get()) {}
44 49
45 ChromeIOSTranslateClient::~ChromeIOSTranslateClient() { 50 ChromeIOSTranslateClient::~ChromeIOSTranslateClient() {
46 } 51 }
47 52
48 // static 53 // static
49 std::unique_ptr<translate::TranslatePrefs> 54 std::unique_ptr<translate::TranslatePrefs>
50 ChromeIOSTranslateClient::CreateTranslatePrefs(PrefService* prefs) { 55 ChromeIOSTranslateClient::CreateTranslatePrefs(PrefService* prefs) {
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 const GURL& report_url) { 152 const GURL& report_url) {
148 NOTREACHED(); 153 NOTREACHED();
149 } 154 }
150 155
151 void ChromeIOSTranslateClient::WebStateDestroyed() { 156 void ChromeIOSTranslateClient::WebStateDestroyed() {
152 // Translation process can be interrupted. 157 // Translation process can be interrupted.
153 // Destroying the TranslateManager now guarantees that it never has to deal 158 // Destroying the TranslateManager now guarantees that it never has to deal
154 // with nullptr WebState. 159 // with nullptr WebState.
155 translate_manager_.reset(); 160 translate_manager_.reset();
156 } 161 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698