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

Side by Side Diff: chrome/browser/sync/api/sync_data.cc

Issue 7978044: Sync/Valgrind: Add gmock printers for SyncChange, SyncData, SyncError. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Review fixes 2. 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
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/api/sync_data.h" 5 #include "chrome/browser/sync/api/sync_data.h"
6 6
7 #include <ostream>
8
9 #include "base/json/json_writer.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "base/utf_string_conversions.h"
12 #include "base/values.h"
7 #include "chrome/browser/sync/internal_api/base_node.h" 13 #include "chrome/browser/sync/internal_api/base_node.h"
14 #include "chrome/browser/sync/protocol/proto_value_conversions.h"
8 #include "chrome/browser/sync/protocol/sync.pb.h" 15 #include "chrome/browser/sync/protocol/sync.pb.h"
16 #include "chrome/browser/sync/syncable/model_type.h"
17 #include "ui/base/text/bytes_formatting.h"
9 18
10 void SyncData::ImmutableSyncEntityTraits::InitializeWrapper( 19 void SyncData::ImmutableSyncEntityTraits::InitializeWrapper(
11 Wrapper* wrapper) { 20 Wrapper* wrapper) {
12 *wrapper = new sync_pb::SyncEntity(); 21 *wrapper = new sync_pb::SyncEntity();
13 } 22 }
14 23
15 void SyncData::ImmutableSyncEntityTraits::DestroyWrapper( 24 void SyncData::ImmutableSyncEntityTraits::DestroyWrapper(
16 Wrapper* wrapper) { 25 Wrapper* wrapper) {
17 delete *wrapper; 26 delete *wrapper;
18 } 27 }
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 } 104 }
96 105
97 int64 SyncData::GetRemoteId() const { 106 int64 SyncData::GetRemoteId() const {
98 DCHECK(!IsLocal()); 107 DCHECK(!IsLocal());
99 return id_; 108 return id_;
100 } 109 }
101 110
102 bool SyncData::IsLocal() const { 111 bool SyncData::IsLocal() const {
103 return id_ == sync_api::kInvalidId; 112 return id_ == sync_api::kInvalidId;
104 } 113 }
114
115 std::string SyncData::ToString() const {
116 if (!IsValid())
117 return "<Invalid SyncData>";
118
119 std::string type = syncable::ModelTypeToString(GetDataType());
120 std::string specifics;
121 scoped_ptr<DictionaryValue> value(
122 browser_sync::EntitySpecificsToValue(GetSpecifics()));
123 base::JSONWriter::Write(value.get(), true, &specifics);
124
125 if (IsLocal()) {
126 std::string tag = IsLocal() ? GetTag() : "";
akalin 2011/09/22 02:59:44 std::string tag = GetTag(); Or just inline it to
James Hawkins 2011/09/22 21:01:58 Done.
127 return "{" + type + ", " + tag + ", " + GetTitle() + ", " + specifics + "}";
akalin 2011/09/22 02:59:44 return "{ isLocal: true, type: " + type + ", tag:
James Hawkins 2011/09/22 21:01:58 Done.
128 }
129
130 std::string id = UTF16ToUTF8(ui::FormatBytes(GetRemoteId()));
akalin 2011/09/22 02:59:44 eh? Just do base::Int64ToString(GetRemoteId()) (#
James Hawkins 2011/09/22 21:01:58 Done.
131 return "{" + type + ", " + specifics + ", " + id + "}";
akalin 2011/09/22 02:59:44 return "{ isLocal: false, type: " + ... + ", speci
James Hawkins 2011/09/22 21:01:58 Done.
132 }
133
134 void PrintTo(const SyncData& sync_data, std::ostream* os) {
135 *os << sync_data.ToString();
136 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698