Add new certificateProvider extension API.
[chromium-blink-merge.git] / chrome / browser / search / hotword_audio_history_handler.h
blob30dbe1e8781938f0255fc183248d6312ed95693f
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
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_SEARCH_HOTWORD_AUDIO_HISTORY_HANDLER_H_
6 #define CHROME_BROWSER_SEARCH_HOTWORD_AUDIO_HISTORY_HANDLER_H_
8 #include "base/memory/ref_counted.h"
9 #include "base/memory/weak_ptr.h"
10 #include "base/prefs/pref_change_registrar.h"
11 #include "content/public/browser/browser_context.h"
13 class Profile;
15 namespace base {
16 class SingleThreadTaskRunner;
19 namespace history {
20 class WebHistoryService;
23 // A class which handles the audio history pref for hotwording. This has been
24 // pulled into its own class in order to transparently (to the rest of
25 // hotwording) handle changing user global pref management systems.
26 class HotwordAudioHistoryHandler {
27 public:
28 typedef base::Callback<void(bool success, bool new_enabled_value)>
29 HotwordAudioHistoryCallback;
31 HotwordAudioHistoryHandler(
32 content::BrowserContext* context,
33 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner);
35 virtual ~HotwordAudioHistoryHandler();
37 // Initiates a call to get the updated audio history state.
38 void UpdateAudioHistoryState();
40 // Updates the current preference value based on the user's account info
41 // or false if the user is not signed in.
42 virtual void GetAudioHistoryEnabled(
43 const HotwordAudioHistoryCallback& callback);
45 // Sets the user's global pref value for enabling audio history.
46 void SetAudioHistoryEnabled(const bool enabled,
47 const HotwordAudioHistoryCallback& callback);
49 // This helper function is made public for testing.
50 virtual history::WebHistoryService* GetWebHistory();
52 private:
53 // Helper function used as a callback and to factor out common code.
54 void UpdateLocalPreference(bool success, bool new_enabled_value);
56 // Called upon completion of web history->GetAudioHistoryEnabled.
57 void GetAudioHistoryComplete(
58 const HotwordAudioHistoryCallback& callback,
59 bool success,
60 bool new_enabled_value);
62 // Called upon completion of web history->SetAudioHistoryEnabled.
63 // |new_enabled_value| is the desired value of the preference.
64 // |callback_enabled_value| should not be considered valid.
65 void SetAudioHistoryComplete(
66 bool new_enabled_value,
67 const HotwordAudioHistoryCallback& callback,
68 bool success,
69 bool callback_enabled_value);
71 scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
73 Profile* profile_;
75 base::WeakPtrFactory<HotwordAudioHistoryHandler> weak_ptr_factory_;
77 DISALLOW_COPY_AND_ASSIGN(HotwordAudioHistoryHandler);
80 #endif // CHROME_BROWSER_SEARCH_HOTWORD_AUDIO_HISTORY_HANDLER_H_