| 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 "chrome/common/extensions/manifest_handlers/app_launch_info.h" |
| 7 #include "extensions/common/extension.h" | 8 #include "extensions/common/extension.h" |
| 8 #include "sync/api/sync_data.h" | 9 #include "sync/api/sync_data.h" |
| 9 #include "sync/protocol/app_specifics.pb.h" | 10 #include "sync/protocol/app_specifics.pb.h" |
| 10 #include "sync/protocol/sync.pb.h" | 11 #include "sync/protocol/sync.pb.h" |
| 11 | 12 |
| 12 namespace extensions { | 13 namespace extensions { |
| 13 | 14 |
| 14 AppSyncData::AppSyncData() {} | 15 AppSyncData::AppSyncData() {} |
| 15 | 16 |
| 16 AppSyncData::AppSyncData(const syncer::SyncData& sync_data) { | 17 AppSyncData::AppSyncData(const syncer::SyncData& sync_data) { |
| 17 PopulateFromSyncData(sync_data); | 18 PopulateFromSyncData(sync_data); |
| 18 } | 19 } |
| 19 | 20 |
| 20 AppSyncData::AppSyncData(const syncer::SyncChange& sync_change) { | 21 AppSyncData::AppSyncData(const syncer::SyncChange& sync_change) { |
| 21 PopulateFromSyncData(sync_change.sync_data()); | 22 PopulateFromSyncData(sync_change.sync_data()); |
| 22 extension_sync_data_.set_uninstalled( | 23 extension_sync_data_.set_uninstalled( |
| 23 sync_change.change_type() == syncer::SyncChange::ACTION_DELETE); | 24 sync_change.change_type() == syncer::SyncChange::ACTION_DELETE); |
| 24 } | 25 } |
| 25 | 26 |
| 26 AppSyncData::AppSyncData(const Extension& extension, | 27 AppSyncData::AppSyncData(const Extension& extension, |
| 27 bool enabled, | 28 bool enabled, |
| 28 bool incognito_enabled, | 29 bool incognito_enabled, |
| 29 const syncer::StringOrdinal& app_launch_ordinal, | 30 const syncer::StringOrdinal& app_launch_ordinal, |
| 30 const syncer::StringOrdinal& page_ordinal, | 31 const syncer::StringOrdinal& page_ordinal, |
| 31 extensions::LaunchType launch_type) | 32 extensions::LaunchType launch_type) |
| 32 : extension_sync_data_(extension, enabled, incognito_enabled), | 33 : extension_sync_data_(extension, enabled, incognito_enabled), |
| 33 app_launch_ordinal_(app_launch_ordinal), | 34 app_launch_ordinal_(app_launch_ordinal), |
| 34 page_ordinal_(page_ordinal), | 35 page_ordinal_(page_ordinal), |
| 35 launch_type_(launch_type) { | 36 launch_type_(launch_type) { |
| 37 if (extension.from_bookmark()) { |
| 38 bookmark_app_description_ = extension.description(); |
| 39 bookmark_app_url_ = AppLaunchInfo::GetLaunchWebURL(&extension).spec(); |
| 40 } |
| 36 } | 41 } |
| 37 | 42 |
| 38 AppSyncData::~AppSyncData() {} | 43 AppSyncData::~AppSyncData() {} |
| 39 | 44 |
| 40 syncer::SyncData AppSyncData::GetSyncData() const { | 45 syncer::SyncData AppSyncData::GetSyncData() const { |
| 41 sync_pb::EntitySpecifics specifics; | 46 sync_pb::EntitySpecifics specifics; |
| 42 PopulateAppSpecifics(specifics.mutable_app()); | 47 PopulateAppSpecifics(specifics.mutable_app()); |
| 43 | 48 |
| 44 return syncer::SyncData::CreateLocalData(extension_sync_data_.id(), | 49 return syncer::SyncData::CreateLocalData(extension_sync_data_.id(), |
| 45 extension_sync_data_.name(), | 50 extension_sync_data_.name(), |
| (...skipping 16 matching lines...) Expand all Loading... |
| 62 sync_pb::AppSpecifics::LaunchType sync_launch_type = | 67 sync_pb::AppSpecifics::LaunchType sync_launch_type = |
| 63 static_cast<sync_pb::AppSpecifics::LaunchType>(launch_type_); | 68 static_cast<sync_pb::AppSpecifics::LaunchType>(launch_type_); |
| 64 | 69 |
| 65 // The corresponding validation of this value during processing of an | 70 // The corresponding validation of this value during processing of an |
| 66 // AppSyncData is in ExtensionSyncService::ProcessAppSyncData. | 71 // AppSyncData is in ExtensionSyncService::ProcessAppSyncData. |
| 67 if (launch_type_ >= LAUNCH_TYPE_FIRST && launch_type_ < NUM_LAUNCH_TYPES && | 72 if (launch_type_ >= LAUNCH_TYPE_FIRST && launch_type_ < NUM_LAUNCH_TYPES && |
| 68 sync_pb::AppSpecifics_LaunchType_IsValid(sync_launch_type)) { | 73 sync_pb::AppSpecifics_LaunchType_IsValid(sync_launch_type)) { |
| 69 specifics->set_launch_type(sync_launch_type); | 74 specifics->set_launch_type(sync_launch_type); |
| 70 } | 75 } |
| 71 | 76 |
| 77 if (!bookmark_app_url_.empty()) |
| 78 specifics->set_bookmark_app_url(bookmark_app_url_); |
| 79 |
| 80 if (!bookmark_app_description_.empty()) |
| 81 specifics->set_bookmark_app_description(bookmark_app_description_); |
| 82 |
| 72 extension_sync_data_.PopulateExtensionSpecifics( | 83 extension_sync_data_.PopulateExtensionSpecifics( |
| 73 specifics->mutable_extension()); | 84 specifics->mutable_extension()); |
| 74 } | 85 } |
| 75 | 86 |
| 76 void AppSyncData::PopulateFromAppSpecifics( | 87 void AppSyncData::PopulateFromAppSpecifics( |
| 77 const sync_pb::AppSpecifics& specifics) { | 88 const sync_pb::AppSpecifics& specifics) { |
| 78 extension_sync_data_.PopulateFromExtensionSpecifics(specifics.extension()); | 89 extension_sync_data_.PopulateFromExtensionSpecifics(specifics.extension()); |
| 79 | 90 |
| 80 app_launch_ordinal_ = syncer::StringOrdinal(specifics.app_launch_ordinal()); | 91 app_launch_ordinal_ = syncer::StringOrdinal(specifics.app_launch_ordinal()); |
| 81 page_ordinal_ = syncer::StringOrdinal(specifics.page_ordinal()); | 92 page_ordinal_ = syncer::StringOrdinal(specifics.page_ordinal()); |
| 82 | 93 |
| 83 launch_type_ = specifics.has_launch_type() | 94 launch_type_ = specifics.has_launch_type() |
| 84 ? static_cast<extensions::LaunchType>(specifics.launch_type()) | 95 ? static_cast<extensions::LaunchType>(specifics.launch_type()) |
| 85 : LAUNCH_TYPE_INVALID; | 96 : LAUNCH_TYPE_INVALID; |
| 97 |
| 98 bookmark_app_url_ = specifics.bookmark_app_url(); |
| 99 bookmark_app_description_ = specifics.bookmark_app_description(); |
| 86 } | 100 } |
| 87 | 101 |
| 88 void AppSyncData::PopulateFromSyncData(const syncer::SyncData& sync_data) { | 102 void AppSyncData::PopulateFromSyncData(const syncer::SyncData& sync_data) { |
| 89 PopulateFromAppSpecifics(sync_data.GetSpecifics().app()); | 103 PopulateFromAppSpecifics(sync_data.GetSpecifics().app()); |
| 90 } | 104 } |
| 91 | 105 |
| 92 } // namespace extensions | 106 } // namespace extensions |
| OLD | NEW |