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_
10 #include "base/basictypes.h"
11 #include "base/callback.h"
12 #include "base/memory/ref_counted.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "base/observer_list.h"
15 #include "base/strings/string16.h"
16 #include "components/keyed_service/core/keyed_service.h"
17 #include "content/public/browser/web_contents.h"
18 #include "ui/app_list/speech_ui_model_observer.h"
20 namespace extensions
{
28 class RecommendedApps
;
29 class StartPageObserver
;
31 // StartPageService collects data to be displayed in app list's start page
32 // and hosts the start page contents.
33 class StartPageService
: public KeyedService
{
35 typedef std::vector
<scoped_refptr
<const extensions::Extension
> >
37 // Gets the instance for the given profile.
38 static StartPageService
* Get(Profile
* profile
);
40 void AddObserver(StartPageObserver
* observer
);
41 void RemoveObserver(StartPageObserver
* observer
);
45 void ToggleSpeechRecognition();
47 // Called when the WebUI has finished loading.
50 // Returns true if the hotword is enabled in the app-launcher.
51 bool HotwordEnabled();
53 // They return essentially the same web contents but might return NULL when
54 // some flag disables the feature.
55 content::WebContents
* GetStartPageContents();
56 content::WebContents
* GetSpeechRecognitionContents();
58 RecommendedApps
* recommended_apps() { return recommended_apps_
.get(); }
59 Profile
* profile() { return profile_
; }
60 SpeechRecognitionState
state() { return state_
; }
61 void OnSpeechResult(const base::string16
& query
, bool is_final
);
62 void OnSpeechSoundLevelChanged(int16 level
);
63 void OnSpeechRecognitionStateChanged(SpeechRecognitionState new_state
);
66 friend class StartPageServiceFactory
;
68 // ProfileDestroyObserver to shutdown the service on exiting. WebContents
69 // depends on the profile and needs to be closed before the profile and its
70 // keyed service shutdown.
71 class ProfileDestroyObserver
;
73 // The WebContentsDelegate implementation for the start page. This allows
74 // getUserMedia() request from the web contents.
75 class StartPageWebContentsDelegate
;
77 explicit StartPageService(Profile
* profile
);
78 virtual ~StartPageService();
81 void UnloadContents();
83 // KeyedService overrides:
84 virtual void Shutdown() override
;
87 scoped_ptr
<content::WebContents
> contents_
;
88 scoped_ptr
<StartPageWebContentsDelegate
> contents_delegate_
;
89 scoped_ptr
<ProfileDestroyObserver
> profile_destroy_observer_
;
90 scoped_ptr
<RecommendedApps
> recommended_apps_
;
91 SpeechRecognitionState state_
;
92 ObserverList
<StartPageObserver
> observers_
;
93 bool speech_button_toggled_manually_
;
94 bool speech_result_obtained_
;
96 bool webui_finished_loading_
;
97 std::vector
<base::Closure
> pending_webui_callbacks_
;
99 DISALLOW_COPY_AND_ASSIGN(StartPageService
);
102 } // namespace app_list
104 #endif // CHROME_BROWSER_UI_APP_LIST_START_PAGE_SERVICE_H_