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

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. 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 <iostream>
akalin 2011/09/22 01:24:56 iostream -> ostream
James Hawkins 2011/09/22 02:50:29 Done.
8 #include <sstream>
9
10 #include "base/json/json_writer.h"
11 #include "base/memory/scoped_ptr.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"
9 17
10 void SyncData::ImmutableSyncEntityTraits::InitializeWrapper( 18 void SyncData::ImmutableSyncEntityTraits::InitializeWrapper(
11 Wrapper* wrapper) { 19 Wrapper* wrapper) {
12 *wrapper = new sync_pb::SyncEntity(); 20 *wrapper = new sync_pb::SyncEntity();
13 } 21 }
14 22
15 void SyncData::ImmutableSyncEntityTraits::DestroyWrapper( 23 void SyncData::ImmutableSyncEntityTraits::DestroyWrapper(
16 Wrapper* wrapper) { 24 Wrapper* wrapper) {
17 delete *wrapper; 25 delete *wrapper;
18 } 26 }
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 } 103 }
96 104
97 int64 SyncData::GetRemoteId() const { 105 int64 SyncData::GetRemoteId() const {
98 DCHECK(!IsLocal()); 106 DCHECK(!IsLocal());
99 return id_; 107 return id_;
100 } 108 }
101 109
102 bool SyncData::IsLocal() const { 110 bool SyncData::IsLocal() const {
103 return id_ == sync_api::kInvalidId; 111 return id_ == sync_api::kInvalidId;
104 } 112 }
113
114 std::string SyncData::ToString() const {
115 int64 id = IsLocal() ? 0 : GetRemoteId();
akalin 2011/09/22 01:24:56 prefer something like: if (IsValid()) { if (IsL
James Hawkins 2011/09/22 02:50:29 Done.
116 const std::string& tag = IsLocal() ? GetTag() : "";
117 std::string specifics;
118 scoped_ptr<DictionaryValue> value(
119 browser_sync::EntitySpecificsToValue(GetSpecifics()));
120 base::JSONWriter::Write(value.get(), true, &specifics);
121
122 std::string out;
123 std::stringstream ss(out, std::stringstream::in);
124 ss <<
125 "{" << id <<
126 ", " << IsValid() <<
127 ", " << IsLocal() <<
128 ", " << syncable::ModelTypeToString(GetDataType()) <<
129 ", " << tag <<
130 ", " << GetTitle() <<
131 ", " << specifics <<
132 "}";
133 return out;
134 }
135
136 void PrintTo(const SyncData& sync_data, std::ostream* os) {
137 *os << sync_data.ToString();
138 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698