Updates the mic icon status based on the device's audio state (2nd)
[chromium-blink-merge.git] / chrome / browser / ui / app_list / start_page_service.h
blobd33bd531bbd29826fc90f2c6560ed88b22da43ed
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.
5 #ifndef CHROME_BROWSER_UI_APP_LIST_START_PAGE_SERVICE_H_
6 #define CHROME_BROWSER_UI_APP_LIST_START_PAGE_SERVICE_H_
8 #include <stdint.h>
9 #include <vector>
11 #include "base/basictypes.h"
12 #include "base/callback.h"
13 #include "base/memory/ref_counted.h"
14 #include "base/memory/scoped_ptr.h"
15 #include "base/memory/weak_ptr.h"
16 #include "base/observer_list.h"
17 #include "base/strings/string16.h"
18 #include "chrome/browser/ui/app_list/speech_recognizer_delegate.h"
19 #include "components/keyed_service/core/keyed_service.h"
20 #include "content/public/browser/web_contents.h"
21 #include "ui/app_list/speech_ui_model_observer.h"
23 namespace extensions {
24 class Extension;
27 class Profile;
29 namespace app_list {
31 class RecommendedApps;
32 class SpeechRecognizer;
33 class StartPageObserver;
35 // StartPageService collects data to be displayed in app list's start page
36 // and hosts the start page contents.
37 class StartPageService : public KeyedService,
38 public SpeechRecognizerDelegate {
39 public:
40 typedef std::vector<scoped_refptr<const extensions::Extension> >
41 ExtensionList;
42 // Gets the instance for the given profile.
43 static StartPageService* Get(Profile* profile);
45 void AddObserver(StartPageObserver* observer);
46 void RemoveObserver(StartPageObserver* observer);
48 void AppListShown();
49 void AppListHidden();
50 void ToggleSpeechRecognition();
52 // Called when the WebUI has finished loading.
53 void WebUILoaded();
55 // Returns true if the hotword is enabled in the app-launcher.
56 bool HotwordEnabled();
58 // They return essentially the same web contents but might return NULL when
59 // some flag disables the feature.
60 content::WebContents* GetStartPageContents();
61 content::WebContents* GetSpeechRecognitionContents();
63 RecommendedApps* recommended_apps() { return recommended_apps_.get(); }
64 Profile* profile() { return profile_; }
65 SpeechRecognitionState state() { return state_; }
67 // Overridden from app_list::SpeechRecognizerDelegate:
68 void OnSpeechResult(const base::string16& query, bool is_final) override;
69 void OnSpeechSoundLevelChanged(int16_t level) override;
70 void OnSpeechRecognitionStateChanged(
71 SpeechRecognitionState new_state) override;
72 content::WebContents* GetSpeechContents() override;
74 protected:
75 // Protected for testing.
76 explicit StartPageService(Profile* profile);
77 ~StartPageService() override;
79 private:
80 friend class StartPageServiceFactory;
82 // ProfileDestroyObserver to shutdown the service on exiting. WebContents
83 // depends on the profile and needs to be closed before the profile and its
84 // keyed service shutdown.
85 class ProfileDestroyObserver;
87 // The WebContentsDelegate implementation for the start page. This allows
88 // getUserMedia() request from the web contents.
89 class StartPageWebContentsDelegate;
91 #if defined(OS_CHROMEOS)
92 // This class observes the change of audio input device availability and
93 // checks if currently the system has valid audio input.
94 class AudioStatus;
95 #endif
97 void LoadContents();
98 void UnloadContents();
100 // KeyedService overrides:
101 void Shutdown() override;
103 Profile* profile_;
104 scoped_ptr<content::WebContents> contents_;
105 scoped_ptr<StartPageWebContentsDelegate> contents_delegate_;
106 scoped_ptr<ProfileDestroyObserver> profile_destroy_observer_;
107 scoped_ptr<RecommendedApps> recommended_apps_;
108 SpeechRecognitionState state_;
109 ObserverList<StartPageObserver> observers_;
110 bool speech_button_toggled_manually_;
111 bool speech_result_obtained_;
113 bool webui_finished_loading_;
114 std::vector<base::Closure> pending_webui_callbacks_;
116 scoped_ptr<SpeechRecognizer> speech_recognizer_;
118 #if defined(OS_CHROMEOS)
119 scoped_ptr<AudioStatus> audio_status_;
120 #endif
122 base::WeakPtrFactory<StartPageService> weak_factory_;
124 DISALLOW_COPY_AND_ASSIGN(StartPageService);
127 } // namespace app_list
129 #endif // CHROME_BROWSER_UI_APP_LIST_START_PAGE_SERVICE_H_