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
3 // found in the LICENSE file.
4 
5 #include "chrome/common/extensions/sync_helper.h"
6 
7 #include "base/logging.h"
8 #include "extensions/common/constants.h"
9 #include "extensions/common/extension.h"
10 #include "extensions/common/features/behavior_feature.h"
11 #include "extensions/common/features/feature.h"
12 #include "extensions/common/features/feature_provider.h"
13 #include "extensions/common/manifest.h"
14 #include "extensions/common/manifest_url_handlers.h"
15 
16 namespace extensions {
17 namespace sync_helper {
18 
IsSyncable(const Extension * extension)19 bool IsSyncable(const Extension* extension) {
20   const Feature* feature =
21       FeatureProvider::GetBehaviorFeature(behavior_feature::kDoNotSync);
22   if (feature && feature->IsAvailableToExtension(extension).is_available())
23     return false;
24 
25   // Default apps are not synced because otherwise they will pollute profiles
26   // that don't already have them. Specially, if a user doesn't have default
27   // apps, creates a new profile (which get default apps) and then enables sync
28   // for it, then their profile everywhere gets the default apps.
29   bool is_syncable = (extension->location() == Manifest::INTERNAL &&
30                       !extension->was_installed_by_default());
31   if (!is_syncable && !IsSyncableComponentExtension(extension)) {
32     // We have a non-standard location.
33     return false;
34   }
35 
36   // Disallow extensions with non-gallery auto-update URLs for now.
37   //
38   // TODO(akalin): Relax this restriction once we've put in UI to
39   // approve synced extensions.
40   if (!ManifestURL::GetUpdateURL(extension).is_empty() &&
41       !ManifestURL::UpdatesFromGallery(extension)) {
42     return false;
43   }
44 
45   switch (extension->GetType()) {
46     case Manifest::TYPE_EXTENSION:
47     case Manifest::TYPE_HOSTED_APP:
48     case Manifest::TYPE_LEGACY_PACKAGED_APP:
49     case Manifest::TYPE_PLATFORM_APP:
50     case Manifest::TYPE_THEME:
51       return true;
52 
53     case Manifest::TYPE_USER_SCRIPT:
54       // We only want to sync user scripts with gallery update URLs.
55       if (ManifestURL::UpdatesFromGallery(extension))
56         return true;
57       return false;
58 
59     case Manifest::TYPE_UNKNOWN:
60     case Manifest::TYPE_SHARED_MODULE:
61     case Manifest::TYPE_LOGIN_SCREEN_EXTENSION:
62       return false;
63 
64     case Manifest::NUM_LOAD_TYPES:
65       NOTREACHED();
66   }
67   NOTREACHED();
68   return false;
69 }
70 
IsSyncableComponentExtension(const Extension * extension)71 bool IsSyncableComponentExtension(const Extension* extension) {
72   if (!Manifest::IsComponentLocation(extension->location()))
73     return false;
74   return (extension->id() == extensions::kWebStoreAppId) ||
75          (extension->id() == extension_misc::kChromeAppId);
76 }
77 
78 }  // namespace sync_helper
79 }  // namespace extensions
80