base::Time multiplicative operator overloading
[chromium-blink-merge.git] / chrome / browser / extensions / app_sync_data.cc
blob6548ef5ca05e474d978b11dfac06bf9185279792
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
3 // found in the LICENSE file.
5 #include "chrome/browser/extensions/app_sync_data.h"
7 #include "chrome/common/extensions/manifest_handlers/app_icon_color_info.h"
8 #include "chrome/common/extensions/manifest_handlers/app_launch_info.h"
9 #include "extensions/common/extension.h"
10 #include "sync/api/sync_data.h"
11 #include "sync/protocol/app_specifics.pb.h"
12 #include "sync/protocol/sync.pb.h"
14 namespace extensions {
16 AppSyncData::AppSyncData() {}
18 AppSyncData::AppSyncData(const syncer::SyncData& sync_data) {
19 PopulateFromSyncData(sync_data);
22 AppSyncData::AppSyncData(const syncer::SyncChange& sync_change) {
23 PopulateFromSyncData(sync_change.sync_data());
24 extension_sync_data_.set_uninstalled(
25 sync_change.change_type() == syncer::SyncChange::ACTION_DELETE);
28 AppSyncData::AppSyncData(const Extension& extension,
29 bool enabled,
30 bool incognito_enabled,
31 bool remote_install,
32 ExtensionSyncData::OptionalBoolean all_urls_enabled,
33 const syncer::StringOrdinal& app_launch_ordinal,
34 const syncer::StringOrdinal& page_ordinal,
35 extensions::LaunchType launch_type)
36 : extension_sync_data_(extension,
37 enabled,
38 incognito_enabled,
39 remote_install,
40 all_urls_enabled),
41 app_launch_ordinal_(app_launch_ordinal),
42 page_ordinal_(page_ordinal),
43 launch_type_(launch_type) {
44 if (extension.from_bookmark()) {
45 bookmark_app_description_ = extension.description();
46 bookmark_app_url_ = AppLaunchInfo::GetLaunchWebURL(&extension).spec();
47 bookmark_app_icon_color_ = AppIconColorInfo::GetIconColorString(&extension);
51 AppSyncData::~AppSyncData() {}
53 syncer::SyncData AppSyncData::GetSyncData() const {
54 sync_pb::EntitySpecifics specifics;
55 PopulateAppSpecifics(specifics.mutable_app());
57 return syncer::SyncData::CreateLocalData(extension_sync_data_.id(),
58 extension_sync_data_.name(),
59 specifics);
62 syncer::SyncChange AppSyncData::GetSyncChange(
63 syncer::SyncChange::SyncChangeType change_type) const {
64 return syncer::SyncChange(FROM_HERE, change_type, GetSyncData());
67 void AppSyncData::PopulateAppSpecifics(sync_pb::AppSpecifics* specifics) const {
68 DCHECK(specifics);
69 // Only sync the ordinal values and launch type if they are valid.
70 if (app_launch_ordinal_.IsValid())
71 specifics->set_app_launch_ordinal(app_launch_ordinal_.ToInternalValue());
72 if (page_ordinal_.IsValid())
73 specifics->set_page_ordinal(page_ordinal_.ToInternalValue());
75 sync_pb::AppSpecifics::LaunchType sync_launch_type =
76 static_cast<sync_pb::AppSpecifics::LaunchType>(launch_type_);
78 // The corresponding validation of this value during processing of an
79 // AppSyncData is in ExtensionSyncService::ProcessAppSyncData.
80 if (launch_type_ >= LAUNCH_TYPE_FIRST && launch_type_ < NUM_LAUNCH_TYPES &&
81 sync_pb::AppSpecifics_LaunchType_IsValid(sync_launch_type)) {
82 specifics->set_launch_type(sync_launch_type);
85 if (!bookmark_app_url_.empty())
86 specifics->set_bookmark_app_url(bookmark_app_url_);
88 if (!bookmark_app_description_.empty())
89 specifics->set_bookmark_app_description(bookmark_app_description_);
91 if (!bookmark_app_icon_color_.empty())
92 specifics->set_bookmark_app_icon_color(bookmark_app_icon_color_);
94 extension_sync_data_.PopulateExtensionSpecifics(
95 specifics->mutable_extension());
98 void AppSyncData::PopulateFromAppSpecifics(
99 const sync_pb::AppSpecifics& specifics) {
100 extension_sync_data_.PopulateFromExtensionSpecifics(specifics.extension());
102 app_launch_ordinal_ = syncer::StringOrdinal(specifics.app_launch_ordinal());
103 page_ordinal_ = syncer::StringOrdinal(specifics.page_ordinal());
105 launch_type_ = specifics.has_launch_type()
106 ? static_cast<extensions::LaunchType>(specifics.launch_type())
107 : LAUNCH_TYPE_INVALID;
109 bookmark_app_url_ = specifics.bookmark_app_url();
110 bookmark_app_description_ = specifics.bookmark_app_description();
111 bookmark_app_icon_color_ = specifics.bookmark_app_icon_color();
114 void AppSyncData::PopulateFromSyncData(const syncer::SyncData& sync_data) {
115 PopulateFromAppSpecifics(sync_data.GetSpecifics().app());
118 } // namespace extensions