Adding instrumentation to locate the source of jankiness
[chromium-blink-merge.git] / chrome / browser / ui / app_list / start_page_service.h
blob4a2abb9ecc2f5b0f2183fbe39323827a4de7693c
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 <vector>
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 {
21 class Extension;
24 class Profile;
26 namespace app_list {
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 {
34 public:
35 typedef std::vector<scoped_refptr<const extensions::Extension> >
36 ExtensionList;
37 // Gets the instance for the given profile.
38 static StartPageService* Get(Profile* profile);
40 void AddObserver(StartPageObserver* observer);
41 void RemoveObserver(StartPageObserver* observer);
43 void AppListShown();
44 void AppListHidden();
45 void ToggleSpeechRecognition();
47 // Called when the WebUI has finished loading.
48 void WebUILoaded();
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);
65 private:
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();
80 void LoadContents();
81 void UnloadContents();
83 // KeyedService overrides:
84 virtual void Shutdown() override;
86 Profile* profile_;
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_