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

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

Issue 1240703003: Extension profile generator + benchmark for startup with profile. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 5 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
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
5 import json
6 import os
7 import tempfile
8 import zipfile
9
10 import page_sets
11 from profile_creators import fast_navigation_profile_extender
12 from catapult_base import cloud_storage
erikchen 2015/07/14 23:36:14 these imports should be alphabetically ordered.
sydli 2015/07/15 22:56:23 Done.
13
14 # Google Cloud Storage bucket and remote directory to download
15 # extensions from
erikchen 2015/07/14 23:36:14 missing a period.
sydli 2015/07/15 22:56:23 Done.
16 BUCKET_NAME = "chrome-partner-telemetry"
erikchen 2015/07/14 23:36:14 you shouldn't need to define this variable. Use th
sydli 2015/07/15 22:56:23 Done.
17 DEFAULT_REMOTE_DIR = "extension_set"
erikchen 2015/07/14 23:36:14 DEFAULT implies remote_dir can be changed by someo
sydli 2015/07/15 22:56:23 No, it shouldn't be able to. Changed the name.
18
19 class ExtensionProfileExtender(
20 fast_navigation_profile_extender.FastNavigationProfileExtender):
21 """Creates a small profile with many extensions """
22
23 def __init__(self, finder_options):
24 maximum_batch_size = 1
25 super(ExtensionProfileExtender, self).__init__(
26 finder_options, maximum_batch_size)
27 # Make browser navigate to blank page
28 self._page_set = page_sets.BlankPageSet()
29 urls = []
30 for story in self._page_set.stories:
31 urls.append(story.url)
32 self._navigation_urls = urls
erikchen 2015/07/14 23:36:14 It might not be simpler, but it makes more sense t
sydli 2015/07/15 22:56:23 Stuck with FastNav since it creates and destroys t
33
34 if not finder_options.browser_options.profile_dir:
35 finder_options.browser_options.profile_dir = tempfile.mkdtemp()
erikchen 2015/07/14 23:36:14 How do you prevent tempfile.mkdtemp() from leaking
sydli 2015/07/15 22:56:23 Didn't realize profile generator already creates s
36 finder_options.browser_options.disable_default_apps = False
erikchen 2015/07/14 23:36:14 I seem to recall that you also set a similar flag
sydli 2015/07/15 22:56:23 I set this here as well so the profile generator w
erikchen 2015/07/16 00:33:28 nope, you'll need it in both places.
37
38 # DL extensions from cloud & force-install extensions into profile.
39 profile_dir = finder_options.browser_options.profile_dir
40 local_extensions_dir = os.path.join(profile_dir, "External Extensions Crx")
erikchen 2015/07/14 23:36:14 Please don't use spaces in folder names.
sydli 2015/07/15 22:56:23 Done.
41 self._DownloadRemoteExtensions(
erikchen 2015/07/14 23:36:14 This logic should be called from ProfileExtender.R
sydli 2015/07/15 22:56:24 Done.
42 BUCKET_NAME,
43 DEFAULT_REMOTE_DIR,
44 local_extensions_dir)
45 self._LoadExtensions(local_extensions_dir, profile_dir)
46
47 def _DownloadRemoteExtensions(self, remote_bucket, remote_extensions_dir,
48 local_extensions_dir):
49 """ Downloads set of common extensions to disk. """
erikchen 2015/07/14 23:36:14 What exceptions can this function throw? Please do
sydli 2015/07/15 22:56:24 Should document errors that this function explicit
50 remote_crx_files = cloud_storage.List(
51 os.path.join(remote_bucket, remote_extensions_dir))
52 for crx_file in remote_crx_files:
53 if not crx_file.endswith(".crx"):
erikchen 2015/07/14 23:36:14 Should this ever happen? If it should never happen
sydli 2015/07/15 22:56:23 Deleted. Check here is redundant with check in _Lo
54 continue
erikchen 2015/07/14 23:36:14 2 space indentation
sydli 2015/07/15 22:56:23 Done.
55 remote_crx_path = os.path.join(remote_extensions_dir, crx_file)
56 local_crx_path = os.path.join(local_extensions_dir, crx_file)
57 cloud_storage.Get(remote_bucket, remote_crx_path, local_crx_path)
58
59 def _GetExtensionInfoFromCRX(self, crxfile): #TODO: integrity checks?
erikchen 2015/07/14 23:36:14 I wouldn't be too worried about integrity checks.
sydli 2015/07/15 22:56:23 Acknowledged.
60 """ Format CRX as expected """
61 crx_zip = zipfile.ZipFile(crxfile)
62 manifest_contents = crx_zip.read('manifest.json')
63 decoded_manifest = json.loads(manifest_contents)
64 crx_version = decoded_manifest['version']
65 extension_name = decoded_manifest['name']
66 return (crx_version, extension_name)
67
68 def _LoadExtensions(self, local_extensions_dir, profile_dir):
69 """ Loads extensions in _local_extensions_dir into finder_options """
erikchen 2015/07/14 23:36:14 what exceptions can this throw?
sydli 2015/07/15 22:56:23 Any File IO or if extension directory was malforme
70 ext_files = os.listdir(local_extensions_dir)
71 # IF MAC
erikchen 2015/07/14 23:36:14 It's okay to start off with this benchmark only ru
sydli 2015/07/15 22:56:23 Disabled the benchmark on all platforms except mac
72 external_ext_dir = os.path.join(profile_dir, "External Extensions")
73 os.makedirs(external_ext_dir)
74 for ext_file in ext_files:
75 if not ext_file.endswith('.crx'):
erikchen 2015/07/14 23:36:14 ditto - should this ever happen? maybe this should
sydli 2015/07/15 22:56:23 Should definitely never happen. I'll raise an exce
76 continue
77 ext_path = os.path.join(local_extensions_dir, ext_file)
78 (version, name) = self._GetExtensionInfoFromCRX(ext_path)
79 extension_info = {'external_crx': ext_path,
80 'external_version': version,
erikchen 2015/07/14 23:36:14 formatting of this dictionary - please see python
sydli 2015/07/15 22:56:24 Done.
81 '_comment': name}
82 ext_id = os.path.splitext(os.path.basename(ext_path))[0]
83 extension_json_path = os.path.join(external_ext_dir, "%s.json" % ext_id)
84 with open(extension_json_path, 'w') as f:
85 f.write(json.dumps(extension_info))
86
87 def GetUrlIterator(self):
88 """Superclass override."""
89 return iter(self._navigation_urls)
90
91 def ShouldExitAfterBatchNavigation(self):
92 """Superclass override."""
93 return False
94
95 def Run(self):
96 super(ExtensionProfileExtender, self).Run()
97
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698