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

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

Issue 2943343003: implement ios for translate event. (Closed)
Patch Set: apply switch as well 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
« no previous file with comments | « ios/chrome/browser/translate/BUILD.gn ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/feature_list.h"
10 #include "base/logging.h" 11 #include "base/logging.h"
11 #include "base/memory/ptr_util.h" 12 #include "base/memory/ptr_util.h"
12 #include "components/infobars/core/infobar.h" 13 #include "components/infobars/core/infobar.h"
13 #include "components/metrics/proto/translate_event.pb.h" 14 #include "components/metrics/proto/translate_event.pb.h"
14 #include "components/prefs/pref_service.h" 15 #include "components/prefs/pref_service.h"
16 #include "components/sync/driver/sync_driver_switches.h"
17 #include "components/sync/protocol/user_event_specifics.pb.h"
18 #include "components/sync/user_events/user_event_service.h"
15 #include "components/translate/core/browser/page_translated_details.h" 19 #include "components/translate/core/browser/page_translated_details.h"
16 #include "components/translate/core/browser/translate_accept_languages.h" 20 #include "components/translate/core/browser/translate_accept_languages.h"
17 #include "components/translate/core/browser/translate_infobar_delegate.h" 21 #include "components/translate/core/browser/translate_infobar_delegate.h"
18 #include "components/translate/core/browser/translate_manager.h" 22 #include "components/translate/core/browser/translate_manager.h"
19 #include "components/translate/core/browser/translate_prefs.h" 23 #include "components/translate/core/browser/translate_prefs.h"
20 #include "components/translate/core/browser/translate_step.h" 24 #include "components/translate/core/browser/translate_step.h"
25 #include "components/translate/core/common/translation_logging_helper.h"
21 #include "ios/chrome/browser/browser_state/chrome_browser_state.h" 26 #include "ios/chrome/browser/browser_state/chrome_browser_state.h"
22 #include "ios/chrome/browser/infobars/infobar.h" 27 #include "ios/chrome/browser/infobars/infobar.h"
23 #include "ios/chrome/browser/infobars/infobar_controller.h" 28 #include "ios/chrome/browser/infobars/infobar_controller.h"
24 #include "ios/chrome/browser/infobars/infobar_manager_impl.h" 29 #include "ios/chrome/browser/infobars/infobar_manager_impl.h"
25 #include "ios/chrome/browser/pref_names.h" 30 #include "ios/chrome/browser/pref_names.h"
31 #import "ios/chrome/browser/sync/ios_user_event_service_factory.h"
26 #import "ios/chrome/browser/translate/after_translate_infobar_controller.h" 32 #import "ios/chrome/browser/translate/after_translate_infobar_controller.h"
27 #import "ios/chrome/browser/translate/before_translate_infobar_controller.h" 33 #import "ios/chrome/browser/translate/before_translate_infobar_controller.h"
28 #include "ios/chrome/browser/translate/language_model_factory.h" 34 #include "ios/chrome/browser/translate/language_model_factory.h"
29 #import "ios/chrome/browser/translate/never_translate_infobar_controller.h" 35 #import "ios/chrome/browser/translate/never_translate_infobar_controller.h"
30 #include "ios/chrome/browser/translate/translate_accept_languages_factory.h" 36 #include "ios/chrome/browser/translate/translate_accept_languages_factory.h"
31 #import "ios/chrome/browser/translate/translate_message_infobar_controller.h" 37 #import "ios/chrome/browser/translate/translate_message_infobar_controller.h"
32 #include "ios/chrome/browser/translate/translate_ranker_factory.h" 38 #include "ios/chrome/browser/translate/translate_ranker_factory.h"
33 #include "ios/chrome/browser/translate/translate_service_ios.h" 39 #include "ios/chrome/browser/translate/translate_service_ios.h"
34 #include "ios/chrome/grit/ios_theme_resources.h" 40 #include "ios/chrome/grit/ios_theme_resources.h"
35 #include "ios/web/public/browser_state.h" 41 #include "ios/web/public/browser_state.h"
42 #include "ios/web/public/navigation_item.h"
43 #include "ios/web/public/navigation_manager.h"
36 #include "ios/web/public/web_state/web_state.h" 44 #include "ios/web/public/web_state/web_state.h"
37 #include "url/gurl.h" 45 #include "url/gurl.h"
38 46
39 DEFINE_WEB_STATE_USER_DATA_KEY(ChromeIOSTranslateClient); 47 DEFINE_WEB_STATE_USER_DATA_KEY(ChromeIOSTranslateClient);
40 48
41 ChromeIOSTranslateClient::ChromeIOSTranslateClient(web::WebState* web_state) 49 ChromeIOSTranslateClient::ChromeIOSTranslateClient(web::WebState* web_state)
42 : web::WebStateObserver(web_state), 50 : web::WebStateObserver(web_state),
43 translate_manager_(base::MakeUnique<translate::TranslateManager>( 51 translate_manager_(base::MakeUnique<translate::TranslateManager>(
44 this, 52 this,
45 translate::TranslateRankerFactory::GetForBrowserState( 53 translate::TranslateRankerFactory::GetForBrowserState(
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 break; 103 break;
96 default: 104 default:
97 NOTREACHED(); 105 NOTREACHED();
98 } 106 }
99 infobar->SetController(controller); 107 infobar->SetController(controller);
100 // TODO(crbug.com/703565): remove std::move() once Xcode 9.0+ is required. 108 // TODO(crbug.com/703565): remove std::move() once Xcode 9.0+ is required.
101 return std::move(infobar); 109 return std::move(infobar);
102 } 110 }
103 111
104 void ChromeIOSTranslateClient::RecordTranslateEvent( 112 void ChromeIOSTranslateClient::RecordTranslateEvent(
105 const metrics::TranslateEventProto&) { 113 const metrics::TranslateEventProto& translate_event) {
106 // TODO(crbug.com/728491): Implementing gaia-keyed logging. 114 if (!base::FeatureList::IsEnabled(switches::kSyncUserTranslationEvents))
115 return;
116
117 syncer::UserEventService* const user_event_service =
118 IOSUserEventServiceFactory::GetForBrowserState(
119 ios::ChromeBrowserState::FromBrowserState(
120 web_state()->GetBrowserState()));
121 const auto* item =
napper 2017/06/27 01:29:58 const auto* const
renjieliu1 2017/06/27 01:54:59 Done.
122 web_state()->GetNavigationManager()->GetLastCommittedItem();
123
124 // If entry is null, we don't record the page.
125 // The navigation entry can be null in situations like download or initial
126 // blank page.
127 if (item == nullptr)
128 return;
129
130 auto specifics = base::MakeUnique<sync_pb::UserEventSpecifics>();
131 // We only log the event we care about.
132 const bool needs_logging = translate::ConstructTranslateEvent(
133 item->GetTimestamp().ToInternalValue(), translate_event, specifics.get());
134 if (needs_logging) {
135 user_event_service->RecordUserEvent(std::move(specifics));
136 }
107 } 137 }
108 138
109 void ChromeIOSTranslateClient::ShowTranslateUI( 139 void ChromeIOSTranslateClient::ShowTranslateUI(
110 translate::TranslateStep step, 140 translate::TranslateStep step,
111 const std::string& source_language, 141 const std::string& source_language,
112 const std::string& target_language, 142 const std::string& target_language,
113 translate::TranslateErrors::Type error_type, 143 translate::TranslateErrors::Type error_type,
114 bool triggered_from_menu) { 144 bool triggered_from_menu) {
115 DCHECK(web_state()); 145 DCHECK(web_state());
116 if (error_type != translate::TranslateErrors::NONE) 146 if (error_type != translate::TranslateErrors::NONE)
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 const GURL& report_url) { 194 const GURL& report_url) {
165 NOTREACHED(); 195 NOTREACHED();
166 } 196 }
167 197
168 void ChromeIOSTranslateClient::WebStateDestroyed() { 198 void ChromeIOSTranslateClient::WebStateDestroyed() {
169 // Translation process can be interrupted. 199 // Translation process can be interrupted.
170 // Destroying the TranslateManager now guarantees that it never has to deal 200 // Destroying the TranslateManager now guarantees that it never has to deal
171 // with nullptr WebState. 201 // with nullptr WebState.
172 translate_manager_.reset(); 202 translate_manager_.reset();
173 } 203 }
OLDNEW
« no previous file with comments | « ios/chrome/browser/translate/BUILD.gn ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698