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

Side by Side Diff: chrome/browser/ui/webui/settings/search_engines_handler.cc

Issue 2572963004: MD Settings: Add "Show Google Now cards in the launcher" row in Search section. (Closed)
Patch Set: Rebase Created 4 years 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/webui/settings/search_engines_handler.h" 5 #include "chrome/browser/ui/webui/settings/search_engines_handler.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/memory/ptr_util.h" 8 #include "base/memory/ptr_util.h"
9 #include "base/metrics/field_trial.h"
9 #include "base/strings/string_number_conversions.h" 10 #include "base/strings/string_number_conversions.h"
10 #include "base/strings/utf_string_conversions.h" 11 #include "base/strings/utf_string_conversions.h"
11 #include "base/values.h" 12 #include "base/values.h"
12 #include "chrome/browser/extensions/extension_util.h" 13 #include "chrome/browser/extensions/extension_util.h"
13 #include "chrome/browser/profiles/profile.h" 14 #include "chrome/browser/profiles/profile.h"
14 #include "chrome/browser/search/hotword_audio_history_handler.h" 15 #include "chrome/browser/search/hotword_audio_history_handler.h"
15 #include "chrome/browser/search/hotword_service.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/search_engines/template_url_service_factory.h" 18 #include "chrome/browser/search_engines/template_url_service_factory.h"
18 #include "chrome/browser/search_engines/ui_thread_search_terms_data.h" 19 #include "chrome/browser/search_engines/ui_thread_search_terms_data.h"
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 url_template->url_ref().HasGoogleBaseURLs( 63 url_template->url_ref().HasGoogleBaseURLs(
63 template_url_service->search_terms_data()); 64 template_url_service->search_terms_data());
64 } 65 }
65 66
66 bool GetHotwordAlwaysOn(Profile* profile) { 67 bool GetHotwordAlwaysOn(Profile* profile) {
67 SigninManagerBase* signin = SigninManagerFactory::GetForProfile(profile); 68 SigninManagerBase* signin = SigninManagerFactory::GetForProfile(profile);
68 return signin && signin->IsAuthenticated() && 69 return signin && signin->IsAuthenticated() &&
69 HotwordServiceFactory::IsAlwaysOnAvailable(); 70 HotwordServiceFactory::IsAlwaysOnAvailable();
70 } 71 }
71 72
73 bool IsGoogleNowAvailable(Profile* profile) {
74 std::string group = base::FieldTrialList::FindFullName("GoogleNowExtension");
75 bool has_field_trial = !group.empty() && group != "Disabled";
76 return has_field_trial && IsGoogleDefaultSearch(profile);
77 }
78
72 } // namespace 79 } // namespace
73 80
74 namespace settings { 81 namespace settings {
75 82
76 SearchEnginesHandler::SearchEnginesHandler(Profile* profile) 83 SearchEnginesHandler::SearchEnginesHandler(Profile* profile)
77 : profile_(profile), list_controller_(profile), weak_ptr_factory_(this) { 84 : profile_(profile), list_controller_(profile), weak_ptr_factory_(this) {
78 pref_change_registrar_.Init(profile_->GetPrefs()); 85 pref_change_registrar_.Init(profile_->GetPrefs());
79 } 86 }
80 87
81 SearchEnginesHandler::~SearchEnginesHandler() { 88 SearchEnginesHandler::~SearchEnginesHandler() {
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 "searchEngineEditCompleted", 120 "searchEngineEditCompleted",
114 base::Bind(&SearchEnginesHandler::HandleSearchEngineEditCompleted, 121 base::Bind(&SearchEnginesHandler::HandleSearchEngineEditCompleted,
115 base::Unretained(this))); 122 base::Unretained(this)));
116 web_ui()->RegisterMessageCallback( 123 web_ui()->RegisterMessageCallback(
117 "getHotwordInfo", base::Bind(&SearchEnginesHandler::HandleGetHotwordInfo, 124 "getHotwordInfo", base::Bind(&SearchEnginesHandler::HandleGetHotwordInfo,
118 base::Unretained(this))); 125 base::Unretained(this)));
119 web_ui()->RegisterMessageCallback( 126 web_ui()->RegisterMessageCallback(
120 "setHotwordSearchEnabled", 127 "setHotwordSearchEnabled",
121 base::Bind(&SearchEnginesHandler::HandleSetHotwordSearchEnabled, 128 base::Bind(&SearchEnginesHandler::HandleSetHotwordSearchEnabled,
122 base::Unretained(this))); 129 base::Unretained(this)));
130 web_ui()->RegisterMessageCallback(
131 "getGoogleNowAvailability",
132 base::Bind(&SearchEnginesHandler::HandleGetGoogleNowAvailability,
133 base::Unretained(this)));
123 } 134 }
124 135
125 void SearchEnginesHandler::OnJavascriptAllowed() { 136 void SearchEnginesHandler::OnJavascriptAllowed() {
126 list_controller_.table_model()->SetObserver(this); 137 list_controller_.table_model()->SetObserver(this);
127 pref_change_registrar_.Add(prefs::kHotwordSearchEnabled, 138 pref_change_registrar_.Add(prefs::kHotwordSearchEnabled,
128 base::Bind(&SearchEnginesHandler::SendHotwordInfo, 139 base::Bind(&SearchEnginesHandler::SendHotwordInfo,
129 base::Unretained(this))); 140 base::Unretained(this)));
130 pref_change_registrar_.Add(prefs::kHotwordAlwaysOnSearchEnabled, 141 pref_change_registrar_.Add(prefs::kHotwordAlwaysOnSearchEnabled,
131 base::Bind(&SearchEnginesHandler::SendHotwordInfo, 142 base::Bind(&SearchEnginesHandler::SendHotwordInfo,
132 base::Unretained(this))); 143 base::Unretained(this)));
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 search_engines_info->Set("extensions", 190 search_engines_info->Set("extensions",
180 base::WrapUnique(extensions.release())); 191 base::WrapUnique(extensions.release()));
181 return search_engines_info; 192 return search_engines_info;
182 } 193 }
183 194
184 void SearchEnginesHandler::OnModelChanged() { 195 void SearchEnginesHandler::OnModelChanged() {
185 AllowJavascript(); 196 AllowJavascript();
186 CallJavascriptFunction("cr.webUIListenerCallback", 197 CallJavascriptFunction("cr.webUIListenerCallback",
187 base::StringValue("search-engines-changed"), 198 base::StringValue("search-engines-changed"),
188 *GetSearchEnginesList()); 199 *GetSearchEnginesList());
200 // Google Now availability may have changed.
201 CallJavascriptFunction(
202 "cr.webUIListenerCallback",
203 base::StringValue("google-now-availability-changed"),
204 base::FundamentalValue(IsGoogleNowAvailable(profile_)));
189 } 205 }
190 206
191 void SearchEnginesHandler::OnItemsChanged(int start, int length) { 207 void SearchEnginesHandler::OnItemsChanged(int start, int length) {
192 OnModelChanged(); 208 OnModelChanged();
193 } 209 }
194 210
195 void SearchEnginesHandler::OnItemsAdded(int start, int length) { 211 void SearchEnginesHandler::OnItemsAdded(int start, int length) {
196 OnModelChanged(); 212 OnModelChanged();
197 } 213 }
198 214
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after
425 441
426 // OnGetHotwordAudioHistoryEnabled will call HotwordInfoComplete(). 442 // OnGetHotwordAudioHistoryEnabled will call HotwordInfoComplete().
427 HotwordServiceFactory::GetForProfile(profile_) 443 HotwordServiceFactory::GetForProfile(profile_)
428 ->GetAudioHistoryHandler() 444 ->GetAudioHistoryHandler()
429 ->GetAudioHistoryEnabled( 445 ->GetAudioHistoryEnabled(
430 base::Bind(&SearchEnginesHandler::OnGetHotwordAudioHistoryEnabled, 446 base::Bind(&SearchEnginesHandler::OnGetHotwordAudioHistoryEnabled,
431 weak_ptr_factory_.GetWeakPtr(), base::Passed(&callback_id), 447 weak_ptr_factory_.GetWeakPtr(), base::Passed(&callback_id),
432 base::Passed(&status))); 448 base::Passed(&status)));
433 } 449 }
434 450
451 void SearchEnginesHandler::HandleGetGoogleNowAvailability(
452 const base::ListValue* args) {
453 CHECK_EQ(1U, args->GetSize());
454 const base::Value* callback_id;
455 CHECK(args->Get(0, &callback_id));
456 AllowJavascript();
457 ResolveJavascriptCallback(
458 *callback_id, base::FundamentalValue(IsGoogleNowAvailable(profile_)));
459 }
460
435 std::unique_ptr<base::DictionaryValue> SearchEnginesHandler::GetHotwordInfo() { 461 std::unique_ptr<base::DictionaryValue> SearchEnginesHandler::GetHotwordInfo() {
436 auto status = base::MakeUnique<base::DictionaryValue>(); 462 auto status = base::MakeUnique<base::DictionaryValue>();
437 if (!IsGoogleDefaultSearch(profile_)) { 463 if (!IsGoogleDefaultSearch(profile_)) {
438 status->SetBoolean(kHotwordSatusAllowed, false); 464 status->SetBoolean(kHotwordSatusAllowed, false);
439 return status; 465 return status;
440 } 466 }
441 467
442 status->SetBoolean(kHotwordSatusAllowed, 468 status->SetBoolean(kHotwordSatusAllowed,
443 HotwordServiceFactory::IsHotwordAllowed(profile_)); 469 HotwordServiceFactory::IsHotwordAllowed(profile_));
444 470
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
531 bool logging_enabled = 557 bool logging_enabled =
532 profile_->GetPrefs()->GetBoolean(prefs::kHotwordAudioLoggingEnabled); 558 profile_->GetPrefs()->GetBoolean(prefs::kHotwordAudioLoggingEnabled);
533 launch_mode = logging_enabled ? HotwordService::HOTWORD_ONLY 559 launch_mode = logging_enabled ? HotwordService::HOTWORD_ONLY
534 : HotwordService::HOTWORD_AND_AUDIO_HISTORY; 560 : HotwordService::HOTWORD_AND_AUDIO_HISTORY;
535 } 561 }
536 hotword_service->OptIntoHotwording(launch_mode); 562 hotword_service->OptIntoHotwording(launch_mode);
537 SendHotwordInfo(); 563 SendHotwordInfo();
538 } 564 }
539 565
540 } // namespace settings 566 } // namespace settings
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/settings/search_engines_handler.h ('k') | chrome/test/data/webui/settings/search_page_test.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698