OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "sync/engine/traffic_logger.h" | 5 #include "sync/engine/traffic_logger.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/json/json_writer.h" | 9 #include "base/json/json_writer.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
12 #include "base/values.h" | 12 #include "base/values.h" |
13 #include "sync/protocol/proto_value_conversions.h" | 13 #include "sync/protocol/proto_value_conversions.h" |
14 #include "sync/protocol/sync.pb.h" | 14 #include "sync/protocol/sync.pb.h" |
15 | 15 |
16 namespace syncer { | 16 namespace syncer { |
17 | 17 |
18 namespace { | 18 namespace { |
19 template <class T> | 19 template <class T> |
20 void LogData(const T& data, | 20 void LogData(const T& data, |
21 scoped_ptr<base::DictionaryValue>(*to_dictionary_value)(const T&, | 21 scoped_ptr<base::DictionaryValue>(*to_dictionary_value)(const T&, |
22 bool), | 22 bool), |
23 const std::string& description) { | 23 const std::string& description) { |
24 if (::logging::DEBUG_MODE && VLOG_IS_ON(1)) { | 24 if (::logging::DEBUG_MODE && VLOG_IS_ON(1)) { |
25 scoped_ptr<base::DictionaryValue> value = | 25 scoped_ptr<base::DictionaryValue> value = |
26 (*to_dictionary_value)(data, true /* include_specifics */); | 26 (*to_dictionary_value)(data, true /* include_specifics */); |
27 std::string message; | 27 std::string message; |
28 base::JSONWriter::WriteWithOptions(value.get(), | 28 base::JSONWriter::WriteWithOptions( |
29 base::JSONWriter::OPTIONS_PRETTY_PRINT, | 29 *value, base::JSONWriter::OPTIONS_PRETTY_PRINT, &message); |
30 &message); | |
31 DVLOG(1) << "\n" << description << "\n" << message << "\n"; | 30 DVLOG(1) << "\n" << description << "\n" << message << "\n"; |
32 } | 31 } |
33 } | 32 } |
34 } // namespace | 33 } // namespace |
35 | 34 |
36 void LogClientToServerMessage(const sync_pb::ClientToServerMessage& msg) { | 35 void LogClientToServerMessage(const sync_pb::ClientToServerMessage& msg) { |
37 LogData(msg, &ClientToServerMessageToValue, | 36 LogData(msg, &ClientToServerMessageToValue, |
38 "******Client To Server Message******"); | 37 "******Client To Server Message******"); |
39 } | 38 } |
40 | 39 |
41 void LogClientToServerResponse( | 40 void LogClientToServerResponse( |
42 const sync_pb::ClientToServerResponse& response) { | 41 const sync_pb::ClientToServerResponse& response) { |
43 LogData(response, &ClientToServerResponseToValue, | 42 LogData(response, &ClientToServerResponseToValue, |
44 "******Server Response******"); | 43 "******Server Response******"); |
45 } | 44 } |
46 | 45 |
47 } // namespace syncer | 46 } // namespace syncer |
OLD | NEW |