blob: 926c98acc08464cb0c60e6172d67888ac2596e38 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
|
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#import "ios/chrome/browser/net/metrics_network_client_manager.h"
#import "base/ios/weak_nsobject.h"
#import "base/location.h"
#include "base/mac/bind_objc_block.h"
#include "base/mac/scoped_nsobject.h"
#include "base/metrics/histogram.h"
#import "ios/chrome/browser/net/metrics_network_client.h"
#include "ios/web/public/web_thread.h"
#include "url/gurl.h"
@interface PageLoadTimeRecord ()
@property(nonatomic, readonly) GURL url;
@property(nonatomic, readonly) base::TimeTicks creationTime;
@property(nonatomic, assign) BOOL alreadyCounted;
- (instancetype)initWithURL:(const GURL&)url time:(base::TimeTicks)time;
@end
@implementation PageLoadTimeRecord {
GURL _url;
base::TimeTicks _creationTime;
BOOL _alreadyCounted;
BOOL _dataProxyUsed;
}
@synthesize url = _url;
@synthesize creationTime = _creationTime;
@synthesize alreadyCounted = _alreadyCounted;
@synthesize dataProxyUsed = _dataProxyUsed;
- (instancetype)initWithURL:(const GURL&)url time:(base::TimeTicks)time {
if ((self = [super init])) {
_url = url;
_creationTime = time;
}
return self;
}
@end
@interface MetricsNetworkClientManager ()
// IO-thread-only methods.
- (void)handlePageLoadStarted:(const GURL&)url;
- (void)handlePageLoadCompleted;
@end
@implementation MetricsNetworkClientManager {
// Set of page load time objects created. Beyond deallocation and
// creation, should only be accessed on the IO thread.
base::scoped_nsobject<NSMutableSet> _pageLoadTimes;
// Current URL being loaded by the tab that owns this object. Only accessible
// on the IO thread.
GURL _pageURL;
}
- (instancetype)init {
if ((self = [super init])) {
_pageLoadTimes.reset([[NSMutableSet set] retain]);
}
return self;
}
- (Class)clientClass {
return [MetricsNetworkClient class];
}
#pragma mark CRWForwardingNetworkClientFactory methods
- (CRNForwardingNetworkClient*)clientHandlingRequest:
(const net::URLRequest&)request {
return [[[MetricsNetworkClient alloc] initWithManager:self] autorelease];
}
#pragma mark - public UI-thread methods
- (void)pageLoadStarted:(GURL)url {
DCHECK_CURRENTLY_ON(web::WebThread::UI);
web::WebThread::PostTask(web::WebThread::IO, FROM_HERE, base::BindBlock(^{
[self handlePageLoadStarted:url];
}));
}
- (void)pageLoadCompleted {
DCHECK_CURRENTLY_ON(web::WebThread::UI);
web::WebThread::PostTask(web::WebThread::IO, FROM_HERE, base::BindBlock(^{
[self handlePageLoadCompleted];
}));
}
#pragma mark - public IO-thread methods
- (PageLoadTimeRecord*)recordForPageLoad:(const GURL&)url
time:(base::TimeTicks)time {
DCHECK_CURRENTLY_ON(web::WebThread::IO);
base::scoped_nsobject<PageLoadTimeRecord> plt;
if (!_pageURL.spec().empty() && url == _pageURL) {
plt.reset([[PageLoadTimeRecord alloc] initWithURL:url time:time]);
[_pageLoadTimes addObject:plt];
}
return plt.get();
}
#pragma mark - IO-thread handlers for UI thread methods.
- (void)handlePageLoadStarted:(const GURL&)url {
DCHECK_CURRENTLY_ON(web::WebThread::IO);
[_pageLoadTimes removeAllObjects];
_pageURL = url;
}
- (void)handlePageLoadCompleted {
DCHECK_CURRENTLY_ON(web::WebThread::IO);
for (PageLoadTimeRecord* plt in _pageLoadTimes.get()) {
if (plt.url == _pageURL && !plt.alreadyCounted) {
plt.alreadyCounted = YES;
base::TimeDelta elapsed = base::TimeTicks::Now() - plt.creationTime;
if (plt.dataProxyUsed) {
UMA_HISTOGRAM_MEDIUM_TIMES(
"Tabs.iOS_PostRedirectPLT_DataReductionProxy", elapsed);
} else {
UMA_HISTOGRAM_MEDIUM_TIMES("Tabs.iOS_PostRedirectPLT", elapsed);
}
break;
}
}
}
@end
|