| 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" |
| 11 #include "base/metrics/user_metrics.h" | 11 #include "base/metrics/user_metrics.h" |
| 12 #include "base/prefs/pref_service.h" | 12 #include "base/prefs/pref_service.h" |
| 13 #include "chrome/browser/chrome_notification_types.h" | 13 #include "chrome/browser/chrome_notification_types.h" |
| 14 #include "chrome/browser/media/media_stream_infobar_delegate.h" | 14 #include "chrome/browser/media/media_stream_infobar_delegate.h" |
| 15 #include "chrome/browser/profiles/profile.h" | 15 #include "chrome/browser/profiles/profile.h" |
| 16 #include "chrome/browser/search/hotword_service.h" | |
| 17 #include "chrome/browser/search/hotword_service_factory.h" | 16 #include "chrome/browser/search/hotword_service_factory.h" |
| 18 #include "chrome/browser/ui/app_list/recommended_apps.h" | 17 #include "chrome/browser/ui/app_list/recommended_apps.h" |
| 19 #include "chrome/browser/ui/app_list/start_page_observer.h" | 18 #include "chrome/browser/ui/app_list/start_page_observer.h" |
| 20 #include "chrome/browser/ui/app_list/start_page_service_factory.h" | 19 #include "chrome/browser/ui/app_list/start_page_service_factory.h" |
| 21 #include "chrome/common/chrome_switches.h" | 20 #include "chrome/common/chrome_switches.h" |
| 22 #include "chrome/common/pref_names.h" | 21 #include "chrome/common/pref_names.h" |
| 23 #include "chrome/common/url_constants.h" | 22 #include "chrome/common/url_constants.h" |
| 24 #include "content/public/browser/notification_details.h" | 23 #include "content/public/browser/notification_details.h" |
| 25 #include "content/public/browser/notification_observer.h" | 24 #include "content/public/browser/notification_observer.h" |
| 26 #include "content/public/browser/notification_registrar.h" | 25 #include "content/public/browser/notification_registrar.h" |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 return StartPageServiceFactory::GetForProfile(profile); | 96 return StartPageServiceFactory::GetForProfile(profile); |
| 98 } | 97 } |
| 99 | 98 |
| 100 StartPageService::StartPageService(Profile* profile) | 99 StartPageService::StartPageService(Profile* profile) |
| 101 : profile_(profile), | 100 : profile_(profile), |
| 102 profile_destroy_observer_(new ProfileDestroyObserver(this)), | 101 profile_destroy_observer_(new ProfileDestroyObserver(this)), |
| 103 recommended_apps_(new RecommendedApps(profile)), | 102 recommended_apps_(new RecommendedApps(profile)), |
| 104 state_(app_list::SPEECH_RECOGNITION_OFF), | 103 state_(app_list::SPEECH_RECOGNITION_OFF), |
| 105 speech_button_toggled_manually_(false), | 104 speech_button_toggled_manually_(false), |
| 106 speech_result_obtained_(false) { | 105 speech_result_obtained_(false) { |
| 107 #if defined(OS_CHROMEOS) | |
| 108 // Updates the default state to hotword listening, because this is | |
| 109 // the default behavior. This will be updated when the page is loaded and | |
| 110 // the nacl module is loaded. | |
| 111 if (app_list::switches::IsVoiceSearchEnabled()) | |
| 112 state_ = app_list::SPEECH_RECOGNITION_HOTWORD_LISTENING; | |
| 113 #endif | |
| 114 | |
| 115 if (app_list::switches::IsExperimentalAppListEnabled()) | 106 if (app_list::switches::IsExperimentalAppListEnabled()) |
| 116 LoadContents(); | 107 LoadContents(); |
| 117 } | 108 } |
| 118 | 109 |
| 119 StartPageService::~StartPageService() {} | 110 StartPageService::~StartPageService() {} |
| 120 | 111 |
| 121 void StartPageService::AddObserver(StartPageObserver* observer) { | 112 void StartPageService::AddObserver(StartPageObserver* observer) { |
| 122 observers_.AddObserver(observer); | 113 observers_.AddObserver(observer); |
| 123 } | 114 } |
| 124 | 115 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 144 } | 135 } |
| 145 | 136 |
| 146 void StartPageService::ToggleSpeechRecognition() { | 137 void StartPageService::ToggleSpeechRecognition() { |
| 147 speech_button_toggled_manually_ = true; | 138 speech_button_toggled_manually_ = true; |
| 148 contents_->GetWebUI()->CallJavascriptFunction( | 139 contents_->GetWebUI()->CallJavascriptFunction( |
| 149 "appList.startPage.toggleSpeechRecognition"); | 140 "appList.startPage.toggleSpeechRecognition"); |
| 150 } | 141 } |
| 151 | 142 |
| 152 bool StartPageService::HotwordEnabled() { | 143 bool StartPageService::HotwordEnabled() { |
| 153 #if defined(OS_CHROMEOS) | 144 #if defined(OS_CHROMEOS) |
| 154 if (!HotwordService::DoesHotwordSupportLanguage(profile_)) | 145 return HotwordServiceFactory::IsServiceAvailable(profile_) && |
| 155 return false; | 146 profile_->GetPrefs()->GetBoolean(prefs::kHotwordSearchEnabled); |
| 156 | |
| 157 const PrefService::Preference* preference = | |
| 158 profile_->GetPrefs()->FindPreference(prefs::kHotwordSearchEnabled); | |
| 159 if (!preference) | |
| 160 return false; | |
| 161 | |
| 162 if (!HotwordServiceFactory::IsServiceAvailable(profile_)) | |
| 163 return false; | |
| 164 | |
| 165 // kHotwordSearchEnabled is off by default, but app-list is on by default. | |
| 166 // To achieve this, we'll return true if it's in the default status. | |
| 167 if (preference->IsDefaultValue()) | |
| 168 return true; | |
| 169 | |
| 170 bool isEnabled = false; | |
| 171 return preference->GetValue()->GetAsBoolean(&isEnabled) && isEnabled; | |
| 172 #else | 147 #else |
| 173 return false; | 148 return false; |
| 174 #endif | 149 #endif |
| 175 } | 150 } |
| 176 | 151 |
| 177 content::WebContents* StartPageService::GetStartPageContents() { | 152 content::WebContents* StartPageService::GetStartPageContents() { |
| 178 return app_list::switches::IsExperimentalAppListEnabled() ? contents_.get() | 153 return app_list::switches::IsExperimentalAppListEnabled() ? contents_.get() |
| 179 : NULL; | 154 : NULL; |
| 180 } | 155 } |
| 181 | 156 |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 248 content::Referrer(), | 223 content::Referrer(), |
| 249 content::PAGE_TRANSITION_AUTO_TOPLEVEL, | 224 content::PAGE_TRANSITION_AUTO_TOPLEVEL, |
| 250 std::string()); | 225 std::string()); |
| 251 } | 226 } |
| 252 | 227 |
| 253 void StartPageService::UnloadContents() { | 228 void StartPageService::UnloadContents() { |
| 254 contents_.reset(); | 229 contents_.reset(); |
| 255 } | 230 } |
| 256 | 231 |
| 257 } // namespace app_list | 232 } // namespace app_list |
| OLD | NEW |