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 18 matching lines...) Expand all Loading... |
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 CommandLine* command_line = CommandLine::ForCurrentProcess(); |
38 if (!command_line->HasSwitch(::switches::kShowAppListStartPage) && | 38 if (!command_line->HasSwitch(::switches::kShowAppListStartPage) && |
39 !command_line->HasSwitch(app_list::switches::kEnableVoiceSearch)) { | 39 command_line->HasSwitch(app_list::switches::kDisableVoiceSearch)) { |
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 CommandLine::ForCurrentProcess()->HasSwitch( |
169 // is enabled. | 169 app_list::switches::kDisableVoiceSearch) ? NULL : contents_.get(); |
170 return contents_.get(); | |
171 } | 170 } |
172 | 171 |
173 void StartPageService::OnSpeechResult( | 172 void StartPageService::OnSpeechResult( |
174 const base::string16& query, bool is_final) { | 173 const base::string16& query, bool is_final) { |
175 FOR_EACH_OBSERVER(StartPageObserver, | 174 FOR_EACH_OBSERVER(StartPageObserver, |
176 observers_, | 175 observers_, |
177 OnSpeechResult(query, is_final)); | 176 OnSpeechResult(query, is_final)); |
178 } | 177 } |
179 | 178 |
180 void StartPageService::OnSpeechSoundLevelChanged(int16 level) { | 179 void StartPageService::OnSpeechSoundLevelChanged(int16 level) { |
181 FOR_EACH_OBSERVER(StartPageObserver, | 180 FOR_EACH_OBSERVER(StartPageObserver, |
182 observers_, | 181 observers_, |
183 OnSpeechSoundLevelChanged(level)); | 182 OnSpeechSoundLevelChanged(level)); |
184 } | 183 } |
185 | 184 |
186 void StartPageService::OnSpeechRecognitionStateChanged( | 185 void StartPageService::OnSpeechRecognitionStateChanged( |
187 SpeechRecognitionState new_state) { | 186 SpeechRecognitionState new_state) { |
188 FOR_EACH_OBSERVER(StartPageObserver, | 187 FOR_EACH_OBSERVER(StartPageObserver, |
189 observers_, | 188 observers_, |
190 OnSpeechRecognitionStateChanged(new_state)); | 189 OnSpeechRecognitionStateChanged(new_state)); |
191 } | 190 } |
192 | 191 |
193 void StartPageService::Shutdown() { | 192 void StartPageService::Shutdown() { |
194 contents_.reset(); | 193 contents_.reset(); |
195 } | 194 } |
196 | 195 |
197 } // namespace app_list | 196 } // namespace app_list |
OLD | NEW |