Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / ui / app_list / start_page_service.h
index 7bcded2..61e2260 100644 (file)
@@ -5,13 +5,17 @@
 #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 "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"
@@ -25,11 +29,13 @@ 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 KeyedService {
+class StartPageService : public KeyedService,
+                         public SpeechRecognizerDelegate {
  public:
   typedef std::vector<scoped_refptr<const extensions::Extension> >
       ExtensionList;
@@ -43,6 +49,9 @@ class StartPageService : public KeyedService {
   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();
 
@@ -54,9 +63,18 @@ class StartPageService : public KeyedService {
   RecommendedApps* recommended_apps() { return recommended_apps_.get(); }
   Profile* profile() { return profile_; }
   SpeechRecognitionState state() { return state_; }
-  void OnSpeechResult(const base::string16& query, bool is_final);
-  void OnSpeechSoundLevelChanged(int16 level);
-  void OnSpeechRecognitionStateChanged(SpeechRecognitionState new_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:
   friend class StartPageServiceFactory;
@@ -70,14 +88,11 @@ class StartPageService : public KeyedService {
   // getUserMedia() request from the web contents.
   class StartPageWebContentsDelegate;
 
-  explicit StartPageService(Profile* profile);
-  virtual ~StartPageService();
-
   void LoadContents();
   void UnloadContents();
 
   // KeyedService overrides:
-  virtual void Shutdown() OVERRIDE;
+  void Shutdown() override;
 
   Profile* profile_;
   scoped_ptr<content::WebContents> contents_;
@@ -89,6 +104,13 @@ class StartPageService : public KeyedService {
   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);
 };