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

Side by Side 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 unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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_audio_history_handler.h" 5 #include "chrome/browser/search/hotword_audio_history_handler.h"
6 6
7 #include "base/prefs/pref_service.h" 7 #include "base/prefs/pref_service.h"
8 #include "chrome/browser/history/web_history_service.h"
9 #include "chrome/browser/history/web_history_service_factory.h"
8 #include "chrome/browser/profiles/profile.h" 10 #include "chrome/browser/profiles/profile.h"
9 #include "chrome/common/pref_names.h" 11 #include "chrome/common/pref_names.h"
10 12
11 HotwordAudioHistoryHandler::HotwordAudioHistoryHandler( 13 HotwordAudioHistoryHandler::HotwordAudioHistoryHandler(
12 content::BrowserContext* context) 14 content::BrowserContext* context)
13 : profile_(Profile::FromBrowserContext(context)) { 15 : profile_(Profile::FromBrowserContext(context)),
14 pref_change_registrar_.Init(profile_->GetPrefs()); 16 weak_factory_(this) {
15 pref_change_registrar_.Add(
16 prefs::kHotwordAudioHistoryEnabled,
17 base::Bind(&HotwordAudioHistoryHandler::OnAudioHistoryEnabledChanged,
18 base::Unretained(this)));
19 17
20 // Poll for current value on init which should happen on first use by 18 // Poll for current value on init which should happen on first use by
21 // way of the hotword service init. 19 // way of the hotword service init.
22 GetAudioHistoryEnabled(); 20 GetAudioHistoryEnabled();
23 } 21 }
24 22
25 HotwordAudioHistoryHandler::~HotwordAudioHistoryHandler() { 23 HotwordAudioHistoryHandler::~HotwordAudioHistoryHandler() {
26 } 24 }
27 25
28 bool HotwordAudioHistoryHandler::GetAudioHistoryEnabled() { 26 void HotwordAudioHistoryHandler::GetAudioHistoryEnabled() {
29 // TODO(rlp): fill in. 27 bool success = false;
30 return false; 28 history::WebHistoryService* web_history =
29 WebHistoryServiceFactory::GetForProfile(profile_);
30 if (web_history) {
31 web_history->GetAudioHistoryEnabled(
32 base::Bind(&HotwordAudioHistoryHandler::GetAudioHistoryComplete,
33 weak_factory_.GetWeakPtr()));
34 } else {
35 // If web_history is null, the user is not signed in.
36 PrefService* prefs = profile_->GetPrefs();
37 prefs->SetBoolean(prefs::kHotwordAudioHistoryEnabled, false);
38 }
31 } 39 }
32 40
33 void HotwordAudioHistoryHandler::SetAudioHistoryEnabled(const bool enabled) { 41 void HotwordAudioHistoryHandler::SetAudioHistoryEnabled(const bool enabled) {
34 // TODO(rlp): fill in. 42 history::WebHistoryService* web_history =
43 WebHistoryServiceFactory::GetForProfile(profile_);
44 if (web_history) {
45 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
46 enabled,
47 base::Bind(&HotwordAudioHistoryHandler::SetAudioHistoryComplete,
48 weak_factory_.GetWeakPtr()));
49 }
35 } 50 }
36 51
37 void HotwordAudioHistoryHandler::OnAudioHistoryEnabledChanged( 52 void HotwordAudioHistoryHandler::GetAudioHistoryComplete(
38 const std::string& pref_name) { 53 bool success, bool new_enabled_value) {
39 DCHECK(pref_name == std::string(prefs::kHotwordAudioHistoryEnabled)); 54 PrefService* prefs = profile_->GetPrefs();
55 // Set preference to false if the call was not successful to err on the safe
56 // side.
57 prefs->SetBoolean(prefs::kHotwordAudioHistoryEnabled,
58 success && new_enabled_value);
59 }
40 60
41 PrefService* prefs = profile_->GetPrefs(); 61 void HotwordAudioHistoryHandler::SetAudioHistoryComplete(
42 SetAudioHistoryEnabled(prefs->GetBoolean(prefs::kHotwordAudioHistoryEnabled)); 62 bool success, bool new_enabled_value) {
43 } 63 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698