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