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" |
16 #include "chrome/browser/search/hotword_service_factory.h" | 17 #include "chrome/browser/search/hotword_service_factory.h" |
17 #include "chrome/browser/ui/app_list/recommended_apps.h" | 18 #include "chrome/browser/ui/app_list/recommended_apps.h" |
18 #include "chrome/browser/ui/app_list/start_page_observer.h" | 19 #include "chrome/browser/ui/app_list/start_page_observer.h" |
19 #include "chrome/browser/ui/app_list/start_page_service_factory.h" | 20 #include "chrome/browser/ui/app_list/start_page_service_factory.h" |
20 #include "chrome/common/chrome_switches.h" | 21 #include "chrome/common/chrome_switches.h" |
21 #include "chrome/common/pref_names.h" | 22 #include "chrome/common/pref_names.h" |
22 #include "chrome/common/url_constants.h" | 23 #include "chrome/common/url_constants.h" |
23 #include "content/public/browser/notification_details.h" | 24 #include "content/public/browser/notification_details.h" |
24 #include "content/public/browser/notification_observer.h" | 25 #include "content/public/browser/notification_observer.h" |
25 #include "content/public/browser/notification_registrar.h" | 26 #include "content/public/browser/notification_registrar.h" |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 return StartPageServiceFactory::GetForProfile(profile); | 97 return StartPageServiceFactory::GetForProfile(profile); |
97 } | 98 } |
98 | 99 |
99 StartPageService::StartPageService(Profile* profile) | 100 StartPageService::StartPageService(Profile* profile) |
100 : profile_(profile), | 101 : profile_(profile), |
101 profile_destroy_observer_(new ProfileDestroyObserver(this)), | 102 profile_destroy_observer_(new ProfileDestroyObserver(this)), |
102 recommended_apps_(new RecommendedApps(profile)), | 103 recommended_apps_(new RecommendedApps(profile)), |
103 state_(app_list::SPEECH_RECOGNITION_OFF), | 104 state_(app_list::SPEECH_RECOGNITION_OFF), |
104 speech_button_toggled_manually_(false), | 105 speech_button_toggled_manually_(false), |
105 speech_result_obtained_(false) { | 106 speech_result_obtained_(false) { |
| 107 // If experimental hotwording is enabled, then we're always "ready". |
| 108 // Transitioning into the "hotword recognizing" state is handled by the |
| 109 // hotword extension. |
| 110 if (HotwordService::IsExperimentalHotwordingEnabled()) |
| 111 state_ = app_list::SPEECH_RECOGNITION_READY; |
| 112 |
106 if (app_list::switches::IsExperimentalAppListEnabled()) | 113 if (app_list::switches::IsExperimentalAppListEnabled()) |
107 LoadContents(); | 114 LoadContents(); |
108 } | 115 } |
109 | 116 |
110 StartPageService::~StartPageService() {} | 117 StartPageService::~StartPageService() {} |
111 | 118 |
112 void StartPageService::AddObserver(StartPageObserver* observer) { | 119 void StartPageService::AddObserver(StartPageObserver* observer) { |
113 observers_.AddObserver(observer); | 120 observers_.AddObserver(observer); |
114 } | 121 } |
115 | 122 |
116 void StartPageService::RemoveObserver(StartPageObserver* observer) { | 123 void StartPageService::RemoveObserver(StartPageObserver* observer) { |
117 observers_.RemoveObserver(observer); | 124 observers_.RemoveObserver(observer); |
118 } | 125 } |
119 | 126 |
120 void StartPageService::AppListShown() { | 127 void StartPageService::AppListShown() { |
121 if (!contents_) { | 128 if (!contents_) { |
122 LoadContents(); | 129 LoadContents(); |
123 } else { | 130 } else { |
| 131 // If experimental hotwording is enabled, don't enable hotwording in the |
| 132 // start page, since the hotword extension is taking care of this. |
| 133 bool hotword_enabled = HotwordEnabled() && |
| 134 !HotwordService::IsExperimentalHotwordingEnabled(); |
124 contents_->GetWebUI()->CallJavascriptFunction( | 135 contents_->GetWebUI()->CallJavascriptFunction( |
125 "appList.startPage.onAppListShown", | 136 "appList.startPage.onAppListShown", |
126 base::FundamentalValue(HotwordEnabled())); | 137 base::FundamentalValue(hotword_enabled)); |
127 } | 138 } |
128 } | 139 } |
129 | 140 |
130 void StartPageService::AppListHidden() { | 141 void StartPageService::AppListHidden() { |
131 contents_->GetWebUI()->CallJavascriptFunction( | 142 contents_->GetWebUI()->CallJavascriptFunction( |
132 "appList.startPage.onAppListHidden"); | 143 "appList.startPage.onAppListHidden"); |
133 if (!app_list::switches::IsExperimentalAppListEnabled()) | 144 if (!app_list::switches::IsExperimentalAppListEnabled()) |
134 UnloadContents(); | 145 UnloadContents(); |
135 } | 146 } |
136 | 147 |
137 void StartPageService::ToggleSpeechRecognition() { | 148 void StartPageService::ToggleSpeechRecognition() { |
138 speech_button_toggled_manually_ = true; | 149 speech_button_toggled_manually_ = true; |
139 contents_->GetWebUI()->CallJavascriptFunction( | 150 contents_->GetWebUI()->CallJavascriptFunction( |
140 "appList.startPage.toggleSpeechRecognition"); | 151 "appList.startPage.toggleSpeechRecognition"); |
141 } | 152 } |
142 | 153 |
143 bool StartPageService::HotwordEnabled() { | 154 bool StartPageService::HotwordEnabled() { |
| 155 if (HotwordService::IsExperimentalHotwordingEnabled()) { |
| 156 return HotwordServiceFactory::IsServiceAvailable(profile_) && |
| 157 profile_->GetPrefs()->GetBoolean(prefs::kHotwordSearchEnabled); |
| 158 } |
144 #if defined(OS_CHROMEOS) | 159 #if defined(OS_CHROMEOS) |
145 return HotwordServiceFactory::IsServiceAvailable(profile_) && | 160 return HotwordServiceFactory::IsServiceAvailable(profile_) && |
146 profile_->GetPrefs()->GetBoolean(prefs::kHotwordSearchEnabled); | 161 profile_->GetPrefs()->GetBoolean(prefs::kHotwordSearchEnabled); |
147 #else | 162 #else |
148 return false; | 163 return false; |
149 #endif | 164 #endif |
150 } | 165 } |
151 | 166 |
152 content::WebContents* StartPageService::GetStartPageContents() { | 167 content::WebContents* StartPageService::GetStartPageContents() { |
153 return app_list::switches::IsExperimentalAppListEnabled() ? contents_.get() | 168 return app_list::switches::IsExperimentalAppListEnabled() ? contents_.get() |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
223 content::Referrer(), | 238 content::Referrer(), |
224 content::PAGE_TRANSITION_AUTO_TOPLEVEL, | 239 content::PAGE_TRANSITION_AUTO_TOPLEVEL, |
225 std::string()); | 240 std::string()); |
226 } | 241 } |
227 | 242 |
228 void StartPageService::UnloadContents() { | 243 void StartPageService::UnloadContents() { |
229 contents_.reset(); | 244 contents_.reset(); |
230 } | 245 } |
231 | 246 |
232 } // namespace app_list | 247 } // namespace app_list |
OLD | NEW |