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/extension.h" | 7 #include "chrome/common/extensions/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() : notifications_disabled_(false) {} | 14 AppSyncData::AppSyncData() {} |
15 | 15 |
16 AppSyncData::AppSyncData(const syncer::SyncData& sync_data) | 16 AppSyncData::AppSyncData(const syncer::SyncData& sync_data) { |
17 : notifications_disabled_(false) { | |
18 PopulateFromSyncData(sync_data); | 17 PopulateFromSyncData(sync_data); |
19 } | 18 } |
20 | 19 |
21 AppSyncData::AppSyncData(const syncer::SyncChange& sync_change) | 20 AppSyncData::AppSyncData(const syncer::SyncChange& sync_change) { |
22 : notifications_disabled_(false) { | |
23 PopulateFromSyncData(sync_change.sync_data()); | 21 PopulateFromSyncData(sync_change.sync_data()); |
24 extension_sync_data_.set_uninstalled( | 22 extension_sync_data_.set_uninstalled( |
25 sync_change.change_type() == syncer::SyncChange::ACTION_DELETE); | 23 sync_change.change_type() == syncer::SyncChange::ACTION_DELETE); |
26 } | 24 } |
27 | 25 |
28 AppSyncData::AppSyncData(const Extension& extension, | 26 AppSyncData::AppSyncData(const Extension& extension, |
29 bool enabled, | 27 bool enabled, |
30 bool incognito_enabled, | 28 bool incognito_enabled, |
31 const std::string& notifications_client_id, | |
32 bool notifications_disabled, | |
33 const syncer::StringOrdinal& app_launch_ordinal, | 29 const syncer::StringOrdinal& app_launch_ordinal, |
34 const syncer::StringOrdinal& page_ordinal) | 30 const syncer::StringOrdinal& page_ordinal) |
35 : extension_sync_data_(extension, enabled, incognito_enabled), | 31 : extension_sync_data_(extension, enabled, incognito_enabled), |
36 notifications_client_id_(notifications_client_id), | |
37 notifications_disabled_(notifications_disabled), | |
38 app_launch_ordinal_(app_launch_ordinal), | 32 app_launch_ordinal_(app_launch_ordinal), |
39 page_ordinal_(page_ordinal) { | 33 page_ordinal_(page_ordinal) { |
40 } | 34 } |
41 | 35 |
42 AppSyncData::~AppSyncData() {} | 36 AppSyncData::~AppSyncData() {} |
43 | 37 |
44 syncer::SyncData AppSyncData::GetSyncData() const { | 38 syncer::SyncData AppSyncData::GetSyncData() const { |
45 sync_pb::EntitySpecifics specifics; | 39 sync_pb::EntitySpecifics specifics; |
46 PopulateAppSpecifics(specifics.mutable_app()); | 40 PopulateAppSpecifics(specifics.mutable_app()); |
47 | 41 |
48 return syncer::SyncData::CreateLocalData(extension_sync_data_.id(), | 42 return syncer::SyncData::CreateLocalData(extension_sync_data_.id(), |
49 extension_sync_data_.name(), | 43 extension_sync_data_.name(), |
50 specifics); | 44 specifics); |
51 } | 45 } |
52 | 46 |
53 syncer::SyncChange AppSyncData::GetSyncChange( | 47 syncer::SyncChange AppSyncData::GetSyncChange( |
54 syncer::SyncChange::SyncChangeType change_type) const { | 48 syncer::SyncChange::SyncChangeType change_type) const { |
55 return syncer::SyncChange(FROM_HERE, change_type, GetSyncData()); | 49 return syncer::SyncChange(FROM_HERE, change_type, GetSyncData()); |
56 } | 50 } |
57 | 51 |
58 void AppSyncData::PopulateAppSpecifics(sync_pb::AppSpecifics* specifics) const { | 52 void AppSyncData::PopulateAppSpecifics(sync_pb::AppSpecifics* specifics) const { |
59 DCHECK(specifics); | 53 DCHECK(specifics); |
60 sync_pb::AppNotificationSettings* notification_settings = | |
61 specifics->mutable_notification_settings(); | |
62 if (!notifications_client_id_.empty()) | |
63 notification_settings->set_oauth_client_id(notifications_client_id_); | |
64 notification_settings->set_disabled(notifications_disabled_); | |
65 | |
66 // Only sync the ordinal values if they are valid. | 54 // Only sync the ordinal values if they are valid. |
67 if (app_launch_ordinal_.IsValid()) | 55 if (app_launch_ordinal_.IsValid()) |
68 specifics->set_app_launch_ordinal(app_launch_ordinal_.ToInternalValue()); | 56 specifics->set_app_launch_ordinal(app_launch_ordinal_.ToInternalValue()); |
69 if (page_ordinal_.IsValid()) | 57 if (page_ordinal_.IsValid()) |
70 specifics->set_page_ordinal(page_ordinal_.ToInternalValue()); | 58 specifics->set_page_ordinal(page_ordinal_.ToInternalValue()); |
71 | 59 |
72 extension_sync_data_.PopulateExtensionSpecifics( | 60 extension_sync_data_.PopulateExtensionSpecifics( |
73 specifics->mutable_extension()); | 61 specifics->mutable_extension()); |
74 } | 62 } |
75 | 63 |
76 void AppSyncData::PopulateFromAppSpecifics( | 64 void AppSyncData::PopulateFromAppSpecifics( |
77 const sync_pb::AppSpecifics& specifics) { | 65 const sync_pb::AppSpecifics& specifics) { |
78 extension_sync_data_.PopulateFromExtensionSpecifics(specifics.extension()); | 66 extension_sync_data_.PopulateFromExtensionSpecifics(specifics.extension()); |
79 | 67 |
80 if (specifics.has_notification_settings() && | |
81 specifics.notification_settings().has_oauth_client_id()) { | |
82 notifications_client_id_ = | |
83 specifics.notification_settings().oauth_client_id(); | |
84 } | |
85 | |
86 notifications_disabled_ = | |
87 specifics.has_notification_settings() && | |
88 specifics.notification_settings().has_disabled() && | |
89 specifics.notification_settings().disabled(); | |
90 | |
91 app_launch_ordinal_ = syncer::StringOrdinal(specifics.app_launch_ordinal()); | 68 app_launch_ordinal_ = syncer::StringOrdinal(specifics.app_launch_ordinal()); |
92 page_ordinal_ = syncer::StringOrdinal(specifics.page_ordinal()); | 69 page_ordinal_ = syncer::StringOrdinal(specifics.page_ordinal()); |
93 } | 70 } |
94 | 71 |
95 void AppSyncData::PopulateFromSyncData(const syncer::SyncData& sync_data) { | 72 void AppSyncData::PopulateFromSyncData(const syncer::SyncData& sync_data) { |
96 PopulateFromAppSpecifics(sync_data.GetSpecifics().app()); | 73 PopulateFromAppSpecifics(sync_data.GetSpecifics().app()); |
97 } | 74 } |
98 | 75 |
99 } // namespace extensions | 76 } // namespace extensions |
OLD | NEW |