def0df03fd54a0dc65aa9d37c58ba4de162ebea2
[platform/framework/web/crosswalk.git] / src / chrome / browser / search / hotword_service.h
1 // Copyright 2013 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.
4
5 #ifndef CHROME_BROWSER_SEARCH_HOTWORD_SERVICE_H_
6 #define CHROME_BROWSER_SEARCH_HOTWORD_SERVICE_H_
7
8 #include "base/basictypes.h"
9 #include "base/prefs/pref_change_registrar.h"
10 #include "components/keyed_service/core/keyed_service.h"
11 #include "content/public/browser/notification_observer.h"
12 #include "content/public/browser/notification_registrar.h"
13
14 class ExtensionService;
15 class Profile;
16
17 namespace hotword_internal {
18 // Constants for the hotword field trial.
19 extern const char kHotwordFieldTrialName[];
20 extern const char kHotwordFieldTrialDisabledGroupName[];
21 }  // namespace hotword_internal
22
23 // Provides an interface for the Hotword component that does voice triggered
24 // search.
25 class HotwordService : public content::NotificationObserver,
26                        public KeyedService {
27  public:
28   // Returns true if the hotword supports the current system language.
29   static bool DoesHotwordSupportLanguage(Profile* profile);
30
31   explicit HotwordService(Profile* profile);
32   virtual ~HotwordService();
33
34   // Overridden from content::NotificationObserver:
35   virtual void Observe(int type,
36                        const content::NotificationSource& source,
37                        const content::NotificationDetails& details) OVERRIDE;
38
39   bool ShouldShowOptInPopup();
40
41   // Used in testing to ensure that the popup is not shown more than this
42   // maximum number of times.
43   int MaxNumberTimesToShowOptInPopup();
44
45   // In addition to showing the popup, the preferences
46   // kHotwordOptInPopupTimesShown is also incremented.
47   void ShowOptInPopup();
48
49   // Checks for whether all the necessary files have downloaded to allow for
50   // using the extension.
51   virtual bool IsServiceAvailable();
52
53   // Determine if hotwording is allowed in this profile based on field trials
54   // and language.
55   virtual bool IsHotwordAllowed();
56
57   // Checks if the user has opted into audio logging. Returns true if the user
58   // is opted in, false otherwise..
59   bool IsOptedIntoAudioLogging();
60
61   // Used in the case of an error with the current hotword extension. Tries
62   // to reload the extension or in the case of failure, tries to re-download it.
63   // Returns true upon successful attempt at reload or if the extension has
64   // already loaded successfully by some other means.
65   virtual bool RetryHotwordExtension();
66
67   // Control the state of the hotword extension.
68   void EnableHotwordExtension(ExtensionService* extension_service);
69   void DisableHotwordExtension(ExtensionService* extension_service);
70
71   // Handles enabling/disabling the hotword extension when the user
72   // turns it off via the settings menu.
73   void OnHotwordSearchEnabledChanged(const std::string& pref_name);
74
75  private:
76   Profile* profile_;
77
78   PrefChangeRegistrar pref_registrar_;
79
80   content::NotificationRegistrar registrar_;
81
82   DISALLOW_COPY_AND_ASSIGN(HotwordService);
83 };
84
85 #endif  // CHROME_BROWSER_SEARCH_HOTWORD_SERVICE_H_