Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / common / extensions / sync_helper.cc
blob86457b88d004a49f1cf7a6eb70521eda92e41aa2
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.
5 #include "chrome/common/extensions/sync_helper.h"
7 #include "base/logging.h"
8 #include "chrome/common/extensions/api/plugins/plugins_handler.h"
9 #include "chrome/common/extensions/extension_constants.h"
10 #include "chrome/common/extensions/manifest_url_handler.h"
11 #include "extensions/common/extension.h"
12 #include "extensions/common/manifest.h"
14 namespace extensions {
15 namespace sync_helper {
17 namespace {
19 enum SyncType {
20 SYNC_TYPE_NONE = 0,
21 SYNC_TYPE_EXTENSION,
22 SYNC_TYPE_APP
25 SyncType GetSyncType(const Extension* extension) {
26 if (!IsSyncable(extension)) {
27 // We have a non-standard location.
28 return SYNC_TYPE_NONE;
31 // Disallow extensions with non-gallery auto-update URLs for now.
33 // TODO(akalin): Relax this restriction once we've put in UI to
34 // approve synced extensions.
35 if (!ManifestURL::GetUpdateURL(extension).is_empty() &&
36 !ManifestURL::UpdatesFromGallery(extension)) {
37 return SYNC_TYPE_NONE;
40 // Disallow extensions with native code plugins.
42 // TODO(akalin): Relax this restriction once we've put in UI to
43 // approve synced extensions.
44 if (PluginInfo::HasPlugins(extension) ||
45 extension->HasAPIPermission(APIPermission::kPlugin)) {
46 return SYNC_TYPE_NONE;
49 switch (extension->GetType()) {
50 case Manifest::TYPE_EXTENSION:
51 return SYNC_TYPE_EXTENSION;
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 SYNC_TYPE_EXTENSION;
57 return SYNC_TYPE_NONE;
59 case Manifest::TYPE_HOSTED_APP:
60 case Manifest::TYPE_LEGACY_PACKAGED_APP:
61 case Manifest::TYPE_PLATFORM_APP:
62 return SYNC_TYPE_APP;
64 case Manifest::TYPE_UNKNOWN:
65 // Confusingly, themes are actually synced.
66 // TODO(yoz): Make this look less inconsistent.
67 case Manifest::TYPE_THEME:
68 case Manifest::TYPE_SHARED_MODULE:
69 return SYNC_TYPE_NONE;
71 NOTREACHED();
72 return SYNC_TYPE_NONE;
75 } // namespace
77 bool IsSyncable(const Extension* extension) {
78 // TODO(akalin): Figure out if we need to allow some other types.
80 // Default apps are not synced because otherwise they will pollute profiles
81 // that don't already have them. Specially, if a user doesn't have default
82 // apps, creates a new profile (which get default apps) and then enables sync
83 // for it, then their profile everywhere gets the default apps.
84 bool is_syncable = (extension->location() == Manifest::INTERNAL &&
85 !extension->was_installed_by_default() &&
86 !extension->is_ephemeral());
87 // Sync the chrome web store to maintain its position on the new tab page.
88 is_syncable |= (extension->id() == extension_misc::kWebStoreAppId);
89 // Sync the chrome component app to maintain its position on the app list.
90 is_syncable |= (extension->id() == extension_misc::kChromeAppId);
91 return is_syncable;
94 bool IsSyncableExtension(const Extension* extension) {
95 return GetSyncType(extension) == SYNC_TYPE_EXTENSION;
98 bool IsSyncableApp(const Extension* extension) {
99 return GetSyncType(extension) == SYNC_TYPE_APP;
102 } // namespace sync_helper
103 } // namespace extensions