| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "net/log/trace_net_log_observer.h" | 5 #include "net/log/trace_net_log_observer.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/json/json_reader.h" | 10 #include "base/json/json_reader.h" |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 void OnTraceDataCollected( | 68 void OnTraceDataCollected( |
| 69 base::RunLoop* run_loop, | 69 base::RunLoop* run_loop, |
| 70 const scoped_refptr<base::RefCountedString>& events_str, | 70 const scoped_refptr<base::RefCountedString>& events_str, |
| 71 bool has_more_events) { | 71 bool has_more_events) { |
| 72 DCHECK(trace_events_->empty()); | 72 DCHECK(trace_events_->empty()); |
| 73 trace_buffer_.Start(); | 73 trace_buffer_.Start(); |
| 74 trace_buffer_.AddFragment(events_str->data()); | 74 trace_buffer_.AddFragment(events_str->data()); |
| 75 trace_buffer_.Finish(); | 75 trace_buffer_.Finish(); |
| 76 | 76 |
| 77 scoped_ptr<base::Value> trace_value; | 77 scoped_ptr<base::Value> trace_value; |
| 78 trace_value.reset(base::JSONReader::Read( | 78 trace_value = base::JSONReader::Read( |
| 79 json_output_.json_output, | 79 json_output_.json_output, |
| 80 base::JSON_PARSE_RFC | base::JSON_DETACHABLE_CHILDREN)); | 80 base::JSON_PARSE_RFC | base::JSON_DETACHABLE_CHILDREN); |
| 81 | 81 |
| 82 ASSERT_TRUE(trace_value) << json_output_.json_output; | 82 ASSERT_TRUE(trace_value) << json_output_.json_output; |
| 83 base::ListValue* trace_events = NULL; | 83 base::ListValue* trace_events = NULL; |
| 84 ASSERT_TRUE(trace_value->GetAsList(&trace_events)); | 84 ASSERT_TRUE(trace_value->GetAsList(&trace_events)); |
| 85 | 85 |
| 86 trace_events_ = FilterNetLogTraceEvents(*trace_events); | 86 trace_events_ = FilterNetLogTraceEvents(*trace_events); |
| 87 | 87 |
| 88 if (!has_more_events) | 88 if (!has_more_events) |
| 89 run_loop->Quit(); | 89 run_loop->Quit(); |
| 90 } | 90 } |
| 91 | 91 |
| 92 static void EnableTraceLog() { | 92 static void EnableTraceLog() { |
| 93 TraceLog::GetInstance()->SetEnabled( | 93 TraceLog::GetInstance()->SetEnabled( |
| 94 base::trace_event::CategoryFilter(kNetLogTracingCategory), | 94 base::trace_event::TraceConfig(kNetLogTracingCategory, ""), |
| 95 TraceLog::RECORDING_MODE, base::trace_event::TraceOptions()); | 95 TraceLog::RECORDING_MODE); |
| 96 } | 96 } |
| 97 | 97 |
| 98 void EndTraceAndFlush() { | 98 void EndTraceAndFlush() { |
| 99 base::RunLoop run_loop; | 99 base::RunLoop run_loop; |
| 100 TraceLog::GetInstance()->SetDisabled(); | 100 TraceLog::GetInstance()->SetDisabled(); |
| 101 TraceLog::GetInstance()->Flush( | 101 TraceLog::GetInstance()->Flush( |
| 102 base::Bind(&TraceNetLogObserverTest::OnTraceDataCollected, | 102 base::Bind(&TraceNetLogObserverTest::OnTraceDataCollected, |
| 103 base::Unretained(this), base::Unretained(&run_loop))); | 103 base::Unretained(this), base::Unretained(&run_loop))); |
| 104 run_loop.Run(); | 104 run_loop.Run(); |
| 105 } | 105 } |
| (...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 364 EXPECT_TRUE(item1->GetString("args.params.foo", &item1_params)); | 364 EXPECT_TRUE(item1->GetString("args.params.foo", &item1_params)); |
| 365 EXPECT_EQ("bar", item1_params); | 365 EXPECT_EQ("bar", item1_params); |
| 366 | 366 |
| 367 EXPECT_TRUE(item2->GetString("args.params", &item2_params)); | 367 EXPECT_TRUE(item2->GetString("args.params", &item2_params)); |
| 368 EXPECT_TRUE(item2_params.empty()); | 368 EXPECT_TRUE(item2_params.empty()); |
| 369 } | 369 } |
| 370 | 370 |
| 371 } // namespace | 371 } // namespace |
| 372 | 372 |
| 373 } // namespace net | 373 } // namespace net |
| OLD | NEW |