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

Unified Diff: tools/telemetry/telemetry/core/backends/chrome/extension_backend.py

Issue 165693006: [Telemetry] Factor out common logic between inspector backend lists. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Update comments Created 6 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
Index: tools/telemetry/telemetry/core/backends/chrome/extension_backend.py
diff --git a/tools/telemetry/telemetry/core/backends/chrome/extension_backend.py b/tools/telemetry/telemetry/core/backends/chrome/extension_backend.py
new file mode 100644
index 0000000000000000000000000000000000000000..8e1535ae14c8685171736f9052c96118b8a40085
--- /dev/null
+++ b/tools/telemetry/telemetry/core/backends/chrome/extension_backend.py
@@ -0,0 +1,43 @@
+# Copyright 2013 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+import collections
+
+from telemetry.core import extension_page
+from telemetry.core.backends.chrome import inspector_backend_list
+
+
+class ExtensionBackendList(inspector_backend_list.InspectorBackendList):
+ """A dynamic sequence of extension_page.ExtensionPages."""
+
+ def __init__(self, browser_backend):
+ super(ExtensionBackendList, self).__init__(
+ browser_backend, backend_wrapper=extension_page.ExtensionPage)
+
+ def ShouldIncludeContext(self, context):
+ return context['url'].startswith('chrome-extension://')
+
+
+class ExtensionBackendDict(collections.Mapping):
+ """A dynamic mapping of extension_id to extension_page.ExtensionPages."""
+
+ def __init__(self, browser_backend):
+ self._extension_backend_list = ExtensionBackendList(browser_backend)
+
+ def __getitem__(self, extension_id):
+ for i, context_id in enumerate(self._extension_backend_list):
+ if self.ContextIdToExtensionId(context_id) == extension_id:
+ return self._extension_backend_list[i]
+ raise KeyError('Cannot find an extension with id=%s' % extension_id)
+
+ def __iter__(self):
+ for context_id in self._extension_backend_list:
+ yield self.ContextIdToExtensionId(context_id)
+
+ def __len__(self):
+ return len(self._extension_backend_list)
+
+ def ContextIdToExtensionId(self, context_id):
+ context = self._extension_backend_list.GetContextInfo(context_id)
+ return extension_page.UrlToExtensionId(context['url'])

Powered by Google App Engine
This is Rietveld 408576698