| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/search/hotword_service.h" | 5 #include "chrome/browser/search/hotword_service.h" |
| 6 | 6 |
| 7 #include "base/i18n/case_conversion.h" | 7 #include "base/i18n/case_conversion.h" |
| 8 #include "base/metrics/field_trial.h" | 8 #include "base/metrics/field_trial.h" |
| 9 #include "base/prefs/pref_service.h" | 9 #include "base/prefs/pref_service.h" |
| 10 #include "chrome/browser/browser_process.h" | 10 #include "chrome/browser/browser_process.h" |
| 11 #include "chrome/browser/extensions/extension_service.h" | 11 #include "chrome/browser/extensions/extension_service.h" |
| 12 #include "chrome/browser/profiles/profile.h" | 12 #include "chrome/browser/profiles/profile.h" |
| 13 #include "chrome/common/extensions/extension_constants.h" | 13 #include "chrome/common/extensions/extension_constants.h" |
| 14 #include "chrome/common/pref_names.h" | 14 #include "chrome/common/pref_names.h" |
| 15 #include "extensions/browser/extension_system.h" | 15 #include "extensions/browser/extension_system.h" |
| 16 #include "extensions/common/extension.h" | 16 #include "extensions/common/extension.h" |
| 17 #include "ui/base/l10n/l10n_util.h" | 17 #include "ui/base/l10n/l10n_util.h" |
| 18 | 18 |
| 19 namespace { | 19 namespace { |
| 20 const int kMaxTimesToShowOptInPopup = 10; | 20 const int kMaxTimesToShowOptInPopup = 10; |
| 21 } | 21 } |
| 22 | 22 |
| 23 namespace hotword_internal { | 23 namespace hotword_internal { |
| 24 // Constants for the hotword field trial. | 24 // Constants for the hotword field trial. |
| 25 const char kHotwordFieldTrialName[] = "VoiceTrigger"; | 25 const char kHotwordFieldTrialName[] = "VoiceTrigger"; |
| 26 const char kHotwordFieldTrialDisabledGroupName[] = "Disabled"; | 26 const char kHotwordFieldTrialDisabledGroupName[] = "Disabled"; |
| 27 } // namespace hotword_internal | 27 } // namespace hotword_internal |
| 28 | 28 |
| 29 // static |
| 30 bool HotwordService::DoesHotwordSupportLanguage(Profile* profile) { |
| 31 std::string locale = |
| 32 #if defined(OS_CHROMEOS) |
| 33 // On ChromeOS locale is per-profile. |
| 34 profile->GetPrefs()->GetString(prefs::kApplicationLocale); |
| 35 #else |
| 36 g_browser_process->GetApplicationLocale(); |
| 37 #endif |
| 38 // Only available for English now. |
| 39 std::string normalized_locale = l10n_util::NormalizeLocale(locale); |
| 40 return normalized_locale == "en" || normalized_locale == "en_us" || |
| 41 normalized_locale =="en_US"; |
| 42 } |
| 43 |
| 29 HotwordService::HotwordService(Profile* profile) | 44 HotwordService::HotwordService(Profile* profile) |
| 30 : profile_(profile) { | 45 : profile_(profile) { |
| 31 } | 46 } |
| 32 | 47 |
| 33 HotwordService::~HotwordService() { | 48 HotwordService::~HotwordService() { |
| 34 } | 49 } |
| 35 | 50 |
| 36 bool HotwordService::ShouldShowOptInPopup() { | 51 bool HotwordService::ShouldShowOptInPopup() { |
| 37 if (profile_->IsOffTheRecord()) | 52 if (profile_->IsOffTheRecord()) |
| 38 return false; | 53 return false; |
| (...skipping 26 matching lines...) Expand all Loading... |
| 65 // Do not include disabled extension (false parameter) because if the | 80 // Do not include disabled extension (false parameter) because if the |
| 66 // extension is disabled, it's not available. | 81 // extension is disabled, it's not available. |
| 67 const extensions::Extension* extension = | 82 const extensions::Extension* extension = |
| 68 service->GetExtensionById(extension_misc::kHotwordExtensionId, false); | 83 service->GetExtensionById(extension_misc::kHotwordExtensionId, false); |
| 69 return extension && IsHotwordAllowed(); | 84 return extension && IsHotwordAllowed(); |
| 70 } | 85 } |
| 71 | 86 |
| 72 bool HotwordService::IsHotwordAllowed() { | 87 bool HotwordService::IsHotwordAllowed() { |
| 73 std::string group = base::FieldTrialList::FindFullName( | 88 std::string group = base::FieldTrialList::FindFullName( |
| 74 hotword_internal::kHotwordFieldTrialName); | 89 hotword_internal::kHotwordFieldTrialName); |
| 75 if (!group.empty() && | 90 return !group.empty() && |
| 76 group != hotword_internal::kHotwordFieldTrialDisabledGroupName) { | 91 group != hotword_internal::kHotwordFieldTrialDisabledGroupName && |
| 77 std::string locale = | 92 DoesHotwordSupportLanguage(profile_); |
| 78 #if defined(OS_CHROMEOS) | |
| 79 // On ChromeOS locale is per-profile. | |
| 80 profile_->GetPrefs()->GetString(prefs::kApplicationLocale); | |
| 81 #else | |
| 82 g_browser_process->GetApplicationLocale(); | |
| 83 #endif | |
| 84 // Only available for English now. | |
| 85 std::string normalized_locale = l10n_util::NormalizeLocale(locale); | |
| 86 return normalized_locale == "en" || normalized_locale == "en_us" || | |
| 87 normalized_locale =="en_US"; | |
| 88 } | |
| 89 return false; | |
| 90 } | 93 } |
| OLD | NEW |