1 // Copyright (c) 2010 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.
4
5 #include "chrome/browser/sync/glue/extension_data.h"
6
7 #include "base/logging.h"
8 #include "chrome/browser/sync/glue/extension_util.h"
9
10 namespace browser_sync {
11
FromData(Source source,const sync_pb::ExtensionSpecifics & data)12 ExtensionData ExtensionData::FromData(
13 Source source, const sync_pb::ExtensionSpecifics& data) {
14 DcheckIsExtensionSpecificsValid(data);
15 ExtensionData extension_data;
16 extension_data.merged_data_ = extension_data.source_data_[source] = data;
17 DCHECK(AreExtensionSpecificsEqual(extension_data.merged_data(), data));
18 DCHECK(!extension_data.NeedsUpdate(source));
19 return extension_data;
20 }
21
~ExtensionData()22 ExtensionData::~ExtensionData() {}
23
merged_data() const24 const sync_pb::ExtensionSpecifics& ExtensionData::merged_data() const {
25 DcheckIsExtensionSpecificsValid(merged_data_);
26 return merged_data_;
27 }
28
NeedsUpdate(Source source) const29 bool ExtensionData::NeedsUpdate(Source source) const {
30 SourceDataMap::const_iterator it = source_data_.find(source);
31 return
32 (it == source_data_.end()) ||
33 !AreExtensionSpecificsEqual(it->second, merged_data_);
34 }
35
SetData(Source source,bool merge_user_properties,const sync_pb::ExtensionSpecifics & data)36 void ExtensionData::SetData(
37 Source source, bool merge_user_properties,
38 const sync_pb::ExtensionSpecifics& data) {
39 DcheckIsExtensionSpecificsValid(data);
40 source_data_[source] = data;
41 MergeExtensionSpecifics(data, merge_user_properties, &merged_data_);
42 DcheckIsExtensionSpecificsValid(merged_data_);
43 }
44
ResolveData(Source source)45 void ExtensionData::ResolveData(Source source) {
46 source_data_[source] = merged_data_;
47 DCHECK(!NeedsUpdate(source));
48 }
49
ExtensionData()50 ExtensionData::ExtensionData() {}
51
52 } // namespace browser_sync
53