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

Side by Side Diff: chrome/common/extensions/docs/server2/samples_data_source.py

Issue 344453003: Docserver: separate models for apps and extensions (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase/Add comment Created 6 years, 6 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
1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 import json 5 import json
6 import logging 6 import logging
7 import posixpath 7 import posixpath
8 import re 8 import re
9 import traceback 9 import traceback
10 10
11 from extensions_paths import EXAMPLES 11 from extensions_paths import EXAMPLES
12 import third_party.json_schema_compiler.json_comment_eater as json_comment_eater 12 import third_party.json_schema_compiler.json_comment_eater as json_comment_eater
13 import url_constants 13 import url_constants
14 14
15 15
16 _DEFAULT_ICON_PATH = 'images/sample-default-icon.png' 16 _DEFAULT_ICON_PATH = 'images/sample-default-icon.png'
17 17
18 18
19 class SamplesDataSource(object): 19 class SamplesDataSource(object):
20 '''Constructs a list of samples and their respective files and api calls. 20 '''Constructs a list of samples and their respective files and api calls.
21 ''' 21 '''
22 class Factory(object): 22 class Factory(object):
23 '''A factory to create SamplesDataSource instances bound to individual 23 '''A factory to create SamplesDataSource instances bound to individual
24 Requests. 24 Requests.
25 ''' 25 '''
26 def __init__(self, 26 def __init__(self,
27 host_file_system, 27 host_file_system,
28 app_samples_file_system, 28 app_samples_file_system,
29 compiled_fs_factory, 29 compiled_fs_factory,
30 ref_resolver, 30 platform_bundle,
31 base_path): 31 base_path):
32 self._host_file_system = host_file_system 32 self._host_file_system = host_file_system
33 self._app_samples_file_system = app_samples_file_system 33 self._app_samples_file_system = app_samples_file_system
34 self._ref_resolver = ref_resolver 34 self._platform_bundle = platform_bundle
35 self._base_path = base_path 35 self._base_path = base_path
36 self._extensions_cache = compiled_fs_factory.Create( 36 self._extensions_cache = compiled_fs_factory.Create(
37 host_file_system, 37 host_file_system,
38 self._MakeSamplesList, 38 self._MakeSamplesList,
39 SamplesDataSource, 39 SamplesDataSource,
40 category='extensions') 40 category='extensions')
41 self._extensions_text_cache = compiled_fs_factory.ForUnicode( 41 self._extensions_text_cache = compiled_fs_factory.ForUnicode(
42 host_file_system) 42 host_file_system)
43 self._apps_cache = compiled_fs_factory.Create( 43 self._apps_cache = compiled_fs_factory.Create(
44 app_samples_file_system, 44 app_samples_file_system,
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 api_calls = [] 129 api_calls = []
130 for item in sorted(api_items): 130 for item in sorted(api_items):
131 if len(item.split('.')) < 3: 131 if len(item.split('.')) < 3:
132 continue 132 continue
133 if item.endswith('.removeListener') or item.endswith('.hasListener'): 133 if item.endswith('.removeListener') or item.endswith('.hasListener'):
134 continue 134 continue
135 if item.endswith('.addListener'): 135 if item.endswith('.addListener'):
136 item = item[:-len('.addListener')] 136 item = item[:-len('.addListener')]
137 if item.startswith('chrome.'): 137 if item.startswith('chrome.'):
138 item = item[len('chrome.'):] 138 item = item[len('chrome.'):]
139 ref_data = self._ref_resolver.GetLink(item) 139 ref_data = self._platform_bundle.GetReferenceResolver(
140 'apps' if is_apps else 'extensions').GetLink(item)
140 # TODO(kalman): What about references like chrome.storage.sync.get? 141 # TODO(kalman): What about references like chrome.storage.sync.get?
141 # That should link to either chrome.storage.sync or 142 # That should link to either chrome.storage.sync or
142 # chrome.storage.StorageArea.get (or probably both). 143 # chrome.storage.StorageArea.get (or probably both).
143 # TODO(kalman): Filter out API-only references? This can happen when 144 # TODO(kalman): Filter out API-only references? This can happen when
144 # the API namespace is assigned to a variable, but it's very hard to 145 # the API namespace is assigned to a variable, but it's very hard to
145 # to disambiguate. 146 # to disambiguate.
146 if ref_data is None: 147 if ref_data is None:
147 continue 148 continue
148 api_calls.append({ 149 api_calls.append({
149 'name': ref_data['text'], 150 'name': ref_data['text'],
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
243 else: 244 else:
244 dict_['id'] = self._GetSampleId(name) 245 dict_['id'] = self._GetSampleId(name)
245 return_list.append(dict_) 246 return_list.append(dict_)
246 return return_list 247 return return_list
247 248
248 def get(self, key): 249 def get(self, key):
249 return { 250 return {
250 'apps': lambda: self._CreateSamplesDict('apps'), 251 'apps': lambda: self._CreateSamplesDict('apps'),
251 'extensions': lambda: self._CreateSamplesDict('extensions') 252 'extensions': lambda: self._CreateSamplesDict('extensions')
252 }.get(key, lambda: {})() 253 }.get(key, lambda: {})()
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698