OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 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_UI_APP_LIST_START_PAGE_SERVICE_H_ | 5 #ifndef CHROME_BROWSER_UI_APP_LIST_START_PAGE_SERVICE_H_ |
6 #define CHROME_BROWSER_UI_APP_LIST_START_PAGE_SERVICE_H_ | 6 #define CHROME_BROWSER_UI_APP_LIST_START_PAGE_SERVICE_H_ |
7 | 7 |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
11 #include "base/callback.h" | 11 #include "base/callback.h" |
12 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
14 #include "base/observer_list.h" | 14 #include "base/observer_list.h" |
15 #include "base/strings/string16.h" | 15 #include "base/strings/string16.h" |
16 #include "components/keyed_service/core/keyed_service.h" | 16 #include "components/keyed_service/core/keyed_service.h" |
17 #include "content/public/browser/web_contents.h" | 17 #include "content/public/browser/web_contents.h" |
18 #include "ui/app_list/speech_ui_model_observer.h" | 18 #include "ui/app_list/speech_ui_model_observer.h" |
19 | 19 |
20 namespace extensions { | 20 namespace extensions { |
21 class Extension; | 21 class Extension; |
22 } | 22 } |
23 | 23 |
24 class Profile; | 24 class Profile; |
25 | 25 |
26 namespace app_list { | 26 namespace app_list { |
27 | 27 |
| 28 class AppListSpeechRecognizer; |
28 class RecommendedApps; | 29 class RecommendedApps; |
29 class StartPageObserver; | 30 class StartPageObserver; |
30 | 31 |
31 // StartPageService collects data to be displayed in app list's start page | 32 // StartPageService collects data to be displayed in app list's start page |
32 // and hosts the start page contents. | 33 // and hosts the start page contents. |
33 class StartPageService : public KeyedService { | 34 class StartPageService : public KeyedService { |
34 public: | 35 public: |
35 typedef std::vector<scoped_refptr<const extensions::Extension> > | 36 typedef std::vector<scoped_refptr<const extensions::Extension> > |
36 ExtensionList; | 37 ExtensionList; |
37 // Gets the instance for the given profile. | 38 // Gets the instance for the given profile. |
38 static StartPageService* Get(Profile* profile); | 39 static StartPageService* Get(Profile* profile); |
39 | 40 |
40 void AddObserver(StartPageObserver* observer); | 41 void AddObserver(StartPageObserver* observer); |
41 void RemoveObserver(StartPageObserver* observer); | 42 void RemoveObserver(StartPageObserver* observer); |
42 | 43 |
43 void AppListShown(); | 44 void AppListShown(); |
44 void AppListHidden(); | 45 void AppListHidden(); |
45 void ToggleSpeechRecognition(); | 46 void ToggleSpeechRecognition(); |
46 | 47 |
47 // Called when the WebUI has finished loading. | 48 // Called when the WebUI has finished loading. |
48 void WebUILoaded(); | 49 void WebUILoaded(); |
49 | 50 |
50 // Returns true if the hotword is enabled in the app-launcher. | 51 // Returns true if the hotword is enabled in the app-launcher. |
51 bool HotwordEnabled(); | 52 bool HotwordEnabled(); |
52 | 53 |
53 // They return essentially the same web contents but might return NULL when | 54 // They return essentially the same web contents but might return NULL when |
54 // some flag disables the feature. | 55 // some flag disables the feature. |
55 content::WebContents* GetStartPageContents(); | 56 content::WebContents* GetStartPageContents(); |
56 content::WebContents* GetSpeechRecognitionContents(); | 57 virtual content::WebContents* GetSpeechRecognitionContents(); |
57 | 58 |
58 RecommendedApps* recommended_apps() { return recommended_apps_.get(); } | 59 RecommendedApps* recommended_apps() { return recommended_apps_.get(); } |
59 Profile* profile() { return profile_; } | 60 Profile* profile() { return profile_; } |
60 SpeechRecognitionState state() { return state_; } | 61 SpeechRecognitionState state() { return state_; } |
61 void OnSpeechResult(const base::string16& query, bool is_final); | 62 virtual void OnSpeechResult(const base::string16& query, bool is_final); |
62 void OnSpeechSoundLevelChanged(int16 level); | 63 virtual void OnSpeechSoundLevelChanged(int16 level); |
63 void OnSpeechRecognitionStateChanged(SpeechRecognitionState new_state); | 64 virtual void OnSpeechRecognitionStateChanged( |
| 65 SpeechRecognitionState new_state); |
| 66 |
| 67 protected: |
| 68 // Protected for testing. |
| 69 explicit StartPageService(Profile* profile); |
| 70 ~StartPageService() override; |
64 | 71 |
65 private: | 72 private: |
66 friend class StartPageServiceFactory; | 73 friend class StartPageServiceFactory; |
67 | 74 |
68 // ProfileDestroyObserver to shutdown the service on exiting. WebContents | 75 // ProfileDestroyObserver to shutdown the service on exiting. WebContents |
69 // depends on the profile and needs to be closed before the profile and its | 76 // depends on the profile and needs to be closed before the profile and its |
70 // keyed service shutdown. | 77 // keyed service shutdown. |
71 class ProfileDestroyObserver; | 78 class ProfileDestroyObserver; |
72 | 79 |
73 // The WebContentsDelegate implementation for the start page. This allows | 80 // The WebContentsDelegate implementation for the start page. This allows |
74 // getUserMedia() request from the web contents. | 81 // getUserMedia() request from the web contents. |
75 class StartPageWebContentsDelegate; | 82 class StartPageWebContentsDelegate; |
76 | 83 |
77 explicit StartPageService(Profile* profile); | |
78 ~StartPageService() override; | |
79 | |
80 void LoadContents(); | 84 void LoadContents(); |
81 void UnloadContents(); | 85 void UnloadContents(); |
82 | 86 |
83 // KeyedService overrides: | 87 // KeyedService overrides: |
84 void Shutdown() override; | 88 void Shutdown() override; |
85 | 89 |
86 Profile* profile_; | 90 Profile* profile_; |
87 scoped_ptr<content::WebContents> contents_; | 91 scoped_ptr<content::WebContents> contents_; |
88 scoped_ptr<StartPageWebContentsDelegate> contents_delegate_; | 92 scoped_ptr<StartPageWebContentsDelegate> contents_delegate_; |
89 scoped_ptr<ProfileDestroyObserver> profile_destroy_observer_; | 93 scoped_ptr<ProfileDestroyObserver> profile_destroy_observer_; |
90 scoped_ptr<RecommendedApps> recommended_apps_; | 94 scoped_ptr<RecommendedApps> recommended_apps_; |
91 SpeechRecognitionState state_; | 95 SpeechRecognitionState state_; |
92 ObserverList<StartPageObserver> observers_; | 96 ObserverList<StartPageObserver> observers_; |
93 bool speech_button_toggled_manually_; | 97 bool speech_button_toggled_manually_; |
94 bool speech_result_obtained_; | 98 bool speech_result_obtained_; |
95 | 99 |
96 bool webui_finished_loading_; | 100 bool webui_finished_loading_; |
97 std::vector<base::Closure> pending_webui_callbacks_; | 101 std::vector<base::Closure> pending_webui_callbacks_; |
98 | 102 |
| 103 scoped_refptr<AppListSpeechRecognizer> speech_recognizer_; |
| 104 |
99 DISALLOW_COPY_AND_ASSIGN(StartPageService); | 105 DISALLOW_COPY_AND_ASSIGN(StartPageService); |
100 }; | 106 }; |
101 | 107 |
102 } // namespace app_list | 108 } // namespace app_list |
103 | 109 |
104 #endif // CHROME_BROWSER_UI_APP_LIST_START_PAGE_SERVICE_H_ | 110 #endif // CHROME_BROWSER_UI_APP_LIST_START_PAGE_SERVICE_H_ |
OLD | NEW |