| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/ui/app_list/start_page_service.h" | 5 #include "chrome/browser/ui/app_list/start_page_service.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/memory/singleton.h" | 10 #include "base/memory/singleton.h" |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 #include "content/public/browser/web_contents.h" | 27 #include "content/public/browser/web_contents.h" |
| 28 #include "content/public/browser/web_contents_delegate.h" | 28 #include "content/public/browser/web_contents_delegate.h" |
| 29 #include "extensions/common/extension.h" | 29 #include "extensions/common/extension.h" |
| 30 #include "ui/app_list/app_list_switches.h" | 30 #include "ui/app_list/app_list_switches.h" |
| 31 | 31 |
| 32 namespace app_list { | 32 namespace app_list { |
| 33 | 33 |
| 34 class StartPageService::Factory : public BrowserContextKeyedServiceFactory { | 34 class StartPageService::Factory : public BrowserContextKeyedServiceFactory { |
| 35 public: | 35 public: |
| 36 static StartPageService* GetForProfile(Profile* profile) { | 36 static StartPageService* GetForProfile(Profile* profile) { |
| 37 CommandLine* command_line = CommandLine::ForCurrentProcess(); | 37 if (!CommandLine::ForCurrentProcess()->HasSwitch( |
| 38 if (!command_line->HasSwitch(::switches::kShowAppListStartPage) && | 38 ::switches::kShowAppListStartPage) && |
| 39 !command_line->HasSwitch(app_list::switches::kEnableVoiceSearch)) { | 39 !app_list::switches::IsVoiceSearchEnabled()) { |
| 40 return NULL; | 40 return NULL; |
| 41 } | 41 } |
| 42 | 42 |
| 43 return static_cast<StartPageService*>( | 43 return static_cast<StartPageService*>( |
| 44 GetInstance()->GetServiceForBrowserContext(profile, true)); | 44 GetInstance()->GetServiceForBrowserContext(profile, true)); |
| 45 } | 45 } |
| 46 | 46 |
| 47 static Factory* GetInstance() { | 47 static Factory* GetInstance() { |
| 48 return Singleton<Factory>::get(); | 48 return Singleton<Factory>::get(); |
| 49 } | 49 } |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 158 contents_->GetWebUI()->CallJavascriptFunction( | 158 contents_->GetWebUI()->CallJavascriptFunction( |
| 159 "appList.startPage.toggleSpeechRecognition"); | 159 "appList.startPage.toggleSpeechRecognition"); |
| 160 } | 160 } |
| 161 | 161 |
| 162 content::WebContents* StartPageService::GetStartPageContents() { | 162 content::WebContents* StartPageService::GetStartPageContents() { |
| 163 return CommandLine::ForCurrentProcess()->HasSwitch( | 163 return CommandLine::ForCurrentProcess()->HasSwitch( |
| 164 ::switches::kShowAppListStartPage) ? contents_.get() : NULL; | 164 ::switches::kShowAppListStartPage) ? contents_.get() : NULL; |
| 165 } | 165 } |
| 166 | 166 |
| 167 content::WebContents* StartPageService::GetSpeechRecognitionContents() { | 167 content::WebContents* StartPageService::GetSpeechRecognitionContents() { |
| 168 // Speech recognition is available if either of start-page or voice-search | 168 return app_list::switches::IsVoiceSearchEnabled() ? contents_.get() : NULL; |
| 169 // is enabled. | |
| 170 return contents_.get(); | |
| 171 } | 169 } |
| 172 | 170 |
| 173 void StartPageService::OnSpeechResult( | 171 void StartPageService::OnSpeechResult( |
| 174 const base::string16& query, bool is_final) { | 172 const base::string16& query, bool is_final) { |
| 175 FOR_EACH_OBSERVER(StartPageObserver, | 173 FOR_EACH_OBSERVER(StartPageObserver, |
| 176 observers_, | 174 observers_, |
| 177 OnSpeechResult(query, is_final)); | 175 OnSpeechResult(query, is_final)); |
| 178 } | 176 } |
| 179 | 177 |
| 180 void StartPageService::OnSpeechSoundLevelChanged(int16 level) { | 178 void StartPageService::OnSpeechSoundLevelChanged(int16 level) { |
| 181 FOR_EACH_OBSERVER(StartPageObserver, | 179 FOR_EACH_OBSERVER(StartPageObserver, |
| 182 observers_, | 180 observers_, |
| 183 OnSpeechSoundLevelChanged(level)); | 181 OnSpeechSoundLevelChanged(level)); |
| 184 } | 182 } |
| 185 | 183 |
| 186 void StartPageService::OnSpeechRecognitionStateChanged( | 184 void StartPageService::OnSpeechRecognitionStateChanged( |
| 187 SpeechRecognitionState new_state) { | 185 SpeechRecognitionState new_state) { |
| 188 FOR_EACH_OBSERVER(StartPageObserver, | 186 FOR_EACH_OBSERVER(StartPageObserver, |
| 189 observers_, | 187 observers_, |
| 190 OnSpeechRecognitionStateChanged(new_state)); | 188 OnSpeechRecognitionStateChanged(new_state)); |
| 191 } | 189 } |
| 192 | 190 |
| 193 void StartPageService::Shutdown() { | 191 void StartPageService::Shutdown() { |
| 194 contents_.reset(); | 192 contents_.reset(); |
| 195 } | 193 } |
| 196 | 194 |
| 197 } // namespace app_list | 195 } // namespace app_list |
| OLD | NEW |