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

Side by Side Diff: chrome/browser/language_usage_metrics.cc

Issue 15970002: Add the new UMA key 'Translate.LocalesOnDisabledByPrefs'. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 years, 7 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 (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "chrome/browser/language_usage_metrics.h" 5 #include "chrome/browser/language_usage_metrics.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/metrics/sparse_histogram.h" 9 #include "base/metrics/sparse_histogram.h"
10 #include "base/string_util.h" 10 #include "base/string_util.h"
(...skipping 16 matching lines...) Expand all
27 27
28 // static 28 // static
29 void LanguageUsageMetrics::RecordApplicationLanguage( 29 void LanguageUsageMetrics::RecordApplicationLanguage(
30 const std::string& application_locale) { 30 const std::string& application_locale) {
31 const int language_code = ToLanguageCode(application_locale); 31 const int language_code = ToLanguageCode(application_locale);
32 if (language_code != 0) 32 if (language_code != 0)
33 UMA_HISTOGRAM_SPARSE_SLOWLY("LanguageUsage.ApplicationLanguage", 33 UMA_HISTOGRAM_SPARSE_SLOWLY("LanguageUsage.ApplicationLanguage",
34 language_code); 34 language_code);
35 } 35 }
36 36
37 // static
38 void LanguageUsageMetrics::ParseAcceptLanguages(
39 const std::string& accept_languages,
40 std::set<int>* languages) {
41 languages->clear();
42 base::StringTokenizer locales(accept_languages, ",");
43 while (locales.GetNext()) {
44 const int language_code = ToLanguageCode(locales.token());
45 if (language_code != 0)
46 languages->insert(language_code);
47 }
48 }
49 37
50 // static 38 // static
51 int LanguageUsageMetrics::ToLanguageCode(const std::string& locale) { 39 int LanguageUsageMetrics::ToLanguageCode(const std::string& locale) {
52 base::StringTokenizer parts(locale, "-_"); 40 base::StringTokenizer parts(locale, "-_");
53 if (!parts.GetNext()) 41 if (!parts.GetNext())
54 return 0; 42 return 0;
55 43
56 std::string language_part = parts.token(); 44 std::string language_part = parts.token();
57 StringToLowerASCII(&language_part); 45 StringToLowerASCII(&language_part);
58 46
59 int language_code = 0; 47 int language_code = 0;
60 for (std::string::iterator it = language_part.begin(); 48 for (std::string::iterator it = language_part.begin();
61 it != language_part.end(); ++it) { 49 it != language_part.end(); ++it) {
62 char ch = *it; 50 char ch = *it;
63 if (ch < 'a' || 'z' < ch) 51 if (ch < 'a' || 'z' < ch)
64 return 0; 52 return 0;
65 53
66 language_code <<= 8; 54 language_code <<= 8;
67 language_code += ch; 55 language_code += ch;
68 } 56 }
69 57
70 return language_code; 58 return language_code;
71 } 59 }
60
61 // static
62 void LanguageUsageMetrics::ParseAcceptLanguages(
63 const std::string& accept_languages,
64 std::set<int>* languages) {
65 languages->clear();
66 base::StringTokenizer locales(accept_languages, ",");
67 while (locales.GetNext()) {
68 const int language_code = ToLanguageCode(locales.token());
69 if (language_code != 0)
70 languages->insert(language_code);
71 }
72 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698