| 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/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/i18n/case_conversion.h" | 8 #include "base/i18n/case_conversion.h" |
| 9 #include "base/metrics/field_trial.h" | 9 #include "base/metrics/field_trial.h" |
| 10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
| (...skipping 420 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 431 DoesHotwordSupportLanguage(profile_); | 431 DoesHotwordSupportLanguage(profile_); |
| 432 } | 432 } |
| 433 | 433 |
| 434 bool HotwordService::IsOptedIntoAudioLogging() { | 434 bool HotwordService::IsOptedIntoAudioLogging() { |
| 435 // Do not opt the user in if the preference has not been set. | 435 // Do not opt the user in if the preference has not been set. |
| 436 return | 436 return |
| 437 profile_->GetPrefs()->HasPrefPath(prefs::kHotwordAudioLoggingEnabled) && | 437 profile_->GetPrefs()->HasPrefPath(prefs::kHotwordAudioLoggingEnabled) && |
| 438 profile_->GetPrefs()->GetBoolean(prefs::kHotwordAudioLoggingEnabled); | 438 profile_->GetPrefs()->GetBoolean(prefs::kHotwordAudioLoggingEnabled); |
| 439 } | 439 } |
| 440 | 440 |
| 441 bool HotwordService::IsAlwaysOnEnabled() { |
| 442 return |
| 443 profile_->GetPrefs()->HasPrefPath(prefs::kHotwordAlwaysOnSearchEnabled) && |
| 444 profile_->GetPrefs()->GetBoolean(prefs::kHotwordAlwaysOnSearchEnabled); |
| 445 } |
| 446 |
| 441 void HotwordService::EnableHotwordExtension( | 447 void HotwordService::EnableHotwordExtension( |
| 442 ExtensionService* extension_service) { | 448 ExtensionService* extension_service) { |
| 443 if (extension_service) | 449 if (extension_service) |
| 444 extension_service->EnableExtension(extension_misc::kHotwordExtensionId); | 450 extension_service->EnableExtension(extension_misc::kHotwordExtensionId); |
| 445 } | 451 } |
| 446 | 452 |
| 447 void HotwordService::DisableHotwordExtension( | 453 void HotwordService::DisableHotwordExtension( |
| 448 ExtensionService* extension_service) { | 454 ExtensionService* extension_service) { |
| 449 if (extension_service) { | 455 if (extension_service) { |
| 450 extension_service->DisableExtension( | 456 extension_service->DisableExtension( |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 494 HotwordPrivateEventService* event_service = | 500 HotwordPrivateEventService* event_service = |
| 495 BrowserContextKeyedAPIFactory<HotwordPrivateEventService>::Get(profile_); | 501 BrowserContextKeyedAPIFactory<HotwordPrivateEventService>::Get(profile_); |
| 496 if (event_service) | 502 if (event_service) |
| 497 event_service->OnHotwordSessionRequested(); | 503 event_service->OnHotwordSessionRequested(); |
| 498 } | 504 } |
| 499 | 505 |
| 500 void HotwordService::StopHotwordSession(HotwordClient* client) { | 506 void HotwordService::StopHotwordSession(HotwordClient* client) { |
| 501 if (!IsServiceAvailable()) | 507 if (!IsServiceAvailable()) |
| 502 return; | 508 return; |
| 503 | 509 |
| 510 // Do nothing if there's no client. |
| 511 if (!client_) |
| 512 return; |
| 504 DCHECK(client_ == client); | 513 DCHECK(client_ == client); |
| 505 | 514 |
| 506 client_ = NULL; | 515 client_ = NULL; |
| 507 HotwordPrivateEventService* event_service = | 516 HotwordPrivateEventService* event_service = |
| 508 BrowserContextKeyedAPIFactory<HotwordPrivateEventService>::Get(profile_); | 517 BrowserContextKeyedAPIFactory<HotwordPrivateEventService>::Get(profile_); |
| 509 if (event_service) | 518 if (event_service) |
| 510 event_service->OnHotwordSessionStopped(); | 519 event_service->OnHotwordSessionStopped(); |
| 511 } | 520 } |
| 512 | 521 |
| 513 void HotwordService::SetPreviousLanguagePref() { | 522 void HotwordService::SetPreviousLanguagePref() { |
| 514 profile_->GetPrefs()->SetString(prefs::kHotwordPreviousLanguage, | 523 profile_->GetPrefs()->SetString(prefs::kHotwordPreviousLanguage, |
| 515 GetCurrentLocale(profile_)); | 524 GetCurrentLocale(profile_)); |
| 516 } | 525 } |
| 517 | 526 |
| 518 bool HotwordService::ShouldReinstallHotwordExtension() { | 527 bool HotwordService::ShouldReinstallHotwordExtension() { |
| 519 // If there is no previous locale pref, then this is the first install | 528 // If there is no previous locale pref, then this is the first install |
| 520 // so no need to uninstall first. | 529 // so no need to uninstall first. |
| 521 if (!profile_->GetPrefs()->HasPrefPath(prefs::kHotwordPreviousLanguage)) | 530 if (!profile_->GetPrefs()->HasPrefPath(prefs::kHotwordPreviousLanguage)) |
| 522 return false; | 531 return false; |
| 523 | 532 |
| 524 std::string previous_locale = | 533 std::string previous_locale = |
| 525 profile_->GetPrefs()->GetString(prefs::kHotwordPreviousLanguage); | 534 profile_->GetPrefs()->GetString(prefs::kHotwordPreviousLanguage); |
| 526 std::string locale = GetCurrentLocale(profile_); | 535 std::string locale = GetCurrentLocale(profile_); |
| 527 | 536 |
| 528 // If it's a new locale, then the old extension should be uninstalled. | 537 // If it's a new locale, then the old extension should be uninstalled. |
| 529 return locale != previous_locale && | 538 return locale != previous_locale && |
| 530 HotwordService::DoesHotwordSupportLanguage(profile_); | 539 HotwordService::DoesHotwordSupportLanguage(profile_); |
| 531 } | 540 } |
| OLD | NEW |