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

Side by Side 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: Use base::StringPiece; fix tests. 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/common/favicon/large_icon_url_parser.h"
6
7 #include "base/logging.h"
8 #include "base/strings/string_number_conversions.h"
9 #include "base/strings/string_split.h"
10 #include "base/strings/string_util.h"
11 #include "third_party/skia/include/utils/SkParse.h"
12 #include "ui/gfx/favicon_size.h"
13
14 namespace chrome {
15
16 LargeIconUrlParser::LargeIconUrlParser() : size_in_pixels_(48) {
17 }
18
19 LargeIconUrlParser::~LargeIconUrlParser() {
20 }
21
22 bool LargeIconUrlParser::Parse(base::StringPiece path) {
23 if (path.empty())
24 return false;
25
26 size_t slash = path.find("/", 0); // |path| does not start with '/'.
27 if (slash == base::StringPiece::npos)
28 return false;
29 base::StringPiece size_str = path.substr(0, slash);
30 // Disallow empty, non-numeric, or negative sizes.
31 if (size_str.empty() ||
32 !base::StringToInt(size_str, &size_in_pixels_) ||
33 size_in_pixels_ <= 0)
34 return false;
35
36 // Need to store the index of the URL field, so Instant Extended can translate
37 // large icon URLs using advanced parameters.
38 // Example:
39 // "chrome-search://large-icon/48/<renderer-id>/<most-visited-id>"
40 // would be translated to:
41 // "chrome-search://large-icon/48/<most-visited-item-with-given-id>".
42 path_index_ = slash + 1;
43 url_string_ = path.substr(path_index_).as_string();
44 return true;
45 }
46
47 } // namespace chrome
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698