Index: chrome/common/localized_error.cc |
diff --git a/chrome/common/localized_error.cc b/chrome/common/localized_error.cc |
index 0c4ad4361e590adf71d4784a78846863e490b287..ad1f0d77db5ac452640d2cf72f01d7aec2497053 100644 |
--- a/chrome/common/localized_error.cc |
+++ b/chrome/common/localized_error.cc |
@@ -7,6 +7,7 @@ |
#include "base/command_line.h" |
#include "base/i18n/rtl.h" |
#include "base/logging.h" |
+#include "base/metrics/field_trial.h" |
#include "base/strings/string16.h" |
#include "base/strings/string_number_conversions.h" |
#include "base/strings/string_util.h" |
@@ -56,6 +57,10 @@ static const char kAppWarningLearnMoreUrl[] = |
"chrome-extension://honijodknafkokifofgiaalefdiedpko/main.html" |
"?answer=1721911"; |
#endif // defined(OS_CHROMEOS) |
+static const char kCachedCopyButtonFieldTrial[] = |
+ "EnableGoogleCachedCopyTextExperiment"; |
+static const char kCachedCopyButtonExpTypeControl[] = "control"; |
+static const char kCachedCopyButtonExpTypeCopy[] = "copy"; |
enum NAV_SUGGESTIONS { |
SUGGEST_NONE = 0, |
@@ -518,6 +523,47 @@ const char* GetIconClassForError(const std::string& error_domain, |
const char LocalizedError::kHttpErrorDomain[] = "http"; |
+void LocalizedError::EnableGoogleCachedCopyButtonExperiment( |
sky
2015/06/02 16:18:06
Make position match that of header.
edwardjung
2015/06/03 13:40:36
Done.
|
+ base::ListValue* suggestions, |
+ base::DictionaryValue* error_strings) { |
+ std::string field_trial_exp_type_ = |
+ base::FieldTrialList::FindFullName(kCachedCopyButtonFieldTrial); |
+ |
+ // If the first suggestion is for a Google cache copy. Promote the |
+ // suggestion to a separate set of strings for displaying as a button. |
+ if (!suggestions->empty() && !field_trial_exp_type_.empty() && |
+ field_trial_exp_type_ != kCachedCopyButtonExpTypeControl) { |
+ base::DictionaryValue* suggestion; |
+ suggestions->GetDictionary(0, &suggestion); |
+ int type = -1; |
+ suggestion->GetInteger("type", &type); |
+ |
+ if (type == 0) { |
sky
2015/06/02 16:18:06
where does 0 come from? Please use a constant.
edwardjung
2015/06/03 13:40:36
Done.
|
+ base::string16 cache_url; |
+ suggestion->GetString("urlCorrection", &cache_url); |
+ int cache_tracking_id = -1; |
+ suggestion->GetInteger("trackingId", &cache_tracking_id); |
+ |
+ scoped_ptr<base::DictionaryValue> cache_button(new base::DictionaryValue); |
+ |
+ if (field_trial_exp_type_ == kCachedCopyButtonExpTypeCopy) { |
+ cache_button->SetString( |
+ "msg", |
+ l10n_util::GetStringUTF16(IDS_ERRORPAGES_BUTTON_SHOW_CACHED_COPY)); |
+ } else { |
+ // Default to "Show cached page" button label. |
+ cache_button->SetString( |
+ "msg", |
+ l10n_util::GetStringUTF16(IDS_ERRORPAGES_BUTTON_SHOW_CACHED_PAGE)); |
+ } |
+ cache_button->SetString("cacheUrl", cache_url); |
sky
2015/06/02 16:18:06
You're not checking the url is valid. Should you?
edwardjung
2015/06/03 13:40:36
This link is returned from the link doctor so I wo
|
+ cache_button->SetInteger("trackingId", cache_tracking_id); |
+ error_strings->Set("cacheButton", cache_button.release()); |
+ suggestions->Remove(0, NULL); |
sky
2015/06/02 16:18:06
Why do you need to remove?
sky
2015/06/02 16:18:06
nullptr
edwardjung
2015/06/03 13:40:36
As the suggestion text would be displayed in the d
edwardjung
2015/06/03 13:40:36
Done.
|
+ } |
+ } |
+} |
+ |
void LocalizedError::GetStrings(int error_code, |
const std::string& error_domain, |
const GURL& failed_url, |
@@ -671,6 +717,7 @@ void LocalizedError::GetStrings(int error_code, |
} else { |
suggestions = params->override_suggestions.release(); |
use_default_suggestions = false; |
+ EnableGoogleCachedCopyButtonExperiment(suggestions, error_strings); |
} |
error_strings->Set("suggestions", suggestions); |