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

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

Issue 2952403002: [ObjC ARC] Converts ios/chrome/browser/translate:translate to ARC. (Closed)
Patch Set: Created 3 years, 6 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"
(...skipping 19 matching lines...) Expand all
30 #import "ios/chrome/browser/translate/never_translate_infobar_controller.h" 30 #import "ios/chrome/browser/translate/never_translate_infobar_controller.h"
31 #include "ios/chrome/browser/translate/translate_accept_languages_factory.h" 31 #include "ios/chrome/browser/translate/translate_accept_languages_factory.h"
32 #import "ios/chrome/browser/translate/translate_message_infobar_controller.h" 32 #import "ios/chrome/browser/translate/translate_message_infobar_controller.h"
33 #include "ios/chrome/browser/translate/translate_ranker_factory.h" 33 #include "ios/chrome/browser/translate/translate_ranker_factory.h"
34 #include "ios/chrome/browser/translate/translate_service_ios.h" 34 #include "ios/chrome/browser/translate/translate_service_ios.h"
35 #include "ios/chrome/grit/ios_theme_resources.h" 35 #include "ios/chrome/grit/ios_theme_resources.h"
36 #include "ios/web/public/browser_state.h" 36 #include "ios/web/public/browser_state.h"
37 #include "ios/web/public/web_state/web_state.h" 37 #include "ios/web/public/web_state/web_state.h"
38 #include "url/gurl.h" 38 #include "url/gurl.h"
39 39
40 #if !defined(__has_feature) || !__has_feature(objc_arc)
41 #error "This file requires ARC support."
42 #endif
43
40 DEFINE_WEB_STATE_USER_DATA_KEY(ChromeIOSTranslateClient); 44 DEFINE_WEB_STATE_USER_DATA_KEY(ChromeIOSTranslateClient);
41 45
42 ChromeIOSTranslateClient::ChromeIOSTranslateClient(web::WebState* web_state) 46 ChromeIOSTranslateClient::ChromeIOSTranslateClient(web::WebState* web_state)
43 : web::WebStateObserver(web_state), 47 : web::WebStateObserver(web_state),
44 translate_manager_(base::MakeUnique<translate::TranslateManager>( 48 translate_manager_(base::MakeUnique<translate::TranslateManager>(
45 this, 49 this,
46 translate::TranslateRankerFactory::GetForBrowserState( 50 translate::TranslateRankerFactory::GetForBrowserState(
47 ios::ChromeBrowserState::FromBrowserState( 51 ios::ChromeBrowserState::FromBrowserState(
48 web_state->GetBrowserState())), 52 web_state->GetBrowserState())),
49 prefs::kAcceptLanguages)), 53 prefs::kAcceptLanguages)),
(...skipping 18 matching lines...) Expand all
68 return translate_manager_.get(); 72 return translate_manager_.get();
69 } 73 }
70 74
71 // TranslateClient implementation: 75 // TranslateClient implementation:
72 76
73 std::unique_ptr<infobars::InfoBar> ChromeIOSTranslateClient::CreateInfoBar( 77 std::unique_ptr<infobars::InfoBar> ChromeIOSTranslateClient::CreateInfoBar(
74 std::unique_ptr<translate::TranslateInfoBarDelegate> delegate) const { 78 std::unique_ptr<translate::TranslateInfoBarDelegate> delegate) const {
75 translate::TranslateStep step = delegate->translate_step(); 79 translate::TranslateStep step = delegate->translate_step();
76 80
77 std::unique_ptr<InfoBarIOS> infobar(new InfoBarIOS(std::move(delegate))); 81 std::unique_ptr<InfoBarIOS> infobar(new InfoBarIOS(std::move(delegate)));
78 base::scoped_nsobject<InfoBarController> controller; 82 InfoBarController* controller;
79 switch (step) { 83 switch (step) {
80 case translate::TRANSLATE_STEP_AFTER_TRANSLATE: 84 case translate::TRANSLATE_STEP_AFTER_TRANSLATE:
81 controller.reset([[AfterTranslateInfoBarController alloc] 85 controller = [[AfterTranslateInfoBarController alloc]
82 initWithDelegate:infobar.get()]); 86 initWithDelegate:infobar.get()];
83 break; 87 break;
84 case translate::TRANSLATE_STEP_BEFORE_TRANSLATE: 88 case translate::TRANSLATE_STEP_BEFORE_TRANSLATE:
85 controller.reset([[BeforeTranslateInfoBarController alloc] 89 controller = [[BeforeTranslateInfoBarController alloc]
86 initWithDelegate:infobar.get()]); 90 initWithDelegate:infobar.get()];
87 break; 91 break;
88 case translate::TRANSLATE_STEP_NEVER_TRANSLATE: 92 case translate::TRANSLATE_STEP_NEVER_TRANSLATE:
89 controller.reset([[NeverTranslateInfoBarController alloc] 93 controller = [[NeverTranslateInfoBarController alloc]
90 initWithDelegate:infobar.get()]); 94 initWithDelegate:infobar.get()];
91 break; 95 break;
92 case translate::TRANSLATE_STEP_TRANSLATING: 96 case translate::TRANSLATE_STEP_TRANSLATING:
93 case translate::TRANSLATE_STEP_TRANSLATE_ERROR: 97 case translate::TRANSLATE_STEP_TRANSLATE_ERROR:
94 controller.reset([[TranslateMessageInfoBarController alloc] 98 controller = [[TranslateMessageInfoBarController alloc]
95 initWithDelegate:infobar.get()]); 99 initWithDelegate:infobar.get()];
96 break; 100 break;
97 default: 101 default:
98 NOTREACHED(); 102 NOTREACHED();
99 } 103 }
100 infobar->SetController(controller); 104 infobar->SetController(controller);
101 // TODO(crbug.com/703565): remove std::move() once Xcode 9.0+ is required. 105 // TODO(crbug.com/703565): remove std::move() once Xcode 9.0+ is required.
102 return std::move(infobar); 106 return std::move(infobar);
103 } 107 }
104 108
105 void ChromeIOSTranslateClient::RecordTranslateEvent( 109 void ChromeIOSTranslateClient::RecordTranslateEvent(
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 const GURL& report_url) { 174 const GURL& report_url) {
171 NOTREACHED(); 175 NOTREACHED();
172 } 176 }
173 177
174 void ChromeIOSTranslateClient::WebStateDestroyed() { 178 void ChromeIOSTranslateClient::WebStateDestroyed() {
175 // Translation process can be interrupted. 179 // Translation process can be interrupted.
176 // Destroying the TranslateManager now guarantees that it never has to deal 180 // Destroying the TranslateManager now guarantees that it never has to deal
177 // with nullptr WebState. 181 // with nullptr WebState.
178 translate_manager_.reset(); 182 translate_manager_.reset();
179 } 183 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698