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

Side by Side Diff: chrome/browser/extensions/api/cookies/cookies_helpers.cc

Issue 2121513002: Replace string::find(prefix) == 0 pattern with base::StartsWith(). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix typos Created 4 years, 5 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 // Implements common functionality for the Chrome Extensions Cookies API. 5 // Implements common functionality for the Chrome Extensions Cookies API.
6 6
7 #include "chrome/browser/extensions/api/cookies/cookies_helpers.h" 7 #include "chrome/browser/extensions/api/cookies/cookies_helpers.h"
8 8
9 #include <stddef.h> 9 #include <stddef.h>
10 10
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 } else { 127 } else {
128 cookie_store->GetAllCookiesAsync(callback); 128 cookie_store->GetAllCookiesAsync(callback);
129 } 129 }
130 } 130 }
131 131
132 GURL GetURLFromCanonicalCookie(const net::CanonicalCookie& cookie) { 132 GURL GetURLFromCanonicalCookie(const net::CanonicalCookie& cookie) {
133 const std::string& domain_key = cookie.Domain(); 133 const std::string& domain_key = cookie.Domain();
134 const std::string scheme = 134 const std::string scheme =
135 cookie.IsSecure() ? url::kHttpsScheme : url::kHttpScheme; 135 cookie.IsSecure() ? url::kHttpsScheme : url::kHttpScheme;
136 const std::string host = 136 const std::string host =
137 domain_key.find('.') != 0 ? domain_key : domain_key.substr(1); 137 base::StartsWith(domain_key, ".", base::CompareCase::SENSITIVE)
138 ? domain_key.substr(1)
139 : domain_key;
138 return GURL(scheme + url::kStandardSchemeSeparator + host + "/"); 140 return GURL(scheme + url::kStandardSchemeSeparator + host + "/");
139 } 141 }
140 142
141 void AppendMatchingCookiesToVector(const net::CookieList& all_cookies, 143 void AppendMatchingCookiesToVector(const net::CookieList& all_cookies,
142 const GURL& url, 144 const GURL& url,
143 const GetAll::Params::Details* details, 145 const GetAll::Params::Details* details,
144 const Extension* extension, 146 const Extension* extension,
145 std::vector<Cookie>* match_vector) { 147 std::vector<Cookie>* match_vector) {
146 for (const net::CanonicalCookie& cookie : all_cookies) { 148 for (const net::CanonicalCookie& cookie : all_cookies) {
147 // Ignore any cookie whose domain doesn't match the extension's 149 // Ignore any cookie whose domain doesn't match the extension's
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 if (sub_domain == *details_->domain) 212 if (sub_domain == *details_->domain)
211 return true; 213 return true;
212 const size_t next_dot = sub_domain.find('.', 1); // Skip over leading dot. 214 const size_t next_dot = sub_domain.find('.', 1); // Skip over leading dot.
213 sub_domain.erase(0, next_dot); 215 sub_domain.erase(0, next_dot);
214 } 216 }
215 return false; 217 return false;
216 } 218 }
217 219
218 } // namespace cookies_helpers 220 } // namespace cookies_helpers
219 } // namespace extensions 221 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698