OLD | NEW |
(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/api/sync_data.h" |
| 10 #include "chrome/browser/sync/protocol/extension_setting_specifics.pb.h" |
| 11 |
| 12 ExtensionSettingSyncData::ExtensionSettingSyncData( |
| 13 const SyncChange& sync_change) { |
| 14 Init(sync_change.change_type(), sync_change.sync_data()); |
| 15 } |
| 16 |
| 17 ExtensionSettingSyncData::ExtensionSettingSyncData( |
| 18 const SyncData& sync_data) { |
| 19 Init(SyncChange::ACTION_INVALID, sync_data); |
| 20 } |
| 21 |
| 22 void ExtensionSettingSyncData::Init( |
| 23 SyncChange::SyncChangeType change_type, const SyncData& sync_data) { |
| 24 DCHECK(!internal_.get()); |
| 25 sync_pb::ExtensionSettingSpecifics specifics = |
| 26 sync_data.GetSpecifics().GetExtension(sync_pb::extension_setting); |
| 27 Value* value = |
| 28 base::JSONReader().JsonToValue(specifics.value(), false, false); |
| 29 if (!value) { |
| 30 LOG(WARNING) << "Specifics for " << specifics.extension_id() << "/" << |
| 31 specifics.key() << " had bad JSON for value: " << specifics.value(); |
| 32 value = new DictionaryValue(); |
| 33 } |
| 34 internal_ = new Internal( |
| 35 change_type, |
| 36 specifics.extension_id(), |
| 37 specifics.key(), |
| 38 value); |
| 39 } |
| 40 |
| 41 ExtensionSettingSyncData::ExtensionSettingSyncData( |
| 42 SyncChange::SyncChangeType change_type, |
| 43 const std::string& extension_id, |
| 44 const std::string& key, |
| 45 Value* value) |
| 46 : internal_(new Internal(change_type, extension_id, key, value)) { |
| 47 CHECK(value); |
| 48 } |
| 49 |
| 50 ExtensionSettingSyncData::~ExtensionSettingSyncData() {} |
| 51 |
| 52 SyncChange::SyncChangeType ExtensionSettingSyncData::change_type() const { |
| 53 return internal_->change_type_; |
| 54 } |
| 55 |
| 56 const std::string& ExtensionSettingSyncData::extension_id() const { |
| 57 return internal_->extension_id_; |
| 58 } |
| 59 |
| 60 const std::string& ExtensionSettingSyncData::key() const { |
| 61 return internal_->key_; |
| 62 } |
| 63 |
| 64 const Value& ExtensionSettingSyncData::value() const { |
| 65 return *internal_->value_; |
| 66 } |
| 67 |
| 68 ExtensionSettingSyncData::Internal::Internal( |
| 69 SyncChange::SyncChangeType change_type, |
| 70 const std::string& extension_id, |
| 71 const std::string& key, |
| 72 Value* value) |
| 73 : change_type_(change_type), |
| 74 extension_id_(extension_id), |
| 75 key_(key), |
| 76 value_(value) {} |
| 77 |
| 78 ExtensionSettingSyncData::Internal::~Internal() {} |
OLD | NEW |