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

Unified Diff: chrome/browser/ui/passwords/manage_passwords_view_utils.cc

Issue 2526283002: Handle empty string in GetSavePasswordDialogTitleTextAndLinkRange gracefully (Closed)
Patch Set: EXPECT_THAT Created 4 years, 1 month 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
« no previous file with comments | « no previous file | chrome/browser/ui/passwords/manage_passwords_view_utils_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/ui/passwords/manage_passwords_view_utils.cc
diff --git a/chrome/browser/ui/passwords/manage_passwords_view_utils.cc b/chrome/browser/ui/passwords/manage_passwords_view_utils.cc
index 990fc87aa53b4d29246e7f33e8e3b6cb3c855d6f..b7b1387e1637306c084c6d58f5d39bc925ba9e0b 100644
--- a/chrome/browser/ui/passwords/manage_passwords_view_utils.cc
+++ b/chrome/browser/ui/passwords/manage_passwords_view_utils.cc
@@ -8,7 +8,6 @@
#include <algorithm>
-#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/sync/profile_sync_service_factory.h"
@@ -38,40 +37,6 @@ bool SameDomainOrHost(const GURL& gurl1, const GURL& gurl2) {
net::registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES);
}
-// TODO(crbug.com/658902): Remove |CheckExpectedPlaceholders| after
-// investigation, including the stringprintf.h #include.
-// Retrieves the string for |string_id| and checks that all expected
-// placeholders are present.
-void CheckExpectedPlaceholders(size_t number_of_placeholders, int string_id) {
- std::string format_string = l10n_util::GetStringUTF8(string_id);
- bool success = true;
-
- for (size_t placeholder = 1; placeholder <= number_of_placeholders;
- ++placeholder) {
- std::string placeholder_string = base::StringPrintf("$%zu", placeholder);
- if (format_string.find(placeholder_string) == std::string::npos) {
- success = false;
- LOG(ERROR) << "Expected placeholder " << placeholder_string
- << " missing in format_string '" << format_string << "'";
- }
- }
-
- CHECK(success);
-}
-
-// TODO(crbug.com/658902): Remove |CheckReplacementSize| after investigation.
-void CheckReplacementSize(const std::vector<base::string16>& replacements,
- size_t expected_size) {
- if (replacements.size() != expected_size) {
- LOG(ERROR) << "Expected " << expected_size
- << " replacements but only found " << replacements.size();
- // Separated logging from CHECK instead of using CHECK_EQ, because CHECKs in
- // release builds apparently discard logging (see "CHECK functions discard
- // their log" in base/logging.h).
- CHECK(false);
- }
-}
-
} // namespace
gfx::ImageSkia ScaleImageForAccountAvatar(gfx::ImageSkia skia_image) {
@@ -150,20 +115,14 @@ void GetSavePasswordDialogTitleTextAndLinkRange(
base::string16 title_link =
l10n_util::GetStringUTF16(IDS_PASSWORD_MANAGER_SMART_LOCK);
replacements.insert(replacements.begin(), title_link);
- // TODO(crbug.com/658902): Remove |number_of_placeholders| after
- // investigation.
- size_t number_of_placeholders = 1;
- if (title_id == IDS_UPDATE_PASSWORD_DIFFERENT_DOMAINS_TITLE ||
- title_id == IDS_SAVE_PASSWORD_DIFFERENT_DOMAINS_TITLE) {
- number_of_placeholders = 2;
- }
- CheckExpectedPlaceholders(number_of_placeholders, title_id);
- CheckReplacementSize(replacements, number_of_placeholders);
*title = l10n_util::GetStringFUTF16(title_id, replacements, &offsets);
- // TODO(crbug.com/658902): Remove this CHECK after investigation.
- CHECK(!offsets.empty());
- *title_link_range =
- gfx::Range(offsets[0], offsets[0] + title_link.length());
+ if (!offsets.empty()) {
+ // |offsets| can be empty when the localised string associated with
+ // |title_id| could not be found. While this situation is an error, it
+ // needs to be handled gracefully, see http://crbug.com/658902#c18.
+ *title_link_range =
+ gfx::Range(offsets[0], offsets[0] + title_link.length());
+ }
} else {
replacements.insert(
replacements.begin(),
« no previous file with comments | « no previous file | chrome/browser/ui/passwords/manage_passwords_view_utils_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698