sync_helper.cc revision 868fa2fe829687343ffae624259930155e16dbd8
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 "chrome/common/extensions/api/plugins/plugins_handler.h" 9#include "chrome/common/extensions/extension.h" 10#include "chrome/common/extensions/extension_constants.h" 11#include "chrome/common/extensions/manifest.h" 12#include "chrome/common/extensions/manifest_url_handler.h" 13 14namespace extensions { 15namespace sync_helper { 16 17namespace { 18 19enum SyncType { 20 SYNC_TYPE_NONE = 0, 21 SYNC_TYPE_EXTENSION, 22 SYNC_TYPE_APP 23}; 24 25SyncType GetSyncType(const Extension* extension) { 26 if (!IsSyncable(extension)) { 27 // We have a non-standard location. 28 return SYNC_TYPE_NONE; 29 } 30 31 // Disallow extensions with non-gallery auto-update URLs for now. 32 // 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; 38 } 39 40 // Disallow extensions with native code plugins. 41 // 42 // TODO(akalin): Relax this restriction once we've put in UI to 43 // approve synced extensions. 44 if (PluginInfo::HasPlugins(extension)) 45 return SYNC_TYPE_NONE; 46 47 switch (extension->GetType()) { 48 case Manifest::TYPE_EXTENSION: 49 return SYNC_TYPE_EXTENSION; 50 51 case Manifest::TYPE_USER_SCRIPT: 52 // We only want to sync user scripts with gallery update URLs. 53 if (ManifestURL::UpdatesFromGallery(extension)) 54 return SYNC_TYPE_EXTENSION; 55 return SYNC_TYPE_NONE; 56 57 case Manifest::TYPE_HOSTED_APP: 58 case Manifest::TYPE_LEGACY_PACKAGED_APP: 59 case Manifest::TYPE_PLATFORM_APP: 60 return SYNC_TYPE_APP; 61 62 case Manifest::TYPE_UNKNOWN: 63 // Confusingly, themes are actually synced. 64 // TODO(yoz): Make this look less inconsistent. 65 case Manifest::TYPE_THEME: 66 case Manifest::TYPE_SHARED_MODULE: 67 return SYNC_TYPE_NONE; 68 } 69 NOTREACHED(); 70 return SYNC_TYPE_NONE; 71} 72 73} // namespace 74 75bool IsSyncable(const Extension* extension) { 76 // TODO(akalin): Figure out if we need to allow some other types. 77 78 // Default apps are not synced because otherwise they will pollute profiles 79 // that don't already have them. Specially, if a user doesn't have default 80 // apps, creates a new profile (which get default apps) and then enables sync 81 // for it, then their profile everywhere gets the default apps. 82 bool is_syncable = (extension->location() == Manifest::INTERNAL && 83 !extension->was_installed_by_default()); 84 // Sync the chrome web store to maintain its position on the new tab page. 85 is_syncable |= (extension->id() == extension_misc::kWebStoreAppId); 86 return is_syncable; 87} 88 89bool IsSyncableExtension(const Extension* extension) { 90 return GetSyncType(extension) == SYNC_TYPE_EXTENSION; 91} 92 93bool IsSyncableApp(const Extension* extension) { 94 return GetSyncType(extension) == SYNC_TYPE_APP; 95} 96 97} // namespace sync_helper 98} // namespace extensions 99