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_icon_color_info.h" | 7 #include "chrome/common/extensions/manifest_handlers/app_icon_color_info.h" |
8 #include "chrome/common/extensions/manifest_handlers/app_launch_info.h" | 8 #include "chrome/common/extensions/manifest_handlers/app_launch_info.h" |
| 9 #include "chrome/common/extensions/manifest_handlers/linked_app_icons.h" |
9 #include "extensions/common/extension.h" | 10 #include "extensions/common/extension.h" |
10 #include "sync/api/sync_data.h" | 11 #include "sync/api/sync_data.h" |
11 #include "sync/protocol/app_specifics.pb.h" | 12 #include "sync/protocol/app_specifics.pb.h" |
12 #include "sync/protocol/sync.pb.h" | 13 #include "sync/protocol/sync.pb.h" |
13 | 14 |
14 namespace extensions { | 15 namespace extensions { |
15 | 16 |
| 17 AppSyncData::LinkedAppIconInfo::LinkedAppIconInfo() { |
| 18 } |
| 19 |
| 20 AppSyncData::LinkedAppIconInfo::~LinkedAppIconInfo() { |
| 21 } |
| 22 |
16 AppSyncData::AppSyncData() {} | 23 AppSyncData::AppSyncData() {} |
17 | 24 |
18 AppSyncData::AppSyncData(const Extension& extension, | 25 AppSyncData::AppSyncData(const Extension& extension, |
19 bool enabled, | 26 bool enabled, |
20 bool incognito_enabled, | 27 bool incognito_enabled, |
21 bool remote_install, | 28 bool remote_install, |
22 ExtensionSyncData::OptionalBoolean all_urls_enabled, | 29 ExtensionSyncData::OptionalBoolean all_urls_enabled, |
23 const syncer::StringOrdinal& app_launch_ordinal, | 30 const syncer::StringOrdinal& app_launch_ordinal, |
24 const syncer::StringOrdinal& page_ordinal, | 31 const syncer::StringOrdinal& page_ordinal, |
25 extensions::LaunchType launch_type) | 32 extensions::LaunchType launch_type) |
26 : extension_sync_data_(extension, | 33 : extension_sync_data_(extension, |
27 enabled, | 34 enabled, |
28 incognito_enabled, | 35 incognito_enabled, |
29 remote_install, | 36 remote_install, |
30 all_urls_enabled), | 37 all_urls_enabled), |
31 app_launch_ordinal_(app_launch_ordinal), | 38 app_launch_ordinal_(app_launch_ordinal), |
32 page_ordinal_(page_ordinal), | 39 page_ordinal_(page_ordinal), |
33 launch_type_(launch_type) { | 40 launch_type_(launch_type) { |
34 if (extension.from_bookmark()) { | 41 if (extension.from_bookmark()) { |
35 bookmark_app_description_ = extension.description(); | 42 bookmark_app_description_ = extension.description(); |
36 bookmark_app_url_ = AppLaunchInfo::GetLaunchWebURL(&extension).spec(); | 43 bookmark_app_url_ = AppLaunchInfo::GetLaunchWebURL(&extension).spec(); |
37 bookmark_app_icon_color_ = AppIconColorInfo::GetIconColorString(&extension); | 44 bookmark_app_icon_color_ = AppIconColorInfo::GetIconColorString(&extension); |
| 45 extensions::LinkedAppIcons icons = |
| 46 LinkedAppIcons::GetLinkedAppIcons(&extension); |
| 47 for (const auto& icon : icons.icons) { |
| 48 LinkedAppIconInfo linked_icon; |
| 49 linked_icon.url = icon.url; |
| 50 linked_icon.size = icon.size; |
| 51 linked_icons_.push_back(linked_icon); |
| 52 } |
38 } | 53 } |
39 } | 54 } |
40 | 55 |
41 AppSyncData::~AppSyncData() {} | 56 AppSyncData::~AppSyncData() {} |
42 | 57 |
43 // static | 58 // static |
44 scoped_ptr<AppSyncData> AppSyncData::CreateFromSyncData( | 59 scoped_ptr<AppSyncData> AppSyncData::CreateFromSyncData( |
45 const syncer::SyncData& sync_data) { | 60 const syncer::SyncData& sync_data) { |
46 scoped_ptr<AppSyncData> data(new AppSyncData); | 61 scoped_ptr<AppSyncData> data(new AppSyncData); |
47 if (data->PopulateFromSyncData(sync_data)) | 62 if (data->PopulateFromSyncData(sync_data)) |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 | 110 |
96 if (!bookmark_app_url_.empty()) | 111 if (!bookmark_app_url_.empty()) |
97 specifics->set_bookmark_app_url(bookmark_app_url_); | 112 specifics->set_bookmark_app_url(bookmark_app_url_); |
98 | 113 |
99 if (!bookmark_app_description_.empty()) | 114 if (!bookmark_app_description_.empty()) |
100 specifics->set_bookmark_app_description(bookmark_app_description_); | 115 specifics->set_bookmark_app_description(bookmark_app_description_); |
101 | 116 |
102 if (!bookmark_app_icon_color_.empty()) | 117 if (!bookmark_app_icon_color_.empty()) |
103 specifics->set_bookmark_app_icon_color(bookmark_app_icon_color_); | 118 specifics->set_bookmark_app_icon_color(bookmark_app_icon_color_); |
104 | 119 |
| 120 for (const auto& linked_icon : linked_icons_) { |
| 121 sync_pb::LinkedAppIconInfo* linked_app_icon_info = |
| 122 specifics->add_linked_app_icons(); |
| 123 linked_app_icon_info->set_url(linked_icon.url.spec()); |
| 124 linked_app_icon_info->set_size(linked_icon.size); |
| 125 } |
| 126 |
105 extension_sync_data_.PopulateExtensionSpecifics( | 127 extension_sync_data_.PopulateExtensionSpecifics( |
106 specifics->mutable_extension()); | 128 specifics->mutable_extension()); |
107 } | 129 } |
108 | 130 |
109 bool AppSyncData::PopulateFromAppSpecifics( | 131 bool AppSyncData::PopulateFromAppSpecifics( |
110 const sync_pb::AppSpecifics& specifics) { | 132 const sync_pb::AppSpecifics& specifics) { |
111 if (!extension_sync_data_.PopulateFromExtensionSpecifics( | 133 if (!extension_sync_data_.PopulateFromExtensionSpecifics( |
112 specifics.extension())) | 134 specifics.extension())) |
113 return false; | 135 return false; |
114 | 136 |
115 app_launch_ordinal_ = syncer::StringOrdinal(specifics.app_launch_ordinal()); | 137 app_launch_ordinal_ = syncer::StringOrdinal(specifics.app_launch_ordinal()); |
116 page_ordinal_ = syncer::StringOrdinal(specifics.page_ordinal()); | 138 page_ordinal_ = syncer::StringOrdinal(specifics.page_ordinal()); |
117 | 139 |
118 launch_type_ = specifics.has_launch_type() | 140 launch_type_ = specifics.has_launch_type() |
119 ? static_cast<extensions::LaunchType>(specifics.launch_type()) | 141 ? static_cast<extensions::LaunchType>(specifics.launch_type()) |
120 : LAUNCH_TYPE_INVALID; | 142 : LAUNCH_TYPE_INVALID; |
121 | 143 |
122 bookmark_app_url_ = specifics.bookmark_app_url(); | 144 bookmark_app_url_ = specifics.bookmark_app_url(); |
123 bookmark_app_description_ = specifics.bookmark_app_description(); | 145 bookmark_app_description_ = specifics.bookmark_app_description(); |
124 bookmark_app_icon_color_ = specifics.bookmark_app_icon_color(); | 146 bookmark_app_icon_color_ = specifics.bookmark_app_icon_color(); |
| 147 |
| 148 for (int i = 0; i < specifics.linked_app_icons_size(); ++i) { |
| 149 const sync_pb::LinkedAppIconInfo& linked_app_icon_info = |
| 150 specifics.linked_app_icons(i); |
| 151 if (linked_app_icon_info.has_url() && linked_app_icon_info.has_size()) { |
| 152 LinkedAppIconInfo linked_icon; |
| 153 linked_icon.url = GURL(linked_app_icon_info.url()); |
| 154 linked_icon.size = linked_app_icon_info.size(); |
| 155 linked_icons_.push_back(linked_icon); |
| 156 } |
| 157 } |
| 158 |
125 return true; | 159 return true; |
126 } | 160 } |
127 | 161 |
128 bool AppSyncData::PopulateFromSyncData(const syncer::SyncData& sync_data) { | 162 bool AppSyncData::PopulateFromSyncData(const syncer::SyncData& sync_data) { |
129 return PopulateFromAppSpecifics(sync_data.GetSpecifics().app()); | 163 return PopulateFromAppSpecifics(sync_data.GetSpecifics().app()); |
130 } | 164 } |
131 | 165 |
132 } // namespace extensions | 166 } // namespace extensions |
OLD | NEW |