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

Side by Side Diff: components/translate/core/browser/translate_manager.h

Issue 2400503002: [Translate] Integrate TranslateEventProto UMA logging into TranslateManager. (Closed)
Patch Set: fix trybots Created 4 years, 1 month 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 #ifndef COMPONENTS_TRANSLATE_CORE_BROWSER_TRANSLATE_MANAGER_H_ 5 #ifndef COMPONENTS_TRANSLATE_CORE_BROWSER_TRANSLATE_MANAGER_H_
6 #define COMPONENTS_TRANSLATE_CORE_BROWSER_TRANSLATE_MANAGER_H_ 6 #define COMPONENTS_TRANSLATE_CORE_BROWSER_TRANSLATE_MANAGER_H_
7 7
8 #include <map> 8 #include <map>
9 #include <memory> 9 #include <memory>
10 #include <string> 10 #include <string>
11 #include <vector> 11 #include <vector>
12 12
13 #include "base/callback_list.h" 13 #include "base/callback_list.h"
14 #include "base/feature_list.h" 14 #include "base/feature_list.h"
15 #include "base/gtest_prod_util.h" 15 #include "base/gtest_prod_util.h"
16 #include "base/macros.h" 16 #include "base/macros.h"
17 #include "base/memory/weak_ptr.h" 17 #include "base/memory/weak_ptr.h"
18 #include "components/translate/core/browser/language_state.h" 18 #include "components/translate/core/browser/language_state.h"
19 #include "components/translate/core/common/translate_errors.h" 19 #include "components/translate/core/common/translate_errors.h"
20 20
21 class GURL; 21 class GURL;
22 class PrefService; 22 class PrefService;
23 23
24 namespace metrics {
25 class TranslateEventProto;
26 }
27
24 namespace translate { 28 namespace translate {
25 29
26 extern const base::Feature kTranslateLanguageByULP; 30 extern const base::Feature kTranslateLanguageByULP;
27 31
28 class TranslateClient; 32 class TranslateClient;
29 class TranslateDriver; 33 class TranslateDriver;
30 class TranslatePrefs; 34 class TranslatePrefs;
31 35
32 namespace testing { 36 namespace testing {
33 class TranslateManagerTest; 37 class TranslateManagerTest;
(...skipping 17 matching lines...) Expand all
51 // Returns a weak pointer to this instance. 55 // Returns a weak pointer to this instance.
52 base::WeakPtr<TranslateManager> GetWeakPtr(); 56 base::WeakPtr<TranslateManager> GetWeakPtr();
53 57
54 // Cannot return NULL. 58 // Cannot return NULL.
55 TranslateClient* translate_client() { return translate_client_; } 59 TranslateClient* translate_client() { return translate_client_; }
56 60
57 // Sets the sequence number of the current page, for use while sending 61 // Sets the sequence number of the current page, for use while sending
58 // messages to the renderer. 62 // messages to the renderer.
59 void set_current_seq_no(int page_seq_no) { page_seq_no_ = page_seq_no; } 63 void set_current_seq_no(int page_seq_no) { page_seq_no_ = page_seq_no; }
60 64
65 metrics::TranslateEventProto* mutable_translate_event() {
66 return translate_event_.get();
67 }
68
61 // Returns the language to translate to. The language returned is the 69 // Returns the language to translate to. The language returned is the
62 // first language found in the following list that is supported by the 70 // first language found in the following list that is supported by the
63 // translation service: 71 // translation service:
64 // High confidence and high probability reading language in ULP 72 // High confidence and high probability reading language in ULP
65 // the UI language 73 // the UI language
66 // the accept-language list 74 // the accept-language list
67 // If no language is found then an empty string is returned. 75 // If no language is found then an empty string is returned.
68 static std::string GetTargetLanguage(const TranslatePrefs* prefs); 76 static std::string GetTargetLanguage(const TranslatePrefs* prefs);
69 77
70 // Returns the language to automatically translate to. |original_language| is 78 // Returns the language to automatically translate to. |original_language| is
(...skipping 30 matching lines...) Expand all
101 typedef base::CallbackList<void(const TranslateErrorDetails&)> 109 typedef base::CallbackList<void(const TranslateErrorDetails&)>
102 TranslateErrorCallbackList; 110 TranslateErrorCallbackList;
103 111
104 // Registers a callback for translate errors. 112 // Registers a callback for translate errors.
105 static std::unique_ptr<TranslateErrorCallbackList::Subscription> 113 static std::unique_ptr<TranslateErrorCallbackList::Subscription>
106 RegisterTranslateErrorCallback(const TranslateErrorCallback& callback); 114 RegisterTranslateErrorCallback(const TranslateErrorCallback& callback);
107 115
108 // Gets the LanguageState associated with the TranslateManager 116 // Gets the LanguageState associated with the TranslateManager
109 LanguageState& GetLanguageState(); 117 LanguageState& GetLanguageState();
110 118
119 // Record an event of the given |event_type| using the currently saved
120 // |translate_event_| as context. |event_type| must be one of the values
121 // defined by metrics::TranslateEventProto::EventType.
122 void RecordTranslateEvent(int event_type);
123
111 // By default, don't offer to translate in builds lacking an API key. For 124 // By default, don't offer to translate in builds lacking an API key. For
112 // testing, set to true to offer anyway. 125 // testing, set to true to offer anyway.
113 static void SetIgnoreMissingKeyForTesting(bool ignore); 126 static void SetIgnoreMissingKeyForTesting(bool ignore);
114 127
115 private: 128 private:
116 friend class translate::testing::TranslateManagerTest; 129 friend class translate::testing::TranslateManagerTest;
117 130
118 // Sends a translation request to the TranslateDriver. 131 // Sends a translation request to the TranslateDriver.
119 void DoTranslatePage(const std::string& translate_script, 132 void DoTranslatePage(const std::string& translate_script,
120 const std::string& source_lang, 133 const std::string& source_lang,
(...skipping 10 matching lines...) Expand all
131 // Notifies all registered callbacks of translate errors. 144 // Notifies all registered callbacks of translate errors.
132 void NotifyTranslateError(TranslateErrors::Type error_type); 145 void NotifyTranslateError(TranslateErrors::Type error_type);
133 146
134 // Called when the Translate script has been fetched. 147 // Called when the Translate script has been fetched.
135 // Initiates the translation. 148 // Initiates the translation.
136 void OnTranslateScriptFetchComplete(const std::string& source_lang, 149 void OnTranslateScriptFetchComplete(const std::string& source_lang,
137 const std::string& target_lang, 150 const std::string& target_lang,
138 bool success, 151 bool success,
139 const std::string& data); 152 const std::string& data);
140 153
154 // Helper function to initialize a translate event metric proto.
155 void InitTranslateEvent(const std::string& src_lang,
156 const std::string& dst_lang,
157 const TranslatePrefs& translate_prefs);
158
141 // Sequence number of the current page. 159 // Sequence number of the current page.
142 int page_seq_no_; 160 int page_seq_no_;
143 161
144 // Preference name for the Accept-Languages HTTP header. 162 // Preference name for the Accept-Languages HTTP header.
145 std::string accept_languages_pref_name_; 163 std::string accept_languages_pref_name_;
146 164
147 TranslateClient* translate_client_; // Weak. 165 TranslateClient* translate_client_; // Weak.
148 TranslateDriver* translate_driver_; // Weak. 166 TranslateDriver* translate_driver_; // Weak.
149 167
150 LanguageState language_state_; 168 LanguageState language_state_;
151 169
170 std::unique_ptr<metrics::TranslateEventProto> translate_event_;
171
152 base::WeakPtrFactory<TranslateManager> weak_method_factory_; 172 base::WeakPtrFactory<TranslateManager> weak_method_factory_;
153 173
154 // By default, don't offer to translate in builds lacking an API key. For 174 // By default, don't offer to translate in builds lacking an API key. For
155 // testing, set to true to offer anyway. 175 // testing, set to true to offer anyway.
156 static bool ignore_missing_key_for_testing_; 176 static bool ignore_missing_key_for_testing_;
157 177
158 DISALLOW_COPY_AND_ASSIGN(TranslateManager); 178 DISALLOW_COPY_AND_ASSIGN(TranslateManager);
159 }; 179 };
160 180
161 } // namespace translate 181 } // namespace translate
162 182
163 #endif // COMPONENTS_TRANSLATE_CORE_BROWSER_TRANSLATE_MANAGER_H_ 183 #endif // COMPONENTS_TRANSLATE_CORE_BROWSER_TRANSLATE_MANAGER_H_
OLDNEW
« no previous file with comments | « components/metrics/proto/translate_event.proto ('k') | components/translate/core/browser/translate_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698