Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2016 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 | |
| 5 #include "platform/network/NetworkInstrumentation.h" | |
| 6 | |
| 7 #include "base/trace_event/trace_event.h" | |
| 8 #include "platform/network/ResourceLoadPriority.h" | |
| 9 #include "platform/tracing/TracedValue.h" | |
| 10 | |
| 11 namespace network_instrumentation { | |
| 12 | |
| 13 using network_instrumentation::RequestOutcome; | |
| 14 using blink::TracedValue; | |
| 15 | |
| 16 const char kBlinkResourceID[] = "BlinkResourceID"; | |
| 17 const char kResourceLoadTitle[] = "ResourceLoad"; | |
| 18 const char kInitialResourcePrioritySetTitle[] = "InitialResourcePrioritySet"; | |
| 19 const char kResourcePriorityChangedTitle[] = "ResourcePriorityChanged"; | |
| 20 const char kNetInstrumentationCategory[] = TRACE_DISABLED_BY_DEFAULT("network"); | |
| 21 | |
| 22 const char* RequestOutcomeToString(RequestOutcome outcome) { | |
| 23 switch (outcome) { | |
| 24 case RequestOutcome::Success: | |
| 25 return "Success"; | |
| 26 case RequestOutcome::Fail: | |
| 27 return "Fail"; | |
| 28 default: | |
| 29 NOTREACHED(); | |
| 30 } | |
| 31 } | |
| 32 | |
| 33 ScopedResourceLoadTracker::ScopedResourceLoadTracker( | |
| 34 unsigned long resourceID, | |
| 35 const blink::ResourceRequest& request) | |
| 36 : closeSliceAtEndOfScope(true), resourceID(resourceID) { | |
| 37 std::unique_ptr<TracedValue> beginData = TracedValue::create(); | |
| 38 beginData->setString("url", request.url().getString()); | |
| 39 TRACE_EVENT_NESTABLE_ASYNC_BEGIN1( | |
| 40 kNetInstrumentationCategory, kResourceLoadTitle, | |
| 41 TRACE_ID_WITH_SCOPE(kBlinkResourceID, TRACE_ID_LOCAL(resourceID)), | |
| 42 "beginData", std::move(beginData)); | |
| 43 } | |
| 44 | |
| 45 ScopedResourceLoadTracker::~ScopedResourceLoadTracker() { | |
| 46 if (this->closeSliceAtEndOfScope) | |
|
caseq
2016/11/08 18:24:32
we generally don't mention this-> explicitly.
dproy
2016/11/09 20:44:00
Done for all the `this` cases.
| |
| 47 endResourceLoad(this->resourceID, RequestOutcome::Fail); | |
|
caseq
2016/11/08 18:24:32
ditto.
| |
| 48 } | |
| 49 | |
| 50 void ScopedResourceLoadTracker::doNotCloseSliceAtEndOfScope() { | |
| 51 this->closeSliceAtEndOfScope = false; | |
|
caseq
2016/11/08 18:24:32
ditto.
| |
| 52 } | |
| 53 | |
| 54 void initialResourcePrioritySet(unsigned long resourceID, | |
| 55 blink::ResourceLoadPriority priority) { | |
| 56 std::unique_ptr<TracedValue> data = TracedValue::create(); | |
| 57 data->setInteger("initialPriority", priority); | |
|
caseq
2016/11/08 18:24:32
ditto.
| |
| 58 TRACE_EVENT_NESTABLE_ASYNC_INSTANT1( | |
| 59 kNetInstrumentationCategory, kInitialResourcePrioritySetTitle, | |
| 60 TRACE_ID_WITH_SCOPE(kBlinkResourceID, TRACE_ID_LOCAL(resourceID)), "data", | |
| 61 std::move(data)); | |
| 62 } | |
| 63 | |
| 64 void resourcePriorityChanged(unsigned long resourceID, | |
| 65 blink::ResourceLoadPriority priority) { | |
| 66 std::unique_ptr<TracedValue> data = TracedValue::create(); | |
| 67 data->setInteger("newPriority", priority); | |
| 68 TRACE_EVENT_NESTABLE_ASYNC_INSTANT1( | |
| 69 kNetInstrumentationCategory, kResourcePriorityChangedTitle, | |
| 70 TRACE_ID_WITH_SCOPE(kBlinkResourceID, TRACE_ID_LOCAL(resourceID)), "data", | |
| 71 std::move(data)); | |
| 72 } | |
| 73 | |
| 74 void endResourceLoad(unsigned long resourceID, RequestOutcome outcome) { | |
| 75 std::unique_ptr<TracedValue> endData = TracedValue::create(); | |
| 76 endData->setString("outcome", RequestOutcomeToString(outcome)); | |
| 77 TRACE_EVENT_NESTABLE_ASYNC_END1( | |
| 78 kNetInstrumentationCategory, kResourceLoadTitle, | |
| 79 TRACE_ID_WITH_SCOPE(kBlinkResourceID, TRACE_ID_LOCAL(resourceID)), | |
| 80 "endData", std::move(endData)); | |
| 81 } | |
| 82 | |
| 83 } // namespace network_instrumentation | |
| OLD | NEW |