| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/sync/internal_api/change_record.h" | 5 #include "chrome/browser/sync/internal_api/change_record.h" |
| 6 | 6 |
| 7 #include "base/string_number_conversions.h" | 7 #include "base/string_number_conversions.h" |
| 8 #include "base/values.h" | 8 #include "base/values.h" |
| 9 #include "chrome/browser/sync/internal_api/base_node.h" | 9 #include "chrome/browser/sync/internal_api/base_node.h" |
| 10 #include "chrome/browser/sync/internal_api/read_node.h" | 10 #include "chrome/browser/sync/internal_api/read_node.h" |
| 11 #include "chrome/browser/sync/protocol/proto_value_conversions.h" | 11 #include "chrome/browser/sync/protocol/proto_value_conversions.h" |
| 12 | 12 |
| 13 namespace sync_api { | 13 namespace sync_api { |
| 14 | 14 |
| 15 ChangeRecord::ChangeRecord() | 15 ChangeRecord::ChangeRecord() |
| 16 : id(kInvalidId), action(ACTION_ADD) {} | 16 : id(kInvalidId), action(ACTION_ADD) {} |
| 17 | 17 |
| 18 ChangeRecord::~ChangeRecord() {} | 18 ChangeRecord::~ChangeRecord() {} |
| 19 | 19 |
| 20 DictionaryValue* ChangeRecord::ToValue(const BaseTransaction* trans) const { | 20 DictionaryValue* ChangeRecord::ToValue() const { |
| 21 DictionaryValue* value = new DictionaryValue(); | 21 DictionaryValue* value = new DictionaryValue(); |
| 22 std::string action_str; | 22 std::string action_str; |
| 23 switch (action) { | 23 switch (action) { |
| 24 case ACTION_ADD: | 24 case ACTION_ADD: |
| 25 action_str = "Add"; | 25 action_str = "Add"; |
| 26 break; | 26 break; |
| 27 case ACTION_DELETE: | 27 case ACTION_DELETE: |
| 28 action_str = "Delete"; | 28 action_str = "Delete"; |
| 29 break; | 29 break; |
| 30 case ACTION_UPDATE: | 30 case ACTION_UPDATE: |
| 31 action_str = "Update"; | 31 action_str = "Update"; |
| 32 break; | 32 break; |
| 33 default: | 33 default: |
| 34 NOTREACHED(); | 34 NOTREACHED(); |
| 35 action_str = "Unknown"; | 35 action_str = "Unknown"; |
| 36 break; | 36 break; |
| 37 } | 37 } |
| 38 value->SetString("action", action_str); | 38 value->SetString("action", action_str); |
| 39 Value* node_value = NULL; | 39 value->SetString("id", base::Int64ToString(id)); |
| 40 if (action == ACTION_DELETE) { | 40 if (action == ACTION_DELETE) { |
| 41 DictionaryValue* node_dict = new DictionaryValue(); | |
| 42 node_dict->SetString("id", base::Int64ToString(id)); | |
| 43 node_dict->Set("specifics", | |
| 44 browser_sync::EntitySpecificsToValue(specifics)); | |
| 45 if (extra.get()) { | 41 if (extra.get()) { |
| 46 node_dict->Set("extra", extra->ToValue()); | 42 value->Set("extra", extra->ToValue()); |
| 47 } | 43 } |
| 48 node_value = node_dict; | 44 value->Set("specifics", |
| 49 } else { | 45 browser_sync::EntitySpecificsToValue(specifics)); |
| 50 ReadNode node(trans); | |
| 51 if (node.InitByIdLookup(id)) { | |
| 52 node_value = node.GetDetailsAsValue(); | |
| 53 } | |
| 54 } | 46 } |
| 55 if (!node_value) { | |
| 56 NOTREACHED(); | |
| 57 node_value = Value::CreateNullValue(); | |
| 58 } | |
| 59 value->Set("node", node_value); | |
| 60 return value; | 47 return value; |
| 61 } | 48 } |
| 62 | 49 |
| 63 ExtraPasswordChangeRecordData::ExtraPasswordChangeRecordData() {} | 50 ExtraPasswordChangeRecordData::ExtraPasswordChangeRecordData() {} |
| 64 | 51 |
| 65 ExtraPasswordChangeRecordData::ExtraPasswordChangeRecordData( | 52 ExtraPasswordChangeRecordData::ExtraPasswordChangeRecordData( |
| 66 const sync_pb::PasswordSpecificsData& data) | 53 const sync_pb::PasswordSpecificsData& data) |
| 67 : unencrypted_(data) { | 54 : unencrypted_(data) { |
| 68 } | 55 } |
| 69 | 56 |
| 70 ExtraPasswordChangeRecordData::~ExtraPasswordChangeRecordData() {} | 57 ExtraPasswordChangeRecordData::~ExtraPasswordChangeRecordData() {} |
| 71 | 58 |
| 72 DictionaryValue* ExtraPasswordChangeRecordData::ToValue() const { | 59 DictionaryValue* ExtraPasswordChangeRecordData::ToValue() const { |
| 73 return browser_sync::PasswordSpecificsDataToValue(unencrypted_); | 60 return browser_sync::PasswordSpecificsDataToValue(unencrypted_); |
| 74 } | 61 } |
| 75 | 62 |
| 76 const sync_pb::PasswordSpecificsData& | 63 const sync_pb::PasswordSpecificsData& |
| 77 ExtraPasswordChangeRecordData::unencrypted() const { | 64 ExtraPasswordChangeRecordData::unencrypted() const { |
| 78 return unencrypted_; | 65 return unencrypted_; |
| 79 } | 66 } |
| 80 | 67 |
| 81 } // namespace sync_api | 68 } // namespace sync_api |
| 82 | 69 |
| OLD | NEW |