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