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

Unified Diff: chrome/browser/search/hotword_audio_history_handler.cc

Issue 687803004: [Hotword] Implement audio history pref accessing and setting. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: minor cleanup Created 6 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/search/hotword_audio_history_handler.cc
diff --git a/chrome/browser/search/hotword_audio_history_handler.cc b/chrome/browser/search/hotword_audio_history_handler.cc
index 6bf15b0c5f4aaf882aaf509ebd9a3bb72d7542ec..b1a67ad682716e2c95b142e7ef1d041b521b0e4a 100644
--- a/chrome/browser/search/hotword_audio_history_handler.cc
+++ b/chrome/browser/search/hotword_audio_history_handler.cc
@@ -5,17 +5,15 @@
#include "chrome/browser/search/hotword_audio_history_handler.h"
#include "base/prefs/pref_service.h"
+#include "chrome/browser/history/web_history_service.h"
+#include "chrome/browser/history/web_history_service_factory.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/common/pref_names.h"
HotwordAudioHistoryHandler::HotwordAudioHistoryHandler(
content::BrowserContext* context)
- : profile_(Profile::FromBrowserContext(context)) {
- pref_change_registrar_.Init(profile_->GetPrefs());
- pref_change_registrar_.Add(
- prefs::kHotwordAudioHistoryEnabled,
- base::Bind(&HotwordAudioHistoryHandler::OnAudioHistoryEnabledChanged,
- base::Unretained(this)));
+ : profile_(Profile::FromBrowserContext(context)),
+ weak_factory_(this) {
// Poll for current value on init which should happen on first use by
// way of the hotword service init.
@@ -25,19 +23,41 @@ HotwordAudioHistoryHandler::HotwordAudioHistoryHandler(
HotwordAudioHistoryHandler::~HotwordAudioHistoryHandler() {
}
-bool HotwordAudioHistoryHandler::GetAudioHistoryEnabled() {
- // TODO(rlp): fill in.
- return false;
+void HotwordAudioHistoryHandler::GetAudioHistoryEnabled() {
+ bool success = false;
+ history::WebHistoryService* web_history =
+ WebHistoryServiceFactory::GetForProfile(profile_);
+ if (web_history) {
+ web_history->GetAudioHistoryEnabled(
+ base::Bind(&HotwordAudioHistoryHandler::GetAudioHistoryComplete,
+ weak_factory_.GetWeakPtr()));
+ } else {
+ // If web_history is null, the user is not signed in.
+ PrefService* prefs = profile_->GetPrefs();
+ prefs->SetBoolean(prefs::kHotwordAudioHistoryEnabled, false);
+ }
}
void HotwordAudioHistoryHandler::SetAudioHistoryEnabled(const bool enabled) {
- // TODO(rlp): fill in.
+ history::WebHistoryService* web_history =
+ WebHistoryServiceFactory::GetForProfile(profile_);
+ if (web_history) {
+ web_history->SetAudioHistoryEnabled(
Anand Mistry (off Chromium) 2014/11/12 00:00:10 How is the local PrefService setting supposed to b
rpetterson 2014/11/12 00:36:04 Good point. I suppose we should not leave it up to
Anand Mistry (off Chromium) 2014/11/12 00:56:55 I think the former (on success), since we should a
rpetterson 2014/11/12 01:15:42 I've combined the two callbacks since they would e
+ enabled,
+ base::Bind(&HotwordAudioHistoryHandler::SetAudioHistoryComplete,
+ weak_factory_.GetWeakPtr()));
+ }
}
-void HotwordAudioHistoryHandler::OnAudioHistoryEnabledChanged(
- const std::string& pref_name) {
- DCHECK(pref_name == std::string(prefs::kHotwordAudioHistoryEnabled));
-
+void HotwordAudioHistoryHandler::GetAudioHistoryComplete(
+ bool success, bool new_enabled_value) {
PrefService* prefs = profile_->GetPrefs();
- SetAudioHistoryEnabled(prefs->GetBoolean(prefs::kHotwordAudioHistoryEnabled));
+ // Set preference to false if the call was not successful to err on the safe
+ // side.
+ prefs->SetBoolean(prefs::kHotwordAudioHistoryEnabled,
+ success && new_enabled_value);
+}
+
+void HotwordAudioHistoryHandler::SetAudioHistoryComplete(
+ bool success, bool new_enabled_value) {
}

Powered by Google App Engine
This is Rietveld 408576698