Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 # Copyright 2015 The Chromium Authors. All rights reserved. | |
| 2 # Use of this source code is governed by a BSD-style license that can be | |
| 3 # found in the LICENSE file. | |
| 4 import multiprocessing | |
| 5 import tempfile | |
| 6 import os | |
| 7 | |
| 8 from profile_creators import fast_navigation_profile_extender | |
| 9 | |
| 10 | |
| 11 class HistoryProfileExtender( | |
| 12 fast_navigation_profile_extender.FastNavigationProfileExtender): | |
| 13 """This extender navigates Chrome to a large number of URIs pointing to local | |
| 14 files. It continues running until the history DB becomes full.""" | |
| 15 _HISTORY_DB_MAX_SIZE_IN_MB = 10 | |
| 16 | |
| 17 def __init__(self): | |
| 18 # The rate limiting factors are the speed of page navigation, and the speed | |
| 19 # of python bindings. The former is larger than the latter, so having a | |
| 20 # large batch size skews the amortized average time per page load towards | |
| 21 # the latter. | |
| 22 batch_size = multiprocessing.cpu_count() * 2 | |
| 23 super(HistoryProfileExtender, self).__init__(batch_size) | |
| 24 | |
| 25 # A list of paths of temporary files. The instance is responsible for | |
| 26 # making sure that the files are deleted before they are removed from this | |
| 27 # list. | |
| 28 self._file_paths = [] | |
| 29 | |
| 30 def GetUrlsToNavigate(self, maximum_batch_size): | |
| 31 """Superclass override. | |
| 32 | |
| 33 This method makes temporary files. It returns URIs to these files, which | |
| 34 allows Chrome to populate its history database by navigating to these files | |
| 35 on the local file system. | |
| 36 | |
| 37 This method fills the member |_file_paths| with the absolute paths of the | |
| 38 temporary files, which must be removed at a later point in time. | |
| 39 """ | |
| 40 urls = [] | |
| 41 for _ in range(maximum_batch_size): | |
| 42 suffix = "reallylongsuffixintendedtoartificiallyincreasethelengthoftheurl" | |
|
nednguyen
2015/02/19 00:33:32
Can you add some comment about why we want a long
erikchen
2015/02/19 01:56:03
Done.
| |
| 43 handle, path = tempfile.mkstemp(suffix=suffix) | |
| 44 os.close(handle) | |
| 45 self._file_paths.append(path) | |
| 46 | |
| 47 file_url = "file://" + path | |
| 48 urls.append(file_url) | |
| 49 | |
| 50 return urls | |
| 51 | |
| 52 def ShouldExitAfterBatchNavigation(self): | |
| 53 """Superclass override.""" | |
| 54 return self._IsHistoryDBAtMaxSize() | |
| 55 | |
| 56 def TearDown(self): | |
| 57 """Superclass override.""" | |
| 58 super(HistoryProfileExtender, self).TearDown() | |
| 59 for path in self._file_paths: | |
| 60 os.remove(path) | |
| 61 self._file_paths = [] | |
| 62 | |
| 63 def CleanUpAfterBatchNavigation(self): | |
| 64 """Superclass override.""" | |
| 65 for path in self._file_paths: | |
| 66 os.remove(path) | |
|
nednguyen
2015/02/19 00:33:32
You can move TemporaryFile which is deleted on clo
erikchen
2015/02/19 01:56:03
For a full explanation, see my earlier response. I
| |
| 67 self._file_paths = [] | |
| 68 | |
| 69 def _IsHistoryDBAtMaxSize(self): | |
| 70 """Whether the history DB has reached its maximum size.""" | |
| 71 history_db_path = os.path.join(self.profile_path, "Default", "History") | |
| 72 stat_info = os.stat(history_db_path) | |
| 73 size = stat_info.st_size | |
| 74 | |
| 75 max_size_threshold = 0.95 | |
| 76 max_size = ((10**6 * HistoryProfileExtender._HISTORY_DB_MAX_SIZE_IN_MB) * | |
|
nednguyen
2015/02/19 00:33:32
Technically, this should be 2 ** 20?
erikchen
2015/02/19 01:56:03
Done.
| |
| 77 max_size_threshold) | |
| 78 return size > max_size | |
| OLD | NEW |