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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/webui/settings/search_engines_handler.cc
diff --git a/chrome/browser/ui/webui/settings/search_engines_handler.cc b/chrome/browser/ui/webui/settings/search_engines_handler.cc
index aea264edde5c5281f147dea50d32ff7527214101..994f79ff57fb1408afb98d0da351d870d87c6839 100644
--- a/chrome/browser/ui/webui/settings/search_engines_handler.cc
+++ b/chrome/browser/ui/webui/settings/search_engines_handler.cc
@@ -6,6 +6,7 @@
#include "base/bind.h"
#include "base/memory/ptr_util.h"
+#include "base/metrics/field_trial.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/utf_string_conversions.h"
#include "base/values.h"
@@ -69,6 +70,12 @@ bool GetHotwordAlwaysOn(Profile* profile) {
HotwordServiceFactory::IsAlwaysOnAvailable();
}
+bool IsGoogleNowAvailable(Profile* profile) {
+ std::string group = base::FieldTrialList::FindFullName("GoogleNowExtension");
+ bool has_field_trial = !group.empty() && group != "Disabled";
+ return has_field_trial && IsGoogleDefaultSearch(profile);
+}
+
} // namespace
namespace settings {
@@ -120,6 +127,10 @@ void SearchEnginesHandler::RegisterMessages() {
"setHotwordSearchEnabled",
base::Bind(&SearchEnginesHandler::HandleSetHotwordSearchEnabled,
base::Unretained(this)));
+ web_ui()->RegisterMessageCallback(
+ "getGoogleNowAvailability",
+ base::Bind(&SearchEnginesHandler::HandleGetGoogleNowAvailability,
+ base::Unretained(this)));
}
void SearchEnginesHandler::OnJavascriptAllowed() {
@@ -186,6 +197,11 @@ void SearchEnginesHandler::OnModelChanged() {
CallJavascriptFunction("cr.webUIListenerCallback",
base::StringValue("search-engines-changed"),
*GetSearchEnginesList());
+ // Google Now availability may have changed.
+ CallJavascriptFunction(
+ "cr.webUIListenerCallback",
+ base::StringValue("google-now-availability-changed"),
+ base::FundamentalValue(IsGoogleNowAvailable(profile_)));
}
void SearchEnginesHandler::OnItemsChanged(int start, int length) {
@@ -432,6 +448,16 @@ void SearchEnginesHandler::HandleGetHotwordInfo(const base::ListValue* args) {
base::Passed(&status)));
}
+void SearchEnginesHandler::HandleGetGoogleNowAvailability(
+ const base::ListValue* args) {
+ CHECK_EQ(1U, args->GetSize());
+ const base::Value* callback_id;
+ CHECK(args->Get(0, &callback_id));
+ AllowJavascript();
+ ResolveJavascriptCallback(
+ *callback_id, base::FundamentalValue(IsGoogleNowAvailable(profile_)));
+}
+
std::unique_ptr<base::DictionaryValue> SearchEnginesHandler::GetHotwordInfo() {
auto status = base::MakeUnique<base::DictionaryValue>();
if (!IsGoogleDefaultSearch(profile_)) {
« 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