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

Unified 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 side-by-side diff with in-line comments
Download patch
« 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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/android/loading/request_track.py
diff --git a/tools/android/loading/request_track.py b/tools/android/loading/request_track.py
index f3b5c9c1974cf07953510d496b1effea140bbe4b..e7338abbad866ec3fe583186516d2fb91b4dc4a6 100644
--- a/tools/android/loading/request_track.py
+++ b/tools/android/loading/request_track.py
@@ -117,10 +117,35 @@ class Request(object):
def IsDataRequest(self):
return self.protocol == 'data'
- # For testing.
+ def MaxAge(self):
+ """Returns the max-age of a resource, or -1."""
+ # TODO(lizeb): Handle the "Expires" header as well.
+ cache_control = {}
+ if not self.response_headers:
+ return -1
+ cache_control_str = self.response_headers.get('Cache-Control', None)
+ if cache_control_str is not None:
+ directives = [s.strip() for s in cache_control_str.split(',')]
+ for directive in directives:
+ parts = [s.strip() for s in directive.split('=')]
+ if len(parts) == 1:
+ cache_control[parts[0]] = True
+ else:
+ cache_control[parts[0]] = parts[1]
+ if (u'no-store' in cache_control
+ or u'no-cache' in cache_control
+ or len(cache_control) == 0):
+ return -1
+ if 'max-age' in cache_control:
+ return int(cache_control['max-age'])
+ return -1
+
def __eq__(self, o):
return self.__dict__ == o.__dict__
+ def __hash__(self):
+ return hash(self.request_id)
+
class RequestTrack(devtools_monitor.Track):
"""Aggregates request data."""
« 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