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

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

Issue 10834329: Extension docs server: many changes to bring down the latency of the server, (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 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 unified diff | Download patch | Annotate | Revision Log
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 re 7 import re
8 import time
8 9
9 import third_party.json_schema_compiler.json_comment_eater as json_comment_eater 10 import third_party.json_schema_compiler.json_comment_eater as json_comment_eater
10 import third_party.json_schema_compiler.model as model 11 import third_party.json_schema_compiler.model as model
11 import url_constants 12 import url_constants
12 13
13 DEFAULT_ICON_PATH = '/images/sample-default-icon.png' 14 DEFAULT_ICON_PATH = '/images/sample-default-icon.png'
14 15
15 class SamplesDataSource(object): 16 class SamplesDataSource(object):
16 """Constructs a list of samples and their respective files and api calls. 17 """Constructs a list of samples and their respective files and api calls.
17 """ 18 """
(...skipping 14 matching lines...) Expand all
32 self._static_path = ((('/' + branch) if branch != 'local' else '') + 33 self._static_path = ((('/' + branch) if branch != 'local' else '') +
33 '/static') 34 '/static')
34 self._extensions_cache = cache_builder.build(self._MakeSamplesList) 35 self._extensions_cache = cache_builder.build(self._MakeSamplesList)
35 self._apps_cache = github_cache_builder.build( 36 self._apps_cache = github_cache_builder.build(
36 lambda x: self._MakeSamplesList(x, is_apps=True)) 37 lambda x: self._MakeSamplesList(x, is_apps=True))
37 self._samples_path = samples_path 38 self._samples_path = samples_path
38 39
39 def Create(self, request): 40 def Create(self, request):
40 """Returns a new SamplesDataSource bound to |request|. 41 """Returns a new SamplesDataSource bound to |request|.
41 """ 42 """
42 return SamplesDataSource(self._extensions_cache, 43 return SamplesDataSource(self._extensions_cache.ScopeToRequest(),
43 self._apps_cache, 44 self._apps_cache.ScopeToRequest(),
44 self._samples_path, 45 self._samples_path,
45 request) 46 request)
46 47
47 def _GetApiItems(self, js_file): 48 def _GetApiItems(self, js_file):
48 return set(re.findall('(chrome\.[a-zA-Z0-9\.]+)', js_file)) 49 return set(re.findall('(chrome\.[a-zA-Z0-9\.]+)', js_file))
49 50
50 def _MakeApiLink(self, prefix, item): 51 def _MakeApiLink(self, prefix, item):
51 api, name = item.replace('chrome.', '').split('.', 1) 52 api, name = item.replace('chrome.', '').split('.', 1)
52 return api + '.html#' + prefix + '-' + name 53 return api + '.html#' + prefix + '-' + name
53 54
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 sample_data = dict_ 197 sample_data = dict_
197 return_list.append(sample_data) 198 return_list.append(sample_data)
198 else: 199 else:
199 return_list.append(dict_) 200 return_list.append(dict_)
200 return return_list 201 return return_list
201 202
202 def __getitem__(self, key): 203 def __getitem__(self, key):
203 return self.get(key) 204 return self.get(key)
204 205
205 def get(self, key): 206 def get(self, key):
207 start_time = time.time()
208 try:
209 return self._do_get(key)
210 finally:
211 logging.info("SamplesDataSource: %sms", (time.time() - start_time) * 1000)
212
213 def _do_get(self, key):
206 return { 214 return {
207 'apps': lambda: self._CreateSamplesDict('apps'), 215 'apps': lambda: self._CreateSamplesDict('apps'),
208 'extensions': lambda: self._CreateSamplesDict('extensions') 216 'extensions': lambda: self._CreateSamplesDict('extensions')
209 }.get(key, lambda: {})() 217 }.get(key, lambda: {})()
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698