Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(258)

Side by Side Diff: chrome/browser/ui/app_list/start_page_service.cc

Issue 471853002: Use the new hotword extension in the launcher when it is enabled. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 // Trasitioning into the "hotword recognizing" state is handled by the hotword
arv (Not doing code reviews) 2014/08/14 15:48:06 typo
Anand Mistry (off Chromium) 2014/08/15 00:14:51 Done.
109 // 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 bool hotwordEnabled = HotwordEnabled();
Jun Mukai 2014/08/14 22:10:08 variable names are in style of hotword_enabled Al
Anand Mistry (off Chromium) 2014/08/15 00:14:51 Done.
132 // If experimental hotwording is enabled, don't enable hotwording in the
133 // start page, since the hotword extension is taking care of this.
134 if (HotwordService::IsExperimentalHotwordingEnabled())
135 hotwordEnabled = false;
Jun Mukai 2014/08/14 22:10:08 You can simply hotword_enabled = HotwordEnabled()
Anand Mistry (off Chromium) 2014/08/15 00:14:51 Done.
136
124 contents_->GetWebUI()->CallJavascriptFunction( 137 contents_->GetWebUI()->CallJavascriptFunction(
125 "appList.startPage.onAppListShown", 138 "appList.startPage.onAppListShown",
126 base::FundamentalValue(HotwordEnabled())); 139 base::FundamentalValue(hotwordEnabled));
127 } 140 }
128 } 141 }
129 142
130 void StartPageService::AppListHidden() { 143 void StartPageService::AppListHidden() {
131 contents_->GetWebUI()->CallJavascriptFunction( 144 contents_->GetWebUI()->CallJavascriptFunction(
132 "appList.startPage.onAppListHidden"); 145 "appList.startPage.onAppListHidden");
133 if (!app_list::switches::IsExperimentalAppListEnabled()) 146 if (!app_list::switches::IsExperimentalAppListEnabled())
134 UnloadContents(); 147 UnloadContents();
135 } 148 }
136 149
137 void StartPageService::ToggleSpeechRecognition() { 150 void StartPageService::ToggleSpeechRecognition() {
138 speech_button_toggled_manually_ = true; 151 speech_button_toggled_manually_ = true;
139 contents_->GetWebUI()->CallJavascriptFunction( 152 contents_->GetWebUI()->CallJavascriptFunction(
140 "appList.startPage.toggleSpeechRecognition"); 153 "appList.startPage.toggleSpeechRecognition");
141 } 154 }
142 155
143 bool StartPageService::HotwordEnabled() { 156 bool StartPageService::HotwordEnabled() {
157 if (HotwordService::IsExperimentalHotwordingEnabled())
arv (Not doing code reviews) 2014/08/14 15:48:06 needs {}
Anand Mistry (off Chromium) 2014/08/15 00:14:51 Done.
158 return HotwordServiceFactory::IsServiceAvailable(profile_) &&
159 profile_->GetPrefs()->GetBoolean(prefs::kHotwordSearchEnabled);
144 #if defined(OS_CHROMEOS) 160 #if defined(OS_CHROMEOS)
145 return HotwordServiceFactory::IsServiceAvailable(profile_) && 161 return HotwordServiceFactory::IsServiceAvailable(profile_) &&
146 profile_->GetPrefs()->GetBoolean(prefs::kHotwordSearchEnabled); 162 profile_->GetPrefs()->GetBoolean(prefs::kHotwordSearchEnabled);
147 #else 163 #else
148 return false; 164 return false;
149 #endif 165 #endif
150 } 166 }
151 167
152 content::WebContents* StartPageService::GetStartPageContents() { 168 content::WebContents* StartPageService::GetStartPageContents() {
153 return app_list::switches::IsExperimentalAppListEnabled() ? contents_.get() 169 return app_list::switches::IsExperimentalAppListEnabled() ? contents_.get()
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 content::Referrer(), 239 content::Referrer(),
224 content::PAGE_TRANSITION_AUTO_TOPLEVEL, 240 content::PAGE_TRANSITION_AUTO_TOPLEVEL,
225 std::string()); 241 std::string());
226 } 242 }
227 243
228 void StartPageService::UnloadContents() { 244 void StartPageService::UnloadContents() {
229 contents_.reset(); 245 contents_.reset();
230 } 246 }
231 247
232 } // namespace app_list 248 } // namespace app_list
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698