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