| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/extensions/extension_sync_data.h" | 5 #include "chrome/browser/extensions/extension_sync_data.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "chrome/browser/extensions/app_sync_data.h" | 8 #include "chrome/browser/extensions/app_sync_data.h" |
| 9 #include "chrome/browser/extensions/extension_service.h" | 9 #include "chrome/browser/extensions/extension_service.h" |
| 10 #include "components/crx_file/id_util.h" | 10 #include "components/crx_file/id_util.h" |
| 11 #include "extensions/common/extension.h" | 11 #include "extensions/common/extension.h" |
| 12 #include "extensions/common/manifest_url_handlers.h" | 12 #include "extensions/common/manifest_url_handlers.h" |
| 13 #include "sync/api/sync_data.h" | 13 #include "sync/api/sync_data.h" |
| 14 #include "sync/protocol/extension_specifics.pb.h" | 14 #include "sync/protocol/extension_specifics.pb.h" |
| 15 #include "sync/protocol/sync.pb.h" | 15 #include "sync/protocol/sync.pb.h" |
| 16 | 16 |
| 17 namespace extensions { | 17 namespace extensions { |
| 18 | 18 |
| 19 ExtensionSyncData::ExtensionSyncData() | 19 ExtensionSyncData::ExtensionSyncData() |
| 20 : uninstalled_(false), | 20 : uninstalled_(false), |
| 21 enabled_(false), | 21 enabled_(false), |
| 22 incognito_enabled_(false), | 22 incognito_enabled_(false), |
| 23 remote_install_(false), | 23 remote_install_(false), |
| 24 all_urls_enabled_(PREF_UNSET), |
| 24 installed_by_custodian_(false) { | 25 installed_by_custodian_(false) { |
| 25 } | 26 } |
| 26 | 27 |
| 27 ExtensionSyncData::ExtensionSyncData(const syncer::SyncData& sync_data) | 28 ExtensionSyncData::ExtensionSyncData(const syncer::SyncData& sync_data) |
| 28 : uninstalled_(false), | 29 : uninstalled_(false), |
| 29 enabled_(false), | 30 enabled_(false), |
| 30 incognito_enabled_(false), | 31 incognito_enabled_(false), |
| 31 remote_install_(false), | 32 remote_install_(false), |
| 33 all_urls_enabled_(PREF_UNSET), |
| 32 installed_by_custodian_(false) { | 34 installed_by_custodian_(false) { |
| 33 PopulateFromSyncData(sync_data); | 35 PopulateFromSyncData(sync_data); |
| 34 } | 36 } |
| 35 | 37 |
| 36 ExtensionSyncData::ExtensionSyncData(const syncer::SyncChange& sync_change) | 38 ExtensionSyncData::ExtensionSyncData(const syncer::SyncChange& sync_change) |
| 37 : uninstalled_(sync_change.change_type() == | 39 : uninstalled_(sync_change.change_type() == |
| 38 syncer::SyncChange::ACTION_DELETE), | 40 syncer::SyncChange::ACTION_DELETE), |
| 39 enabled_(false), | 41 enabled_(false), |
| 40 incognito_enabled_(false), | 42 incognito_enabled_(false), |
| 41 remote_install_(false), | 43 remote_install_(false), |
| 44 all_urls_enabled_(PREF_UNSET), |
| 42 installed_by_custodian_(false) { | 45 installed_by_custodian_(false) { |
| 43 PopulateFromSyncData(sync_change.sync_data()); | 46 PopulateFromSyncData(sync_change.sync_data()); |
| 44 } | 47 } |
| 45 | 48 |
| 46 ExtensionSyncData::ExtensionSyncData(const Extension& extension, | 49 ExtensionSyncData::ExtensionSyncData(const Extension& extension, |
| 47 bool enabled, | 50 bool enabled, |
| 48 bool incognito_enabled, | 51 bool incognito_enabled, |
| 49 bool remote_install) | 52 bool remote_install, |
| 53 PrefValue all_urls_enabled) |
| 50 : id_(extension.id()), | 54 : id_(extension.id()), |
| 51 uninstalled_(false), | 55 uninstalled_(false), |
| 52 enabled_(enabled), | 56 enabled_(enabled), |
| 53 incognito_enabled_(incognito_enabled), | 57 incognito_enabled_(incognito_enabled), |
| 54 remote_install_(remote_install), | 58 remote_install_(remote_install), |
| 59 all_urls_enabled_(all_urls_enabled), |
| 55 installed_by_custodian_(extension.was_installed_by_custodian()), | 60 installed_by_custodian_(extension.was_installed_by_custodian()), |
| 56 version_(extension.from_bookmark() ? base::Version("0") | 61 version_(extension.from_bookmark() ? base::Version("0") |
| 57 : *extension.version()), | 62 : *extension.version()), |
| 58 update_url_(ManifestURL::GetUpdateURL(&extension)), | 63 update_url_(ManifestURL::GetUpdateURL(&extension)), |
| 59 name_(extension.non_localized_name()) { | 64 name_(extension.non_localized_name()) { |
| 60 } | 65 } |
| 61 | 66 |
| 62 ExtensionSyncData::~ExtensionSyncData() {} | 67 ExtensionSyncData::~ExtensionSyncData() {} |
| 63 | 68 |
| 64 syncer::SyncData ExtensionSyncData::GetSyncData() const { | 69 syncer::SyncData ExtensionSyncData::GetSyncData() const { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 75 | 80 |
| 76 void ExtensionSyncData::PopulateExtensionSpecifics( | 81 void ExtensionSyncData::PopulateExtensionSpecifics( |
| 77 sync_pb::ExtensionSpecifics* specifics) const { | 82 sync_pb::ExtensionSpecifics* specifics) const { |
| 78 DCHECK(crx_file::id_util::IdIsValid(id_)); | 83 DCHECK(crx_file::id_util::IdIsValid(id_)); |
| 79 specifics->set_id(id_); | 84 specifics->set_id(id_); |
| 80 specifics->set_update_url(update_url_.spec()); | 85 specifics->set_update_url(update_url_.spec()); |
| 81 specifics->set_version(version_.GetString()); | 86 specifics->set_version(version_.GetString()); |
| 82 specifics->set_enabled(enabled_); | 87 specifics->set_enabled(enabled_); |
| 83 specifics->set_incognito_enabled(incognito_enabled_); | 88 specifics->set_incognito_enabled(incognito_enabled_); |
| 84 specifics->set_remote_install(remote_install_); | 89 specifics->set_remote_install(remote_install_); |
| 90 if (all_urls_enabled_ != PREF_UNSET) |
| 91 specifics->set_all_urls_enabled(all_urls_enabled_ == PREF_TRUE); |
| 85 specifics->set_installed_by_custodian(installed_by_custodian_); | 92 specifics->set_installed_by_custodian(installed_by_custodian_); |
| 86 specifics->set_name(name_); | 93 specifics->set_name(name_); |
| 87 } | 94 } |
| 88 | 95 |
| 89 void ExtensionSyncData::PopulateFromExtensionSpecifics( | 96 void ExtensionSyncData::PopulateFromExtensionSpecifics( |
| 90 const sync_pb::ExtensionSpecifics& specifics) { | 97 const sync_pb::ExtensionSpecifics& specifics) { |
| 91 if (!crx_file::id_util::IdIsValid(specifics.id())) { | 98 if (!crx_file::id_util::IdIsValid(specifics.id())) { |
| 92 LOG(FATAL) << "Attempt to sync bad ExtensionSpecifics."; | 99 LOG(FATAL) << "Attempt to sync bad ExtensionSpecifics."; |
| 93 } | 100 } |
| 94 | 101 |
| 95 Version specifics_version(specifics.version()); | 102 Version specifics_version(specifics.version()); |
| 96 if (!specifics_version.IsValid()) | 103 if (!specifics_version.IsValid()) |
| 97 LOG(FATAL) << "Attempt to sync bad ExtensionSpecifics."; | 104 LOG(FATAL) << "Attempt to sync bad ExtensionSpecifics."; |
| 98 | 105 |
| 99 // The update URL must be either empty or valid. | 106 // The update URL must be either empty or valid. |
| 100 GURL specifics_update_url(specifics.update_url()); | 107 GURL specifics_update_url(specifics.update_url()); |
| 101 if (!specifics_update_url.is_empty() && !specifics_update_url.is_valid()) { | 108 if (!specifics_update_url.is_empty() && !specifics_update_url.is_valid()) { |
| 102 LOG(FATAL) << "Attempt to sync bad ExtensionSpecifics."; | 109 LOG(FATAL) << "Attempt to sync bad ExtensionSpecifics."; |
| 103 } | 110 } |
| 104 | 111 |
| 105 id_ = specifics.id(); | 112 id_ = specifics.id(); |
| 106 update_url_ = specifics_update_url; | 113 update_url_ = specifics_update_url; |
| 107 version_ = specifics_version; | 114 version_ = specifics_version; |
| 108 enabled_ = specifics.enabled(); | 115 enabled_ = specifics.enabled(); |
| 109 incognito_enabled_ = specifics.incognito_enabled(); | 116 incognito_enabled_ = specifics.incognito_enabled(); |
| 117 if (specifics.has_all_urls_enabled()) |
| 118 all_urls_enabled_ = specifics.all_urls_enabled() ? PREF_TRUE : PREF_FALSE; |
| 110 remote_install_ = specifics.remote_install(); | 119 remote_install_ = specifics.remote_install(); |
| 111 installed_by_custodian_ = specifics.installed_by_custodian(); | 120 installed_by_custodian_ = specifics.installed_by_custodian(); |
| 112 name_ = specifics.name(); | 121 name_ = specifics.name(); |
| 113 } | 122 } |
| 114 | 123 |
| 115 void ExtensionSyncData::set_uninstalled(bool uninstalled) { | 124 void ExtensionSyncData::set_uninstalled(bool uninstalled) { |
| 116 uninstalled_ = uninstalled; | 125 uninstalled_ = uninstalled; |
| 117 } | 126 } |
| 118 | 127 |
| 119 void ExtensionSyncData::PopulateFromSyncData( | 128 void ExtensionSyncData::PopulateFromSyncData( |
| 120 const syncer::SyncData& sync_data) { | 129 const syncer::SyncData& sync_data) { |
| 121 const sync_pb::EntitySpecifics& entity_specifics = sync_data.GetSpecifics(); | 130 const sync_pb::EntitySpecifics& entity_specifics = sync_data.GetSpecifics(); |
| 122 | 131 |
| 123 if (entity_specifics.has_extension()) { | 132 if (entity_specifics.has_extension()) { |
| 124 PopulateFromExtensionSpecifics(entity_specifics.extension()); | 133 PopulateFromExtensionSpecifics(entity_specifics.extension()); |
| 125 } else { | 134 } else { |
| 126 LOG(FATAL) << "Attempt to sync bad EntitySpecifics."; | 135 LOG(FATAL) << "Attempt to sync bad EntitySpecifics."; |
| 127 } | 136 } |
| 128 } | 137 } |
| 129 | 138 |
| 130 } // namespace extensions | 139 } // namespace extensions |
| OLD | NEW |