| 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.')
|
|
|