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_settings_sync_util.h" |
| 6 |
| 7 #include "base/json/json_writer.h" |
| 8 #include "chrome/browser/sync/protocol/extension_setting_specifics.pb.h" |
| 9 |
| 10 namespace extension_settings_sync_util { |
| 11 |
| 12 SyncData CreateData( |
| 13 const std::string& extension_id, |
| 14 const std::string& key, |
| 15 const Value& value) { |
| 16 sync_pb::EntitySpecifics specifics; |
| 17 sync_pb::ExtensionSettingSpecifics* setting_specifics = |
| 18 specifics.MutableExtension(sync_pb::extension_setting); |
| 19 setting_specifics->set_extension_id(extension_id); |
| 20 setting_specifics->set_key(key); |
| 21 std::string value_as_json; |
| 22 base::JSONWriter::Write(&value, false, &value_as_json); |
| 23 setting_specifics->set_value(value_as_json); |
| 24 return SyncData::CreateLocalData(extension_id + "/" + key, key, specifics); |
| 25 } |
| 26 |
| 27 SyncChange CreateAdd( |
| 28 const std::string& extension_id, |
| 29 const std::string& key, |
| 30 const Value& value) { |
| 31 return SyncChange( |
| 32 SyncChange::ACTION_ADD, CreateData(extension_id, key, value)); |
| 33 } |
| 34 |
| 35 SyncChange CreateUpdate( |
| 36 const std::string& extension_id, |
| 37 const std::string& key, |
| 38 const Value& value) { |
| 39 return SyncChange( |
| 40 SyncChange::ACTION_UPDATE, CreateData(extension_id, key, value)); |
| 41 } |
| 42 |
| 43 SyncChange CreateDelete( |
| 44 const std::string& extension_id, const std::string& key) { |
| 45 DictionaryValue no_value; |
| 46 return SyncChange( |
| 47 SyncChange::ACTION_DELETE, CreateData(extension_id, key, no_value)); |
| 48 } |
| 49 |
| 50 } // namespace extension_settings_sync_util |
OLD | NEW |