Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1225)

Side by Side Diff: chrome/browser/extensions/extension_setting_sync_data.cc

Issue 7775008: Enable sync for the settings from the Extension Settings API. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Review #6 Created 9 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2011 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/extensions/extension_setting_sync_data.h"
6
7 #include "base/json/json_reader.h"
8 #include "base/json/json_writer.h"
9 #include "chrome/browser/sync/protocol/extension_setting_specifics.pb.h"
10
11 ExtensionSettingSyncData::ExtensionSettingSyncData(
12 const SyncChange& sync_change) {
13 Init(sync_change.change_type(), sync_change.sync_data());
14 }
15
16 ExtensionSettingSyncData::ExtensionSettingSyncData(
17 const SyncData& sync_data) {
18 Init(SyncChange::ACTION_INVALID, sync_data);
19 }
20
21 void ExtensionSettingSyncData::Init(
22 SyncChange::SyncChangeType change_type, const SyncData& sync_data) {
23 DCHECK(!internal_.get());
24 sync_pb::ExtensionSettingSpecifics specifics =
25 sync_data.GetSpecifics().GetExtension(sync_pb::extension_setting);
26 Value* value =
27 base::JSONReader().JsonToValue(specifics.value(), false, false);
28 if (!value) {
29 LOG(WARNING) << "Specifics for " << specifics.extension_id() << "/" <<
30 specifics.key() << " had bad JSON for value: " << specifics.value();
31 value = new DictionaryValue();
32 }
33 internal_ = new Internal(
34 change_type,
35 specifics.extension_id(),
36 specifics.key(),
37 value);
38 }
39
40 ExtensionSettingSyncData::ExtensionSettingSyncData(
41 SyncChange::SyncChangeType change_type,
42 const std::string& extension_id,
43 const std::string& key,
44 Value* value)
45 : internal_(new Internal(change_type, extension_id, key, value)) {
46 CHECK(value);
47 }
48
49 ExtensionSettingSyncData::~ExtensionSettingSyncData() {}
50
51 SyncChange::SyncChangeType ExtensionSettingSyncData::change_type() const {
52 return internal_->change_type_;
53 }
54
55 const std::string& ExtensionSettingSyncData::extension_id() const {
56 return internal_->extension_id_;
57 }
58
59 const std::string& ExtensionSettingSyncData::key() const {
60 return internal_->key_;
61 }
62
63 const Value& ExtensionSettingSyncData::value() const {
64 return *internal_->value_;
65 }
66
67 ExtensionSettingSyncData::Internal::Internal(
68 SyncChange::SyncChangeType change_type,
69 const std::string& extension_id,
70 const std::string& key,
71 Value* value)
72 : change_type_(change_type),
73 extension_id_(extension_id),
74 key_(key),
75 value_(value) {
76 DCHECK(value);
akalin 2011/09/21 05:41:53 CHECK? You're already CHECKing in ExtensionSettin
akalin 2011/09/21 05:41:53 You're CHECKing in ExtensionSettingSyncData's cons
not at google - send to devlin 2011/09/21 06:22:41 CHECK above because it will crash later anyway if
akalin 2011/09/21 06:28:23 SGTM.
77 }
78
79 ExtensionSettingSyncData::Internal::~Internal() {}
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698