Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(276)

Side by Side Diff: tools/android/loading/request_track.py

Issue 1610273002: Upgrade loading_model to use the new request_track and loading_trace. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 # Copyright (c) 2016 The Chromium Authors. All rights reserved. 1 # Copyright (c) 2016 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 """The request data track. 5 """The request data track.
6 6
7 When executed, parses a JSON dump of DevTools messages. 7 When executed, parses a JSON dump of DevTools messages.
8 """ 8 """
9 9
10 import collections 10 import collections
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 """Returns the content type, or None.""" 110 """Returns the content type, or None."""
111 content_type = self.response_headers.get('Content-Type', None) 111 content_type = self.response_headers.get('Content-Type', None)
112 if not content_type or ';' not in content_type: 112 if not content_type or ';' not in content_type:
113 return content_type 113 return content_type
114 else: 114 else:
115 return content_type[:content_type.index(';')] 115 return content_type[:content_type.index(';')]
116 116
117 def IsDataRequest(self): 117 def IsDataRequest(self):
118 return self.protocol == 'data' 118 return self.protocol == 'data'
119 119
120 # For testing. 120 def MaxAge(self):
121 """Returns the max-age of a resource, or -1."""
122 # TODO(lizeb): Handle the "Expires" header as well.
123 cache_control = {}
124 if not self.response_headers:
125 return -1
126 cache_control_str = self.response_headers.get('Cache-Control', None)
127 if cache_control_str is not None:
128 directives = [s.strip() for s in cache_control_str.split(',')]
129 for directive in directives:
130 parts = [s.strip() for s in directive.split('=')]
131 if len(parts) == 1:
132 cache_control[parts[0]] = True
133 else:
134 cache_control[parts[0]] = parts[1]
135 if (u'no-store' in cache_control
136 or u'no-cache' in cache_control
137 or len(cache_control) == 0):
138 return -1
139 if 'max-age' in cache_control:
140 return int(cache_control['max-age'])
141 return -1
142
121 def __eq__(self, o): 143 def __eq__(self, o):
122 return self.__dict__ == o.__dict__ 144 return self.__dict__ == o.__dict__
123 145
146 def __hash__(self):
147 return hash(self.request_id)
148
124 149
125 class RequestTrack(devtools_monitor.Track): 150 class RequestTrack(devtools_monitor.Track):
126 """Aggregates request data.""" 151 """Aggregates request data."""
127 REDIRECT_SUFFIX = '.redirect' 152 REDIRECT_SUFFIX = '.redirect'
128 # Request status 153 # Request status
129 _STATUS_SENT = 0 154 _STATUS_SENT = 0
130 _STATUS_RESPONSE = 1 155 _STATUS_RESPONSE = 1
131 _STATUS_DATA = 2 156 _STATUS_DATA = 2
132 _STATUS_FINISHED = 3 157 _STATUS_FINISHED = 3
133 _STATUS_FAILED = 4 158 _STATUS_FAILED = 4
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
305 330
306 331
307 if __name__ == '__main__': 332 if __name__ == '__main__':
308 import json 333 import json
309 import sys 334 import sys
310 events = json.load(open(sys.argv[1], 'r')) 335 events = json.load(open(sys.argv[1], 'r'))
311 request_track = RequestTrack(None) 336 request_track = RequestTrack(None)
312 for event in events: 337 for event in events:
313 event_method = event['method'] 338 event_method = event['method']
314 request_track.Handle(event_method, event) 339 request_track.Handle(event_method, event)
OLDNEW
« no previous file with comments | « tools/android/loading/loading_model_unittest.py ('k') | tools/android/loading/request_track_unittest.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698