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

Unified Diff: chrome/common/favicon/large_icon_url_parser.cc

Issue 1014853004: [Icons NTP] Add LargeIconUrlParser. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Update comment for test case. Created 5 years, 9 months 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/common/favicon/large_icon_url_parser.cc
diff --git a/chrome/common/favicon/large_icon_url_parser.cc b/chrome/common/favicon/large_icon_url_parser.cc
new file mode 100644
index 0000000000000000000000000000000000000000..67bae01dcaff1d512e62531784c8a5ead1fc7ac7
--- /dev/null
+++ b/chrome/common/favicon/large_icon_url_parser.cc
@@ -0,0 +1,43 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/common/favicon/large_icon_url_parser.h"
+
+#include "base/logging.h"
+#include "base/strings/string_number_conversions.h"
+#include "base/strings/string_split.h"
+#include "base/strings/string_util.h"
+#include "third_party/skia/include/utils/SkParse.h"
+#include "ui/gfx/favicon_size.h"
+
+LargeIconUrlParser::LargeIconUrlParser() : size_in_pixels_(48) {
+}
+
+LargeIconUrlParser::~LargeIconUrlParser() {
+}
+
+bool LargeIconUrlParser::Parse(base::StringPiece path) {
+ if (path.empty())
+ return false;
+
+ size_t slash = path.find("/", 0); // |path| does not start with '/'.
+ if (slash == base::StringPiece::npos)
+ return false;
+ base::StringPiece size_str = path.substr(0, slash);
+ // Disallow empty, non-numeric, or non-positive sizes.
+ if (size_str.empty() ||
+ !base::StringToInt(size_str, &size_in_pixels_) ||
+ size_in_pixels_ <= 0)
+ return false;
+
+ // Need to store the index of the URL field, so Instant Extended can translate
+ // large icon URLs using advanced parameters.
+ // Example:
+ // "chrome-search://large-icon/48/<renderer-id>/<most-visited-id>"
+ // would be translated to:
+ // "chrome-search://large-icon/48/<most-visited-item-with-given-id>".
+ path_index_ = slash + 1;
+ url_string_ = path.substr(path_index_).as_string();
+ return true;
+}
« no previous file with comments | « chrome/common/favicon/large_icon_url_parser.h ('k') | chrome/common/favicon/large_icon_url_parser_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698