Browse Source

refactor: follow upstream's suggestions on when to use EmptyGURL() (#45498)

- Prefer GURL() when we want to return a non-reference empty URL.

- In ServiceWorkerMain::GetStorageKey(), use a reference instead
  of instantiating a new temporary GURL.

From url/gurl.h:

> // Returns a reference to a singleton empty GURL. This object is for
> // callers who return references but don't have anything to return in
> // some cases. If you just want an empty URL for normal use, prefer
> // GURL().
Charles Kerr 2 months ago
parent
commit
d7c6fb8250

+ 2 - 2
shell/browser/api/electron_api_service_worker_main.cc

@@ -192,7 +192,7 @@ bool ServiceWorkerMain::IsDestroyed() const {
 }
 
 const blink::StorageKey ServiceWorkerMain::GetStorageKey() {
-  GURL scope = version_info_ ? version_info()->scope : GURL::EmptyGURL();
+  const GURL& scope = version_info_ ? version_info()->scope : GURL::EmptyGURL();
   return blink::StorageKey::CreateFirstParty(url::Origin::Create(scope));
 }
 
@@ -279,7 +279,7 @@ int64_t ServiceWorkerMain::VersionID() const {
 
 GURL ServiceWorkerMain::ScopeURL() const {
   if (version_destroyed_)
-    return GURL::EmptyGURL();
+    return {};
   return version_info()->scope;
 }
 

+ 1 - 1
shell/browser/api/electron_api_web_frame_main.cc

@@ -375,7 +375,7 @@ int WebFrameMain::RoutingID() const {
 
 GURL WebFrameMain::URL() const {
   if (!CheckRenderFrame())
-    return GURL::EmptyGURL();
+    return {};
   return render_frame_->GetLastCommittedURL();
 }
 

+ 1 - 1
shell/browser/extensions/api/management/electron_management_api_delegate.cc

@@ -214,7 +214,7 @@ GURL ElectronManagementAPIDelegate::GetEffectiveUpdateURL(
     const extensions::Extension& extension,
     content::BrowserContext* context) const {
   // TODO(codebytere): we do not currently support ExtensionManagement.
-  return GURL::EmptyGURL();
+  return {};
 }
 
 void ElectronManagementAPIDelegate::ShowMv2DeprecationReEnableDialog(