| 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 "chrome/common/extensions/extension.h" | 10 #include "chrome/common/extensions/extension.h" |
| 11 #include "sync/api/sync_data.h" | 11 #include "sync/api/sync_data.h" |
| 12 #include "sync/protocol/extension_specifics.pb.h" | 12 #include "sync/protocol/extension_specifics.pb.h" |
| 13 #include "sync/protocol/sync.pb.h" | 13 #include "sync/protocol/sync.pb.h" |
| 14 | 14 |
| 15 namespace extensions { | 15 namespace extensions { |
| 16 | 16 |
| 17 ExtensionSyncData::ExtensionSyncData() | 17 ExtensionSyncData::ExtensionSyncData() |
| 18 : uninstalled_(false), | 18 : uninstalled_(false), |
| 19 enabled_(false), | 19 enabled_(false), |
| 20 incognito_enabled_(false) { | 20 incognito_enabled_(false) { |
| 21 } | 21 } |
| 22 | 22 |
| 23 ExtensionSyncData::ExtensionSyncData(const SyncData& sync_data) | 23 ExtensionSyncData::ExtensionSyncData(const csync::SyncData& sync_data) |
| 24 : uninstalled_(false), | 24 : uninstalled_(false), |
| 25 enabled_(false), | 25 enabled_(false), |
| 26 incognito_enabled_(false) { | 26 incognito_enabled_(false) { |
| 27 PopulateFromSyncData(sync_data); | 27 PopulateFromSyncData(sync_data); |
| 28 } | 28 } |
| 29 | 29 |
| 30 ExtensionSyncData::ExtensionSyncData(const SyncChange& sync_change) | 30 ExtensionSyncData::ExtensionSyncData(const csync::SyncChange& sync_change) |
| 31 : uninstalled_(sync_change.change_type() == SyncChange::ACTION_DELETE), | 31 : uninstalled_( |
| 32 sync_change.change_type() == csync::SyncChange::ACTION_DELETE), |
| 32 enabled_(false), | 33 enabled_(false), |
| 33 incognito_enabled_(false) { | 34 incognito_enabled_(false) { |
| 34 PopulateFromSyncData(sync_change.sync_data()); | 35 PopulateFromSyncData(sync_change.sync_data()); |
| 35 } | 36 } |
| 36 | 37 |
| 37 ExtensionSyncData::ExtensionSyncData(const Extension& extension, | 38 ExtensionSyncData::ExtensionSyncData(const Extension& extension, |
| 38 bool enabled, | 39 bool enabled, |
| 39 bool incognito_enabled) | 40 bool incognito_enabled) |
| 40 : id_(extension.id()), | 41 : id_(extension.id()), |
| 41 uninstalled_(false), | 42 uninstalled_(false), |
| 42 enabled_(enabled), | 43 enabled_(enabled), |
| 43 incognito_enabled_(incognito_enabled), | 44 incognito_enabled_(incognito_enabled), |
| 44 version_(*extension.version()), | 45 version_(*extension.version()), |
| 45 update_url_(extension.update_url()), | 46 update_url_(extension.update_url()), |
| 46 name_(extension.non_localized_name()) { | 47 name_(extension.non_localized_name()) { |
| 47 } | 48 } |
| 48 | 49 |
| 49 ExtensionSyncData::~ExtensionSyncData() {} | 50 ExtensionSyncData::~ExtensionSyncData() {} |
| 50 | 51 |
| 51 SyncData ExtensionSyncData::GetSyncData() const { | 52 csync::SyncData ExtensionSyncData::GetSyncData() const { |
| 52 sync_pb::EntitySpecifics specifics; | 53 sync_pb::EntitySpecifics specifics; |
| 53 PopulateExtensionSpecifics(specifics.mutable_extension()); | 54 PopulateExtensionSpecifics(specifics.mutable_extension()); |
| 54 | 55 |
| 55 return SyncData::CreateLocalData(id_, name_, specifics); | 56 return csync::SyncData::CreateLocalData(id_, name_, specifics); |
| 56 } | 57 } |
| 57 | 58 |
| 58 SyncChange ExtensionSyncData::GetSyncChange( | 59 csync::SyncChange ExtensionSyncData::GetSyncChange( |
| 59 SyncChange::SyncChangeType change_type) const { | 60 csync::SyncChange::SyncChangeType change_type) const { |
| 60 return SyncChange(change_type, GetSyncData()); | 61 return csync::SyncChange(change_type, GetSyncData()); |
| 61 } | 62 } |
| 62 | 63 |
| 63 void ExtensionSyncData::PopulateExtensionSpecifics( | 64 void ExtensionSyncData::PopulateExtensionSpecifics( |
| 64 sync_pb::ExtensionSpecifics* specifics) const { | 65 sync_pb::ExtensionSpecifics* specifics) const { |
| 65 DCHECK(Extension::IdIsValid(id_)); | 66 DCHECK(Extension::IdIsValid(id_)); |
| 66 specifics->set_id(id_); | 67 specifics->set_id(id_); |
| 67 specifics->set_update_url(update_url_.spec()); | 68 specifics->set_update_url(update_url_.spec()); |
| 68 specifics->set_version(version_.GetString()); | 69 specifics->set_version(version_.GetString()); |
| 69 specifics->set_enabled(enabled_); | 70 specifics->set_enabled(enabled_); |
| 70 specifics->set_incognito_enabled(incognito_enabled_); | 71 specifics->set_incognito_enabled(incognito_enabled_); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 92 version_ = specifics_version; | 93 version_ = specifics_version; |
| 93 enabled_ = specifics.enabled(); | 94 enabled_ = specifics.enabled(); |
| 94 incognito_enabled_ = specifics.incognito_enabled(); | 95 incognito_enabled_ = specifics.incognito_enabled(); |
| 95 name_ = specifics.name(); | 96 name_ = specifics.name(); |
| 96 } | 97 } |
| 97 | 98 |
| 98 void ExtensionSyncData::set_uninstalled(bool uninstalled) { | 99 void ExtensionSyncData::set_uninstalled(bool uninstalled) { |
| 99 uninstalled_ = uninstalled; | 100 uninstalled_ = uninstalled; |
| 100 } | 101 } |
| 101 | 102 |
| 102 void ExtensionSyncData::PopulateFromSyncData(const SyncData& sync_data) { | 103 void ExtensionSyncData::PopulateFromSyncData(const csync::SyncData& sync_data) { |
| 103 const sync_pb::EntitySpecifics& entity_specifics = sync_data.GetSpecifics(); | 104 const sync_pb::EntitySpecifics& entity_specifics = sync_data.GetSpecifics(); |
| 104 | 105 |
| 105 if (entity_specifics.has_extension()) { | 106 if (entity_specifics.has_extension()) { |
| 106 PopulateFromExtensionSpecifics(entity_specifics.extension()); | 107 PopulateFromExtensionSpecifics(entity_specifics.extension()); |
| 107 } else { | 108 } else { |
| 108 LOG(FATAL) << "Attempt to sync bad EntitySpecifics."; | 109 LOG(FATAL) << "Attempt to sync bad EntitySpecifics."; |
| 109 } | 110 } |
| 110 } | 111 } |
| 111 | 112 |
| 112 } // namespace extensions | 113 } // namespace extensions |
| OLD | NEW |