1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
|
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/extensions/extension_sync_data.h"
#include "base/logging.h"
#include "chrome/browser/extensions/app_sync_data.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/common/extensions/manifest_url_handler.h"
#include "components/crx_file/id_util.h"
#include "extensions/common/extension.h"
#include "sync/api/sync_data.h"
#include "sync/protocol/extension_specifics.pb.h"
#include "sync/protocol/sync.pb.h"
namespace extensions {
ExtensionSyncData::ExtensionSyncData()
: uninstalled_(false),
enabled_(false),
incognito_enabled_(false),
remote_install_(false),
installed_by_custodian_(false) {
}
ExtensionSyncData::ExtensionSyncData(const syncer::SyncData& sync_data)
: uninstalled_(false),
enabled_(false),
incognito_enabled_(false),
remote_install_(false),
installed_by_custodian_(false) {
PopulateFromSyncData(sync_data);
}
ExtensionSyncData::ExtensionSyncData(const syncer::SyncChange& sync_change)
: uninstalled_(sync_change.change_type() ==
syncer::SyncChange::ACTION_DELETE),
enabled_(false),
incognito_enabled_(false),
remote_install_(false),
installed_by_custodian_(false) {
PopulateFromSyncData(sync_change.sync_data());
}
ExtensionSyncData::ExtensionSyncData(const Extension& extension,
bool enabled,
bool incognito_enabled,
bool remote_install)
: id_(extension.id()),
uninstalled_(false),
enabled_(enabled),
incognito_enabled_(incognito_enabled),
remote_install_(remote_install),
installed_by_custodian_(extension.was_installed_by_custodian()),
version_(extension.from_bookmark() ? base::Version("0")
: *extension.version()),
update_url_(ManifestURL::GetUpdateURL(&extension)),
name_(extension.non_localized_name()) {
}
ExtensionSyncData::~ExtensionSyncData() {}
syncer::SyncData ExtensionSyncData::GetSyncData() const {
sync_pb::EntitySpecifics specifics;
PopulateExtensionSpecifics(specifics.mutable_extension());
return syncer::SyncData::CreateLocalData(id_, name_, specifics);
}
syncer::SyncChange ExtensionSyncData::GetSyncChange(
syncer::SyncChange::SyncChangeType change_type) const {
return syncer::SyncChange(FROM_HERE, change_type, GetSyncData());
}
void ExtensionSyncData::PopulateExtensionSpecifics(
sync_pb::ExtensionSpecifics* specifics) const {
DCHECK(crx_file::id_util::IdIsValid(id_));
specifics->set_id(id_);
specifics->set_update_url(update_url_.spec());
specifics->set_version(version_.GetString());
specifics->set_enabled(enabled_);
specifics->set_incognito_enabled(incognito_enabled_);
specifics->set_remote_install(remote_install_);
specifics->set_installed_by_custodian(installed_by_custodian_);
specifics->set_name(name_);
}
void ExtensionSyncData::PopulateFromExtensionSpecifics(
const sync_pb::ExtensionSpecifics& specifics) {
if (!crx_file::id_util::IdIsValid(specifics.id())) {
LOG(FATAL) << "Attempt to sync bad ExtensionSpecifics.";
}
Version specifics_version(specifics.version());
if (!specifics_version.IsValid())
LOG(FATAL) << "Attempt to sync bad ExtensionSpecifics.";
// The update URL must be either empty or valid.
GURL specifics_update_url(specifics.update_url());
if (!specifics_update_url.is_empty() && !specifics_update_url.is_valid()) {
LOG(FATAL) << "Attempt to sync bad ExtensionSpecifics.";
}
id_ = specifics.id();
update_url_ = specifics_update_url;
version_ = specifics_version;
enabled_ = specifics.enabled();
incognito_enabled_ = specifics.incognito_enabled();
remote_install_ = specifics.remote_install();
installed_by_custodian_ = specifics.installed_by_custodian();
name_ = specifics.name();
}
void ExtensionSyncData::set_uninstalled(bool uninstalled) {
uninstalled_ = uninstalled;
}
void ExtensionSyncData::PopulateFromSyncData(
const syncer::SyncData& sync_data) {
const sync_pb::EntitySpecifics& entity_specifics = sync_data.GetSpecifics();
if (entity_specifics.has_extension()) {
PopulateFromExtensionSpecifics(entity_specifics.extension());
} else {
LOG(FATAL) << "Attempt to sync bad EntitySpecifics.";
}
}
} // namespace extensions
|