traffic_logger.cc 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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
  3. // found in the LICENSE file.
  4. #include "components/sync/engine/traffic_logger.h"
  5. #include <memory>
  6. #include <string>
  7. #include "base/json/json_writer.h"
  8. #include "base/logging.h"
  9. #include "base/values.h"
  10. #include "components/sync/protocol/proto_value_conversions.h"
  11. namespace syncer {
  12. namespace {
  13. template <class T>
  14. void LogData(const T& data,
  15. std::unique_ptr<base::DictionaryValue> (*to_dictionary_value)(
  16. const T&,
  17. const ProtoValueConversionOptions& options),
  18. const std::string& description) {
  19. if (DCHECK_IS_ON() && VLOG_IS_ON(1)) {
  20. std::unique_ptr<base::DictionaryValue> value =
  21. (*to_dictionary_value)(data, /*options=*/{});
  22. std::string message;
  23. base::JSONWriter::WriteWithOptions(
  24. *value, base::JSONWriter::OPTIONS_PRETTY_PRINT, &message);
  25. DVLOG(1) << "\n" << description << "\n" << message << "\n";
  26. }
  27. }
  28. } // namespace
  29. void LogClientToServerMessage(const sync_pb::ClientToServerMessage& msg) {
  30. LogData(msg, &ClientToServerMessageToValue,
  31. "******Client To Server Message******");
  32. }
  33. void LogClientToServerResponse(
  34. const sync_pb::ClientToServerResponse& response) {
  35. LogData(response, &ClientToServerResponseToValue,
  36. "******Server Response******");
  37. }
  38. } // namespace syncer