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

Side by Side Diff: chrome/common/favicon/fallback_icon_url_parser.cc

Issue 1010783002: [Icons NTP] Working prototype to fetch, store, and display big icons. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Tweaks and unit test fix. 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
1 // Copyright 2015 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/common/favicon/fallback_icon_url_parser.h" 5 #include "chrome/common/favicon/fallback_icon_url_parser.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/macros.h" 10 #include "base/macros.h"
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 if (path.empty()) 47 if (path.empty())
48 return false; 48 return false;
49 49
50 size_t slash = path.find("/", 0); 50 size_t slash = path.find("/", 0);
51 if (slash == std::string::npos) 51 if (slash == std::string::npos)
52 return false; 52 return false;
53 std::string spec_str = path.substr(0, slash); 53 std::string spec_str = path.substr(0, slash);
54 if (!ParseSpecs(spec_str, &size_in_pixels_, &style_)) 54 if (!ParseSpecs(spec_str, &size_in_pixels_, &style_))
55 return false; // Parse failed. 55 return false; // Parse failed.
56 56
57 // Extract URL, which may be empty (if first slash appears at the end). 57 // Need to store the index of the URL field, so Instant Extended can translate
58 std::string url_str = path.substr(slash + 1); 58 // fallback icon URLs using advanced parameters.
59 url_ = GURL(url_str); 59 // Example:
60 return url_str.empty() || url_.is_valid(); // Allow empty URL. 60 // "chrome-search://fallback-icon/48/<renderer-id>/<most-visited-id>"
61 // would be translated to:
62 // "chrome-search://fallback-icon/48/<most-visited-item-with-given-id>".
63 path_index_ = slash + 1;
64 url_string_ = path.substr(path_index_);
65 return true;
61 } 66 }
62 67
63 // static 68 // static
64 bool ParsedFallbackIconPath::ParseSpecs( 69 bool ParsedFallbackIconPath::ParseSpecs(
65 const std::string& specs_str, 70 const std::string& specs_str,
66 int *size, 71 int *size,
67 favicon_base::FallbackIconStyle* style) { 72 favicon_base::FallbackIconStyle* style) {
68 DCHECK(size); 73 DCHECK(size);
69 DCHECK(style); 74 DCHECK(style);
70 75
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 SkColor temp_color = SK_ColorWHITE; 127 SkColor temp_color = SK_ColorWHITE;
123 const char* end = SkParse::FindColor(color_str.c_str(), &temp_color); 128 const char* end = SkParse::FindColor(color_str.c_str(), &temp_color);
124 if (end && !*end) { // Successful if call succeeds and string is consumed. 129 if (end && !*end) { // Successful if call succeeds and string is consumed.
125 *color = temp_color; 130 *color = temp_color;
126 return true; 131 return true;
127 } 132 }
128 return false; 133 return false;
129 } 134 }
130 135
131 } // namespace chrome 136 } // namespace chrome
OLDNEW
« no previous file with comments | « chrome/common/favicon/fallback_icon_url_parser.h ('k') | chrome/common/favicon/fallback_icon_url_parser_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698