Chromium Code Reviews| Index: chrome/browser/search/contextual_search_promo_source_android.cc |
| diff --git a/chrome/browser/search/contextual_search_promo_source_android.cc b/chrome/browser/search/contextual_search_promo_source_android.cc |
| index 8a93de37a4bc716f35025bcfeacf9c7aff0b0848..3b65c422b8af902a3bb49f63cbffb49557c56d0e 100644 |
| --- a/chrome/browser/search/contextual_search_promo_source_android.cc |
| +++ b/chrome/browser/search/contextual_search_promo_source_android.cc |
| @@ -4,12 +4,14 @@ |
| #include "chrome/browser/search/contextual_search_promo_source_android.h" |
|
huangs
2014/09/23 13:44:38
#include <string> ?
Mathieu
2014/09/23 13:50:08
Done.
|
| +#include "base/json/json_string_value_serializer.h" |
| #include "base/memory/ref_counted_memory.h" |
| #include "base/strings/string_util.h" |
| #include "base/strings/stringprintf.h" |
| #include "base/values.h" |
| #include "chrome/common/url_constants.h" |
| #include "chrome/grit/chromium_strings.h" |
| +#include "components/variations/variations_associated_data.h" |
| #include "grit/browser_resources.h" |
| #include "ui/base/l10n/l10n_util.h" |
| #include "ui/base/resource/resource_bundle.h" |
| @@ -18,12 +20,43 @@ |
| namespace { |
| +const char kPromoConfigPath[] = "/config.js"; |
| const char kPromoHTMLPath[] = "/promo.html"; |
| const char kPromoCSSPath[] = "/promo.css"; |
| const char kPromoJSPath[] = "/promo.js"; |
| const char kRobotoWoffPath[] = "/roboto.woff"; |
| const char kRobotoWoff2Path[] = "/roboto.woff2"; |
| +// Field trial related constants. |
| +const char kContextualSearchFieldTrialName[] = "ContextualSearch"; |
| +const char kContextualSearchHidePromoHeaderParam[] = "hide_promo_header"; |
| +const char kContextualSearchEnabledValue[] = "enabled"; |
| + |
| +// Returns whether we should hide the first-run promo header. |
| +bool ShouldHidePromoHeader() { |
| + return variations::GetVariationParamValue( |
| + kContextualSearchFieldTrialName, kContextualSearchHidePromoHeaderParam) == |
| + kContextualSearchEnabledValue; |
| +} |
| + |
| +// Returns a JS dictionary of configuration data for the Contextual Search |
| +// promo. |
| +std::string GetConfigData() { |
| + base::DictionaryValue config_data; |
| + config_data.SetBoolean("hideHeader", ShouldHidePromoHeader()); |
| + |
| + // Serialize the dictionary. |
| + std::string js_text; |
| + JSONStringValueSerializer serializer(&js_text); |
| + serializer.Serialize(config_data); |
| + |
| + std::string config_data_js; |
| + config_data_js.append("var config = "); |
|
huangs
2014/09/23 13:44:38
Is |config| a global constant? Maybe |CONFIG| ins
Mathieu
2014/09/23 13:50:08
In this limited scope, I think it's fine.
|
| + config_data_js.append(js_text); |
| + config_data_js.append(";"); |
| + return config_data_js; |
| +} |
| + |
| } // namespace |
| ContextualSearchPromoSourceAndroid::ContextualSearchPromoSourceAndroid() {} |
| @@ -43,6 +76,8 @@ void ContextualSearchPromoSourceAndroid::StartDataRequest( |
| SendResource(IDR_CONTEXTUAL_SEARCH_PROMO_CSS, callback); |
| } else if (path == kPromoJSPath) { |
| SendResource(IDR_CONTEXTUAL_SEARCH_PROMO_JS, callback); |
| + } else if (path == kPromoConfigPath) { |
| + SendConfigResource(callback); |
| } else if (path == kRobotoWoffPath) { |
| SendResource(IDR_ROBOTO_WOFF, callback); |
| } else if (path == kRobotoWoff2Path) { |
| @@ -84,6 +119,12 @@ void ContextualSearchPromoSourceAndroid::SendResource( |
| callback.Run(response.get()); |
| } |
| +void ContextualSearchPromoSourceAndroid::SendConfigResource( |
| + const content::URLDataSource::GotDataCallback& callback) { |
| + std::string response = GetConfigData(); |
| + callback.Run(base::RefCountedString::TakeString(&response)); |
| +} |
| + |
| void ContextualSearchPromoSourceAndroid::SendHtmlWithStrings( |
| const content::URLDataSource::GotDataCallback& callback) { |
| base::DictionaryValue strings_data; |