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

Side by Side Diff: chrome/common/extensions/chrome_extensions_client.cc

Issue 2506713002: Avoid parsing the webstore base url so much. (Closed)
Patch Set: don't assume cmd line urls canonical 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 unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/extensions/chrome_extensions_client.h" 5 #include "chrome/common/extensions/chrome_extensions_client.h"
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/files/file_path.h" 10 #include "base/files/file_path.h"
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after
262 // return GetCurrentChannel() > version_info::Channel::DEV; 262 // return GetCurrentChannel() > version_info::Channel::DEV;
263 return true; 263 return true;
264 } 264 }
265 265
266 void ChromeExtensionsClient::RecordDidSuppressFatalError() { 266 void ChromeExtensionsClient::RecordDidSuppressFatalError() {
267 UMA_HISTOGRAM_ENUMERATION("Extensions.DidSuppressJavaScriptException", 267 UMA_HISTOGRAM_ENUMERATION("Extensions.DidSuppressJavaScriptException",
268 GetChromeChannelForHistogram(GetCurrentChannel()), 268 GetChromeChannelForHistogram(GetCurrentChannel()),
269 NUM_CHANNELS_FOR_HISTOGRAM); 269 NUM_CHANNELS_FOR_HISTOGRAM);
270 } 270 }
271 271
272 std::string ChromeExtensionsClient::GetWebstoreBaseURL() const { 272 const GURL& ChromeExtensionsClient::GetWebstoreBaseURL() const {
273 std::string gallery_prefix = extension_urls::kChromeWebstoreBaseURL; 273 // Browser tests like to alter the command line at runtime with new update
274 if (base::CommandLine::ForCurrentProcess()->HasSwitch( 274 // URLs. Just update the cached value of the base url (to avoid reparsing
275 switches::kAppsGalleryURL)) 275 // it) if the value has changed.
276 gallery_prefix = 276 base::CommandLine* cmdline = base::CommandLine::ForCurrentProcess();
277 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( 277 if (cmdline->HasSwitch(switches::kAppsGalleryURL)) {
278 switches::kAppsGalleryURL); 278 std::string url = cmdline->GetSwitchValueASCII(switches::kAppsGalleryURL);
279 if (base::EndsWith(gallery_prefix, "/", base::CompareCase::SENSITIVE)) 279 if (webstore_base_url_.possibly_invalid_spec() != url)
280 gallery_prefix = gallery_prefix.substr(0, gallery_prefix.length() - 1); 280 webstore_base_url_ = GURL(url);
281 return gallery_prefix; 281 } else if (webstore_base_url_.is_empty()) {
Devlin 2016/11/16 19:11:52 Is the savings from lazily populating webstore_bas
Charlie Harrison 2016/11/16 21:45:19 That's a better solution. I don't think lazy initi
282 webstore_base_url_ = GURL(extension_urls::kChromeWebstoreBaseURL);
283 }
284 return webstore_base_url_;
282 } 285 }
283 286
284 const GURL& ChromeExtensionsClient::GetWebstoreUpdateURL() const { 287 const GURL& ChromeExtensionsClient::GetWebstoreUpdateURL() const {
285 // Browser tests like to alter the command line at runtime with new update 288 // Browser tests like to alter the command line at runtime with new update
286 // URLs. Just update the cached value of the update url (to avoid reparsing 289 // URLs. Just update the cached value of the update url (to avoid reparsing
287 // it) if the value has changed. 290 // it) if the value has changed.
288 base::CommandLine* cmdline = base::CommandLine::ForCurrentProcess(); 291 base::CommandLine* cmdline = base::CommandLine::ForCurrentProcess();
289 if (cmdline->HasSwitch(switches::kAppsGalleryUpdateURL)) { 292 if (cmdline->HasSwitch(switches::kAppsGalleryUpdateURL)) {
290 std::string url = 293 std::string url =
291 cmdline->GetSwitchValueASCII(switches::kAppsGalleryUpdateURL); 294 cmdline->GetSwitchValueASCII(switches::kAppsGalleryUpdateURL);
292 if (webstore_update_url_ != url) 295 if (webstore_update_url_.possibly_invalid_spec() != url)
293 webstore_update_url_ = GURL(url); 296 webstore_update_url_ = GURL(url);
294 } else if (webstore_update_url_.is_empty()) { 297 } else if (webstore_update_url_.is_empty()) {
295 webstore_update_url_ = GURL(extension_urls::GetDefaultWebstoreUpdateUrl()); 298 webstore_update_url_ = GURL(extension_urls::GetDefaultWebstoreUpdateUrl());
296 } 299 }
297 return webstore_update_url_; 300 return webstore_update_url_;
298 } 301 }
299 302
300 bool ChromeExtensionsClient::IsBlacklistUpdateURL(const GURL& url) const { 303 bool ChromeExtensionsClient::IsBlacklistUpdateURL(const GURL& url) const {
301 // The extension blacklist URL is returned from the update service and 304 // The extension blacklist URL is returned from the update service and
302 // therefore not determined by Chromium. If the location of the blacklist file 305 // therefore not determined by Chromium. If the location of the blacklist file
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
342 const { 345 const {
343 return GetCurrentChannel() == version_info::Channel::UNKNOWN; 346 return GetCurrentChannel() == version_info::Channel::UNKNOWN;
344 } 347 }
345 348
346 // static 349 // static
347 ChromeExtensionsClient* ChromeExtensionsClient::GetInstance() { 350 ChromeExtensionsClient* ChromeExtensionsClient::GetInstance() {
348 return g_client.Pointer(); 351 return g_client.Pointer();
349 } 352 }
350 353
351 } // namespace extensions 354 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698