Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / ui / app_list / start_page_service.h
index 1b7db3b..61e2260 100644 (file)
@@ -5,13 +5,20 @@
 #ifndef CHROME_BROWSER_UI_APP_LIST_START_PAGE_SERVICE_H_
 #define CHROME_BROWSER_UI_APP_LIST_START_PAGE_SERVICE_H_
 
+#include <stdint.h>
 #include <vector>
 
 #include "base/basictypes.h"
+#include "base/callback.h"
 #include "base/memory/ref_counted.h"
 #include "base/memory/scoped_ptr.h"
-#include "components/browser_context_keyed_service/browser_context_keyed_service.h"
+#include "base/memory/weak_ptr.h"
+#include "base/observer_list.h"
+#include "base/strings/string16.h"
+#include "chrome/browser/ui/app_list/speech_recognizer_delegate.h"
+#include "components/keyed_service/core/keyed_service.h"
 #include "content/public/browser/web_contents.h"
+#include "ui/app_list/speech_ui_model_observer.h"
 
 namespace extensions {
 class Extension;
@@ -22,38 +29,87 @@ class Profile;
 namespace app_list {
 
 class RecommendedApps;
+class SpeechRecognizer;
+class StartPageObserver;
 
 // StartPageService collects data to be displayed in app list's start page
 // and hosts the start page contents.
-class StartPageService : public BrowserContextKeyedService {
+class StartPageService : public KeyedService,
+                         public SpeechRecognizerDelegate {
  public:
   typedef std::vector<scoped_refptr<const extensions::Extension> >
       ExtensionList;
   // Gets the instance for the given profile.
   static StartPageService* Get(Profile* profile);
 
-  content::WebContents* contents() { return contents_.get(); }
+  void AddObserver(StartPageObserver* observer);
+  void RemoveObserver(StartPageObserver* observer);
+
+  void AppListShown();
+  void AppListHidden();
+  void ToggleSpeechRecognition();
+
+  // Called when the WebUI has finished loading.
+  void WebUILoaded();
+
+  // Returns true if the hotword is enabled in the app-launcher.
+  bool HotwordEnabled();
+
+  // They return essentially the same web contents but might return NULL when
+  // some flag disables the feature.
+  content::WebContents* GetStartPageContents();
+  content::WebContents* GetSpeechRecognitionContents();
+
   RecommendedApps* recommended_apps() { return recommended_apps_.get(); }
+  Profile* profile() { return profile_; }
+  SpeechRecognitionState state() { return state_; }
+
+  // Overridden from app_list::SpeechRecognizerDelegate:
+  void OnSpeechResult(const base::string16& query, bool is_final) override;
+  void OnSpeechSoundLevelChanged(int16_t level) override;
+  void OnSpeechRecognitionStateChanged(
+      SpeechRecognitionState new_state) override;
+  content::WebContents* GetSpeechContents() override;
+
+ protected:
+  // Protected for testing.
+  explicit StartPageService(Profile* profile);
+  ~StartPageService() override;
 
  private:
-  // A BrowserContextKeyedServiceFactory for this service.
-  class Factory;
+  friend class StartPageServiceFactory;
 
-  // ExitObserver to shutdown the service on exiting. WebContents depends
-  // on the profile and needs to be closed before the profile and its
+  // ProfileDestroyObserver to shutdown the service on exiting. WebContents
+  // depends on the profile and needs to be closed before the profile and its
   // keyed service shutdown.
-  class ExitObserver;
+  class ProfileDestroyObserver;
 
-  explicit StartPageService(Profile* profile);
-  virtual ~StartPageService();
+  // The WebContentsDelegate implementation for the start page. This allows
+  // getUserMedia() request from the web contents.
+  class StartPageWebContentsDelegate;
+
+  void LoadContents();
+  void UnloadContents();
 
-  // BrowserContextKeyedService overrides:
-  virtual void Shutdown() OVERRIDE;
+  // KeyedService overrides:
+  void Shutdown() override;
 
   Profile* profile_;
   scoped_ptr<content::WebContents> contents_;
-  scoped_ptr<ExitObserver> exit_observer_;
+  scoped_ptr<StartPageWebContentsDelegate> contents_delegate_;
+  scoped_ptr<ProfileDestroyObserver> profile_destroy_observer_;
   scoped_ptr<RecommendedApps> recommended_apps_;
+  SpeechRecognitionState state_;
+  ObserverList<StartPageObserver> observers_;
+  bool speech_button_toggled_manually_;
+  bool speech_result_obtained_;
+
+  bool webui_finished_loading_;
+  std::vector<base::Closure> pending_webui_callbacks_;
+
+  scoped_ptr<SpeechRecognizer> speech_recognizer_;
+
+  base::WeakPtrFactory<StartPageService> weak_factory_;
 
   DISALLOW_COPY_AND_ASSIGN(StartPageService);
 };