start_page_service.h revision a1401311d1ab56c4ed0a474bd38c108f75cb0cd9
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. 4 5#ifndef CHROME_BROWSER_UI_APP_LIST_START_PAGE_SERVICE_H_ 6#define CHROME_BROWSER_UI_APP_LIST_START_PAGE_SERVICE_H_ 7 8#include <vector> 9 10#include "base/basictypes.h" 11#include "base/memory/ref_counted.h" 12#include "base/memory/scoped_ptr.h" 13#include "base/observer_list.h" 14#include "base/strings/string16.h" 15#include "components/keyed_service/core/keyed_service.h" 16#include "content/public/browser/web_contents.h" 17#include "ui/app_list/speech_ui_model_observer.h" 18 19namespace extensions { 20class Extension; 21} 22 23class Profile; 24 25namespace app_list { 26 27class RecommendedApps; 28class StartPageObserver; 29 30// StartPageService collects data to be displayed in app list's start page 31// and hosts the start page contents. 32class StartPageService : public KeyedService { 33 public: 34 typedef std::vector<scoped_refptr<const extensions::Extension> > 35 ExtensionList; 36 // Gets the instance for the given profile. 37 static StartPageService* Get(Profile* profile); 38 39 void AddObserver(StartPageObserver* observer); 40 void RemoveObserver(StartPageObserver* observer); 41 42 void ToggleSpeechRecognition(); 43 44 // They return essentially the same web contents but might return NULL when 45 // some flag disables the feature. 46 content::WebContents* GetStartPageContents(); 47 content::WebContents* GetSpeechRecognitionContents(); 48 49 RecommendedApps* recommended_apps() { return recommended_apps_.get(); } 50 Profile* profile() { return profile_; } 51 SpeechRecognitionState state() { return state_; } 52 void OnSpeechResult(const base::string16& query, bool is_final); 53 void OnSpeechSoundLevelChanged(int16 level); 54 void OnSpeechRecognitionStateChanged(SpeechRecognitionState new_state); 55 56 private: 57 friend class StartPageServiceFactory; 58 59 // ProfileDestroyObserver to shutdown the service on exiting. WebContents 60 // depends on the profile and needs to be closed before the profile and its 61 // keyed service shutdown. 62 class ProfileDestroyObserver; 63 64 // The WebContentsDelegate implementation for the start page. This allows 65 // getUserMedia() request from the web contents. 66 class StartPageWebContentsDelegate; 67 68 explicit StartPageService(Profile* profile); 69 virtual ~StartPageService(); 70 71 // KeyedService overrides: 72 virtual void Shutdown() OVERRIDE; 73 74 Profile* profile_; 75 scoped_ptr<content::WebContents> contents_; 76 scoped_ptr<StartPageWebContentsDelegate> contents_delegate_; 77 scoped_ptr<ProfileDestroyObserver> profile_destroy_observer_; 78 scoped_ptr<RecommendedApps> recommended_apps_; 79 SpeechRecognitionState state_; 80 ObserverList<StartPageObserver> observers_; 81 bool speech_button_toggled_manually_; 82 bool speech_result_obtained_; 83 84 DISALLOW_COPY_AND_ASSIGN(StartPageService); 85}; 86 87} // namespace app_list 88 89#endif // CHROME_BROWSER_UI_APP_LIST_START_PAGE_SERVICE_H_ 90