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

Unified Diff: chrome/common/extensions/docs/server2/api_data_source.py

Issue 437323003: Docserver: Factor SamplesModel out of SamplesDataSource (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 6 years, 4 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
« no previous file with comments | « no previous file | chrome/common/extensions/docs/server2/app.yaml » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/common/extensions/docs/server2/api_data_source.py
diff --git a/chrome/common/extensions/docs/server2/api_data_source.py b/chrome/common/extensions/docs/server2/api_data_source.py
index c57ecc54815266723657b01c57c01ea5c664003d..56fae41ece9d82df93367f6a5062a0474bd2c244 100644
--- a/chrome/common/extensions/docs/server2/api_data_source.py
+++ b/chrome/common/extensions/docs/server2/api_data_source.py
@@ -9,19 +9,7 @@ from file_system import FileNotFoundError
from future import Future, All
from jsc_view import JSCView, GetEventByNameFromEvents
from platform_util import GetPlatforms
-
-
-class _LazySamplesGetter(object):
- '''This class is needed so that an extensions API page does not have to fetch
- the apps samples page and vice versa.
- '''
-
- def __init__(self, api_name, samples):
- self._api_name = api_name
- self._samples = samples
-
- def get(self, key):
- return self._samples.FilterSamples(key, self._api_name)
+from samples_data_source import CreateSamplesView
class APIDataSource(DataSource):
@@ -43,7 +31,7 @@ class APIDataSource(DataSource):
# This caches the result of _LoadEventByName.
self._event_byname_futures = {}
- self._samples = server_instance.samples_data_source_factory.Create(request)
+ self._request = request
def _LoadEventByName(self, platform):
'''All events have some members in common. We source their description
@@ -84,9 +72,12 @@ class APIDataSource(DataSource):
# Parsing samples on the preview server takes seconds and doesn't add
# anything. Don't do it.
if not IsPreviewServer():
- jsc_view['samples'] = _LazySamplesGetter(
- jsc_view['name'],
- self._samples)
+ samples_model = self._platform_bundle.GetSamplesModel(platform)
+ # Creates an object that lazily gets samples.
+ jsc_view['samples'] = type('getter', (object,), {
+ 'get': lambda _, platform: CreateSamplesView(
+ samples_model.FilterSamples(jsc_view['name']), self._request)
+ })()
return jsc_view
return Future(callback=resolve)
« no previous file with comments | « no previous file | chrome/common/extensions/docs/server2/app.yaml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698