[Extensions] Modify IsSyncable to use policy enforced update URL

This change gives ExtensionManagement control over update URL used when
updating extensions. Previously only first install was affected, all
later updates used update URL from the extension manifest. Now update
URL from the policy can be used if extension management said so.
This CL adds changes to IsSyncable method to use policy
enforced update URL.

Update URL from policy is handled in
https://chromium-review.googlesource.com/c/chromium/src/+/2593260.

Bug: b:175767504
Change-Id: I5aeb99061affbb47339a1b1bf385cea1603f3642
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2593103
Reviewed-by: Devlin <[email protected]>
Reviewed-by: David Roger <[email protected]>
Commit-Queue: Swapnil Gupta <[email protected]>
Cr-Commit-Position: refs/heads/master@{#843645}
diff --git a/chrome/browser/extensions/extension_util.cc b/chrome/browser/extensions/extension_util.cc
index b068eab..91d63910 100644
--- a/chrome/browser/extensions/extension_util.cc
+++ b/chrome/browser/extensions/extension_util.cc
@@ -36,6 +36,7 @@
 #include "extensions/browser/extension_util.h"
 #include "extensions/common/extension.h"
 #include "extensions/common/extension_icon_set.h"
+#include "extensions/common/extension_urls.h"
 #include "extensions/common/manifest.h"
 #include "extensions/common/manifest_handlers/app_isolation_info.h"
 #include "extensions/common/manifest_handlers/incognito_info.h"
@@ -203,6 +204,17 @@
 
 bool ShouldSync(const Extension* extension,
                 content::BrowserContext* context) {
+  ExtensionManagement* extension_management =
+      ExtensionManagementFactory::GetForBrowserContext(context);
+  // Update URL is overridden only for non webstore extensions and offstore
+  // extensions should not be synced.
+  if (extension_management->IsUpdateUrlOverridden(extension->id())) {
+    const GURL update_url =
+        extension_management->GetEffectiveUpdateURL(*extension);
+    DCHECK(!extension_urls::IsWebstoreUpdateUrl(update_url))
+        << "Update URL cannot be overridden to be the webstore URL!";
+    return false;
+  }
   return sync_helper::IsSyncable(extension) &&
          !ExtensionPrefs::Get(context)->DoNotSync(extension->id());
 }