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

Side by Side Diff: tools/perf/profile_creators/cookie_profile_extender.py

Issue 914253005: Telemetry: Create new profile creator large_profile_creator. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Comments from sullivan. Created 5 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 unified diff | Download patch
« no previous file with comments | « no previous file | tools/perf/profile_creators/cookie_profile_extender_unittest.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 os
6 import sqlite3
7
8 from profile_creators import fast_navigation_profile_extender
9 from profile_creators import profile_safe_url_list
10
11 class CookieProfileExtender(
12 fast_navigation_profile_extender.FastNavigationProfileExtender):
13 """This extender performs a large number of navigations (up to 500), with the
14 goal of filling out the cookie database.
15
16 By default, Chrome purges the cookie DB down to 3300 cookies. However, it
17 won't purge cookies accessed in the last month. This means the extender needs
18 to be careful not to create an artificially high number of cookies.
19 """
20 _COOKIE_DB_EXPECTED_SIZE = 3300
21
22 def __init__(self):
23 # The rate limiting factors are fetching network resources and executing
24 # javascript. There's not much to be done about the former, and having one
25 # tab per logical core appears close to optimum for the latter.
26 maximum_batch_size = multiprocessing.cpu_count()
27 super(CookieProfileExtender, self).__init__(maximum_batch_size)
28
29 # A list of urls that have not yet been navigated to. This list will shrink
30 # over time. Each navigation will add a diminishing number of new cookies,
31 # since there's a high probability that the cookie is already present. If
32 # the cookie DB isn't full by 500 navigations, just give up.
33 self._navigation_urls = profile_safe_url_list.GetShuffledSafeUrls()[0:500]
34
35 def GetUrlIterator(self):
36 """Superclass override."""
37 return iter(self._navigation_urls)
38
39 def ShouldExitAfterBatchNavigation(self):
40 """Superclass override."""
41 return self._IsCookieDBFull()
42
43 @staticmethod
44 def _CookieCountInDB(db_path):
45 """The number of cookies in the db at |db_path|."""
46 connection = sqlite3.connect(db_path)
47 try:
48 cursor = connection.cursor()
49 cursor.execute("select count(*) from cookies")
50 cookie_count = cursor.fetchone()[0]
51 except:
52 raise
53 finally:
54 connection.close()
55 return cookie_count
56
57 def _IsCookieDBFull(self):
58 """Chrome does not immediately flush cookies to its database. It's possible
59 that this method will return a false negative."""
60 cookie_db_path = os.path.join(self.profile_path, "Default", "Cookies")
61 try:
62 cookie_count = CookieProfileExtender._CookieCountInDB(cookie_db_path)
63 except sqlite3.OperationalError:
64 # There will occasionally be contention for the SQLite database. This
65 # shouldn't happen often, so ignore the errors.
66 return False
67
68 return cookie_count > CookieProfileExtender._COOKIE_DB_EXPECTED_SIZE
OLDNEW
« no previous file with comments | « no previous file | tools/perf/profile_creators/cookie_profile_extender_unittest.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698