| 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/network/ResourceRequest.h" |
| 10 #include "platform/tracing/TracedValue.h" |
| 11 |
| 12 namespace network_instrumentation { |
| 13 |
| 14 using network_instrumentation::RequestOutcome; |
| 15 using blink::TracedValue; |
| 16 |
| 17 const char kBlinkResourceID[] = "BlinkResourceID"; |
| 18 const char kResourceLoadTitle[] = "ResourceLoad"; |
| 19 const char kResourcePrioritySetTitle[] = "ResourcePrioritySet"; |
| 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 // We need to return something to avoid compiler warning. |
| 31 return "This should never happen"; |
| 32 } |
| 33 } |
| 34 |
| 35 ScopedResourceLoadTracker::ScopedResourceLoadTracker( |
| 36 unsigned long resourceID, |
| 37 const blink::ResourceRequest& request) |
| 38 : m_resourceLoadContinuesBeyondScope(false), m_resourceID(resourceID) { |
| 39 std::unique_ptr<TracedValue> beginData = TracedValue::create(); |
| 40 beginData->setString("url", request.url().getString()); |
| 41 TRACE_EVENT_NESTABLE_ASYNC_BEGIN1( |
| 42 kNetInstrumentationCategory, kResourceLoadTitle, |
| 43 TRACE_ID_WITH_SCOPE(kBlinkResourceID, TRACE_ID_LOCAL(resourceID)), |
| 44 "beginData", std::move(beginData)); |
| 45 } |
| 46 |
| 47 ScopedResourceLoadTracker::~ScopedResourceLoadTracker() { |
| 48 if (!m_resourceLoadContinuesBeyondScope) |
| 49 endResourceLoad(m_resourceID, RequestOutcome::Fail); |
| 50 } |
| 51 |
| 52 void ScopedResourceLoadTracker::resourceLoadContinuesBeyondScope() { |
| 53 m_resourceLoadContinuesBeyondScope = true; |
| 54 } |
| 55 |
| 56 void resourcePrioritySet(unsigned long resourceID, |
| 57 blink::ResourceLoadPriority priority) { |
| 58 std::unique_ptr<TracedValue> data = TracedValue::create(); |
| 59 data->setInteger("priority", priority); |
| 60 TRACE_EVENT_NESTABLE_ASYNC_INSTANT1( |
| 61 kNetInstrumentationCategory, kResourcePrioritySetTitle, |
| 62 TRACE_ID_WITH_SCOPE(kBlinkResourceID, TRACE_ID_LOCAL(resourceID)), "data", |
| 63 std::move(data)); |
| 64 } |
| 65 |
| 66 void endResourceLoad(unsigned long resourceID, RequestOutcome outcome) { |
| 67 std::unique_ptr<TracedValue> endData = TracedValue::create(); |
| 68 endData->setString("outcome", RequestOutcomeToString(outcome)); |
| 69 TRACE_EVENT_NESTABLE_ASYNC_END1( |
| 70 kNetInstrumentationCategory, kResourceLoadTitle, |
| 71 TRACE_ID_WITH_SCOPE(kBlinkResourceID, TRACE_ID_LOCAL(resourceID)), |
| 72 "endData", std::move(endData)); |
| 73 } |
| 74 |
| 75 } // namespace network_instrumentation |
| OLD | NEW |