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

Unified Diff: tools/android/loading/chrome_cache.py

Issue 1737103002: sandwich: Implements filter-cache sub-command. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@i10
Patch Set: Updates loading_trace_paths's help Created 4 years, 10 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 | « no previous file | tools/android/loading/sandwich.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/android/loading/chrome_cache.py
diff --git a/tools/android/loading/chrome_cache.py b/tools/android/loading/chrome_cache.py
index d6d65a265690fdc4a2fa9fea4a3238a4dd7511e6..40d15bb7dd07f78aa4bdb5f556e26e7b16c039e5 100644
--- a/tools/android/loading/chrome_cache.py
+++ b/tools/android/loading/chrome_cache.py
@@ -8,6 +8,7 @@
from datetime import datetime
import json
import os
+import shutil
import subprocess
import sys
import tempfile
@@ -278,6 +279,32 @@ class CacheBackend(object):
return stdout_data
+def ApplyUrlWhitelistToCacheArchive(cache_archive_path,
+ whitelisted_urls,
+ output_cache_archive_path):
+ """Generate a new cache archive containing only whitelisted urls.
+
+ Args:
+ cache_archive_path: Path of the cache archive to apply the white listing.
+ whitelisted_urls: Set of url to keep in cache.
+ output_cache_archive_path: Destination path of cache archive containing only
+ white-listed urls.
+ """
+ cache_temp_directory = tempfile.mkdtemp(suffix='.cache')
+ try:
+ UnzipDirectoryContent(cache_archive_path, cache_temp_directory)
+ backend = CacheBackend(cache_temp_directory, 'simple')
+ cached_urls = backend.ListKeys()
+ for cached_url in cached_urls:
+ if cached_url not in whitelisted_urls:
+ backend.DeleteKey(cached_url)
+ for cached_url in backend.ListKeys():
+ assert cached_url in whitelisted_urls
+ ZipDirectoryContent(cache_temp_directory, output_cache_archive_path)
+ finally:
+ shutil.rmtree(cache_temp_directory)
+
+
if __name__ == '__main__':
import argparse
parser = argparse.ArgumentParser(description='Tests cache back-end.')
« no previous file with comments | « no previous file | tools/android/loading/sandwich.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698