summaryrefslogtreecommitdiffstats
path: root/chrome/browser/sync/glue/extension_data.cc
blob: c62c3620603109b77530650d8ae2418cb3037470 (plain)
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
// Copyright (c) 2010 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/sync/glue/extension_data.h"

#include "base/logging.h"
#include "chrome/browser/sync/glue/extension_util.h"

namespace browser_sync {

ExtensionData ExtensionData::FromData(
    Source source, const sync_pb::ExtensionSpecifics& data) {
  DcheckIsExtensionSpecificsValid(data);
  ExtensionData extension_data;
  extension_data.merged_data_ = extension_data.source_data_[source] = data;
  DCHECK(AreExtensionSpecificsEqual(extension_data.merged_data(), data));
  DCHECK(!extension_data.NeedsUpdate(source));
  return extension_data;
}

ExtensionData::~ExtensionData() {}

const sync_pb::ExtensionSpecifics& ExtensionData::merged_data() const {
  DcheckIsExtensionSpecificsValid(merged_data_);
  return merged_data_;
}

bool ExtensionData::NeedsUpdate(Source source) const {
  SourceDataMap::const_iterator it = source_data_.find(source);
  return
      (it == source_data_.end()) ||
      !AreExtensionSpecificsEqual(it->second, merged_data_);
}

void ExtensionData::SetData(
    Source source, bool merge_user_properties,
    const sync_pb::ExtensionSpecifics& data) {
  DcheckIsExtensionSpecificsValid(data);
  source_data_[source] = data;
  MergeExtensionSpecifics(data, merge_user_properties, &merged_data_);
  DcheckIsExtensionSpecificsValid(merged_data_);
}

void ExtensionData::ResolveData(Source source) {
  source_data_[source] = merged_data_;
  DCHECK(!NeedsUpdate(source));
}

ExtensionData::ExtensionData() {}

}  // namespace browser_sync