| 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_recorder.h" |    5 #include "sync/engine/traffic_recorder.h" | 
|    6  |    6  | 
|    7 #include "base/json/json_writer.h" |    7 #include "base/json/json_writer.h" | 
|    8 #include "base/logging.h" |    8 #include "base/logging.h" | 
|    9 #include "base/memory/scoped_ptr.h" |    9 #include "base/memory/scoped_ptr.h" | 
|   10 #include "base/values.h" |   10 #include "base/values.h" | 
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|   54       return "Request"; |   54       return "Request"; | 
|   55     case TrafficRecorder::CLIENT_TO_SERVER_RESPONSE: |   55     case TrafficRecorder::CLIENT_TO_SERVER_RESPONSE: | 
|   56       return "Response"; |   56       return "Response"; | 
|   57     default: |   57     default: | 
|   58       NOTREACHED(); |   58       NOTREACHED(); | 
|   59       return ""; |   59       return ""; | 
|   60   } |   60   } | 
|   61 } |   61 } | 
|   62 } |   62 } | 
|   63  |   63  | 
|   64 DictionaryValue* TrafficRecorder::TrafficRecord::ToValue() const { |   64 base::DictionaryValue* TrafficRecorder::TrafficRecord::ToValue() const { | 
|   65   scoped_ptr<DictionaryValue> value; |   65   scoped_ptr<base::DictionaryValue> value; | 
|   66   if (truncated) { |   66   if (truncated) { | 
|   67     value.reset(new DictionaryValue()); |   67     value.reset(new base::DictionaryValue()); | 
|   68     value->SetString("message_type", |   68     value->SetString("message_type", | 
|   69                      GetMessageTypeString(message_type)); |   69                      GetMessageTypeString(message_type)); | 
|   70     value->SetBoolean("truncated", true); |   70     value->SetBoolean("truncated", true); | 
|   71   } else if (message_type == TrafficRecorder::CLIENT_TO_SERVER_MESSAGE) { |   71   } else if (message_type == TrafficRecorder::CLIENT_TO_SERVER_MESSAGE) { | 
|   72     sync_pb::ClientToServerMessage message_proto; |   72     sync_pb::ClientToServerMessage message_proto; | 
|   73     if (message_proto.ParseFromString(message)) |   73     if (message_proto.ParseFromString(message)) | 
|   74       value.reset( |   74       value.reset( | 
|   75           ClientToServerMessageToValue(message_proto, |   75           ClientToServerMessageToValue(message_proto, | 
|   76                                        false /* include_specifics */)); |   76                                        false /* include_specifics */)); | 
|   77   } else if (message_type == TrafficRecorder::CLIENT_TO_SERVER_RESPONSE) { |   77   } else if (message_type == TrafficRecorder::CLIENT_TO_SERVER_RESPONSE) { | 
|   78     sync_pb::ClientToServerResponse message_proto; |   78     sync_pb::ClientToServerResponse message_proto; | 
|   79     if (message_proto.ParseFromString(message)) |   79     if (message_proto.ParseFromString(message)) | 
|   80       value.reset( |   80       value.reset( | 
|   81           ClientToServerResponseToValue(message_proto, |   81           ClientToServerResponseToValue(message_proto, | 
|   82                                         false /* include_specifics */)); |   82                                         false /* include_specifics */)); | 
|   83   } else { |   83   } else { | 
|   84     NOTREACHED(); |   84     NOTREACHED(); | 
|   85   } |   85   } | 
|   86  |   86  | 
|   87   value->SetString("timestamp", GetTimeDebugString(timestamp)); |   87   value->SetString("timestamp", GetTimeDebugString(timestamp)); | 
|   88  |   88  | 
|   89   return value.release(); |   89   return value.release(); | 
|   90 } |   90 } | 
|   91  |   91  | 
|   92  |   92  | 
|   93 ListValue* TrafficRecorder::ToValue() const { |   93 base::ListValue* TrafficRecorder::ToValue() const { | 
|   94   scoped_ptr<ListValue> value(new ListValue()); |   94   scoped_ptr<base::ListValue> value(new base::ListValue()); | 
|   95   std::deque<TrafficRecord>::const_iterator it; |   95   std::deque<TrafficRecord>::const_iterator it; | 
|   96   for (it = records_.begin(); it != records_.end(); ++it) { |   96   for (it = records_.begin(); it != records_.end(); ++it) { | 
|   97     const TrafficRecord& record = *it; |   97     const TrafficRecord& record = *it; | 
|   98     value->Append(record.ToValue()); |   98     value->Append(record.ToValue()); | 
|   99   } |   99   } | 
|  100  |  100  | 
|  101   return value.release(); |  101   return value.release(); | 
|  102 } |  102 } | 
|  103  |  103  | 
|  104  |  104  | 
| (...skipping 29 matching lines...) Expand all  Loading... | 
|  134   StoreProtoInQueue(msg, CLIENT_TO_SERVER_MESSAGE); |  134   StoreProtoInQueue(msg, CLIENT_TO_SERVER_MESSAGE); | 
|  135 } |  135 } | 
|  136  |  136  | 
|  137 void TrafficRecorder::RecordClientToServerResponse( |  137 void TrafficRecorder::RecordClientToServerResponse( | 
|  138     const sync_pb::ClientToServerResponse& response) { |  138     const sync_pb::ClientToServerResponse& response) { | 
|  139   StoreProtoInQueue(response, CLIENT_TO_SERVER_RESPONSE); |  139   StoreProtoInQueue(response, CLIENT_TO_SERVER_RESPONSE); | 
|  140 } |  140 } | 
|  141  |  141  | 
|  142 }  // namespace syncer |  142 }  // namespace syncer | 
|  143  |  143  | 
| OLD | NEW |