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

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: fixing memory leak with scoped ptrs 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
« no previous file with comments | « chrome/browser/search/hotword_audio_history_handler.h ('k') | chrome/chrome_tests_unit.gypi » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..5a001ae63cd15a9a6e1639fc9119ace9f6a5a3ef 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,36 @@ HotwordAudioHistoryHandler::HotwordAudioHistoryHandler(
HotwordAudioHistoryHandler::~HotwordAudioHistoryHandler() {
}
-bool HotwordAudioHistoryHandler::GetAudioHistoryEnabled() {
- // TODO(rlp): fill in.
- return false;
+void HotwordAudioHistoryHandler::GetAudioHistoryEnabled() {
+ history::WebHistoryService* web_history =
+ WebHistoryServiceFactory::GetForProfile(profile_);
+ if (web_history) {
+ web_history->GetAudioHistoryEnabled(
+ base::Bind(&HotwordAudioHistoryHandler::AudioHistoryComplete,
+ 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(
+ enabled,
+ base::Bind(&HotwordAudioHistoryHandler::AudioHistoryComplete,
+ weak_factory_.GetWeakPtr()));
+ }
}
-void HotwordAudioHistoryHandler::OnAudioHistoryEnabledChanged(
- const std::string& pref_name) {
- DCHECK(pref_name == std::string(prefs::kHotwordAudioHistoryEnabled));
-
+void HotwordAudioHistoryHandler::AudioHistoryComplete(
+ 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);
}
« no previous file with comments | « chrome/browser/search/hotword_audio_history_handler.h ('k') | chrome/chrome_tests_unit.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698