Chromium Code Reviews| 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/app_sync_data.h" | 5 #include "chrome/browser/extensions/app_sync_data.h" |
| 6 | 6 |
| 7 #include "extensions/common/extension.h" | 7 #include "extensions/common/extension.h" |
| 8 #include "sync/api/sync_data.h" | 8 #include "sync/api/sync_data.h" |
| 9 #include "sync/protocol/app_specifics.pb.h" | 9 #include "sync/protocol/app_specifics.pb.h" |
| 10 #include "sync/protocol/sync.pb.h" | 10 #include "sync/protocol/sync.pb.h" |
| 11 | 11 |
| 12 namespace extensions { | 12 namespace extensions { |
| 13 | 13 |
| 14 AppSyncData::AppSyncData() {} | 14 AppSyncData::AppSyncData() {} |
| 15 | 15 |
| 16 AppSyncData::AppSyncData(const syncer::SyncData& sync_data) { | 16 AppSyncData::AppSyncData(const syncer::SyncData& sync_data) { |
| 17 PopulateFromSyncData(sync_data); | 17 PopulateFromSyncData(sync_data); |
| 18 } | 18 } |
| 19 | 19 |
| 20 AppSyncData::AppSyncData(const syncer::SyncChange& sync_change) { | 20 AppSyncData::AppSyncData(const syncer::SyncChange& sync_change) { |
| 21 PopulateFromSyncData(sync_change.sync_data()); | 21 PopulateFromSyncData(sync_change.sync_data()); |
| 22 extension_sync_data_.set_uninstalled( | 22 extension_sync_data_.set_uninstalled( |
| 23 sync_change.change_type() == syncer::SyncChange::ACTION_DELETE); | 23 sync_change.change_type() == syncer::SyncChange::ACTION_DELETE); |
| 24 } | 24 } |
| 25 | 25 |
| 26 AppSyncData::AppSyncData(const Extension& extension, | 26 AppSyncData::AppSyncData(const Extension& extension, |
| 27 bool enabled, | 27 bool enabled, |
| 28 bool incognito_enabled, | 28 bool incognito_enabled, |
| 29 const syncer::StringOrdinal& app_launch_ordinal, | 29 const syncer::StringOrdinal& app_launch_ordinal, |
| 30 const syncer::StringOrdinal& page_ordinal) | 30 const syncer::StringOrdinal& page_ordinal, |
| 31 extensions::LaunchType launch_type) | |
| 31 : extension_sync_data_(extension, enabled, incognito_enabled), | 32 : extension_sync_data_(extension, enabled, incognito_enabled), |
| 32 app_launch_ordinal_(app_launch_ordinal), | 33 app_launch_ordinal_(app_launch_ordinal), |
| 33 page_ordinal_(page_ordinal) { | 34 page_ordinal_(page_ordinal), |
| 35 launch_type_(launch_type) { | |
| 34 } | 36 } |
| 35 | 37 |
| 36 AppSyncData::~AppSyncData() {} | 38 AppSyncData::~AppSyncData() {} |
| 37 | 39 |
| 38 syncer::SyncData AppSyncData::GetSyncData() const { | 40 syncer::SyncData AppSyncData::GetSyncData() const { |
| 39 sync_pb::EntitySpecifics specifics; | 41 sync_pb::EntitySpecifics specifics; |
| 40 PopulateAppSpecifics(specifics.mutable_app()); | 42 PopulateAppSpecifics(specifics.mutable_app()); |
| 41 | 43 |
| 42 return syncer::SyncData::CreateLocalData(extension_sync_data_.id(), | 44 return syncer::SyncData::CreateLocalData(extension_sync_data_.id(), |
| 43 extension_sync_data_.name(), | 45 extension_sync_data_.name(), |
| 44 specifics); | 46 specifics); |
| 45 } | 47 } |
| 46 | 48 |
| 47 syncer::SyncChange AppSyncData::GetSyncChange( | 49 syncer::SyncChange AppSyncData::GetSyncChange( |
| 48 syncer::SyncChange::SyncChangeType change_type) const { | 50 syncer::SyncChange::SyncChangeType change_type) const { |
| 49 return syncer::SyncChange(FROM_HERE, change_type, GetSyncData()); | 51 return syncer::SyncChange(FROM_HERE, change_type, GetSyncData()); |
| 50 } | 52 } |
| 51 | 53 |
| 52 void AppSyncData::PopulateAppSpecifics(sync_pb::AppSpecifics* specifics) const { | 54 void AppSyncData::PopulateAppSpecifics(sync_pb::AppSpecifics* specifics) const { |
| 53 DCHECK(specifics); | 55 DCHECK(specifics); |
| 54 // Only sync the ordinal values if they are valid. | 56 // Only sync the ordinal values and launch type if they are valid. |
| 55 if (app_launch_ordinal_.IsValid()) | 57 if (app_launch_ordinal_.IsValid()) |
| 56 specifics->set_app_launch_ordinal(app_launch_ordinal_.ToInternalValue()); | 58 specifics->set_app_launch_ordinal(app_launch_ordinal_.ToInternalValue()); |
| 57 if (page_ordinal_.IsValid()) | 59 if (page_ordinal_.IsValid()) |
| 58 specifics->set_page_ordinal(page_ordinal_.ToInternalValue()); | 60 specifics->set_page_ordinal(page_ordinal_.ToInternalValue()); |
| 59 | 61 |
| 62 if (launch_type_ >= extensions::LAUNCH_TYPE_FIRST && | |
| 63 launch_type_ < extensions::NUM_LAUNCH_TYPES) { | |
| 64 specifics->set_launch_type(launch_type_); | |
| 65 } | |
| 66 | |
| 60 extension_sync_data_.PopulateExtensionSpecifics( | 67 extension_sync_data_.PopulateExtensionSpecifics( |
| 61 specifics->mutable_extension()); | 68 specifics->mutable_extension()); |
| 62 } | 69 } |
| 63 | 70 |
| 64 void AppSyncData::PopulateFromAppSpecifics( | 71 void AppSyncData::PopulateFromAppSpecifics( |
| 65 const sync_pb::AppSpecifics& specifics) { | 72 const sync_pb::AppSpecifics& specifics) { |
| 66 extension_sync_data_.PopulateFromExtensionSpecifics(specifics.extension()); | 73 extension_sync_data_.PopulateFromExtensionSpecifics(specifics.extension()); |
| 67 | 74 |
| 68 app_launch_ordinal_ = syncer::StringOrdinal(specifics.app_launch_ordinal()); | 75 app_launch_ordinal_ = syncer::StringOrdinal(specifics.app_launch_ordinal()); |
| 69 page_ordinal_ = syncer::StringOrdinal(specifics.page_ordinal()); | 76 page_ordinal_ = syncer::StringOrdinal(specifics.page_ordinal()); |
| 77 | |
| 78 launch_type_ = specifics.has_launch_type() | |
|
Nicolas Zea
2013/12/18 21:14:04
It might be worth considering what might happen if
calamity
2013/12/19 06:27:52
Hmm yeah. We also wouldn't want to write an invali
Nicolas Zea
2013/12/19 19:57:00
See my other comment. If we're introducing a misma
| |
| 79 ? static_cast<extensions::LaunchType>(specifics.launch_type()) | |
| 80 : LAUNCH_TYPE_INVALID; | |
| 70 } | 81 } |
| 71 | 82 |
| 72 void AppSyncData::PopulateFromSyncData(const syncer::SyncData& sync_data) { | 83 void AppSyncData::PopulateFromSyncData(const syncer::SyncData& sync_data) { |
| 73 PopulateFromAppSpecifics(sync_data.GetSpecifics().app()); | 84 PopulateFromAppSpecifics(sync_data.GetSpecifics().app()); |
| 74 } | 85 } |
| 75 | 86 |
| 76 } // namespace extensions | 87 } // namespace extensions |
| OLD | NEW |