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

Side by Side Diff: chrome/common/extensions/docs/server2/api_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
« no previous file with comments | « no previous file | chrome/common/extensions/docs/server2/api_list_data_source.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 os 7 import os
8 import time
8 9
9 from file_system import FileNotFoundError 10 from file_system import FileNotFoundError
10 from handlebar_dict_generator import HandlebarDictGenerator 11 from handlebar_dict_generator import HandlebarDictGenerator
11 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
12 import third_party.json_schema_compiler.model as model 13 import third_party.json_schema_compiler.model as model
13 import third_party.json_schema_compiler.idl_schema as idl_schema 14 import third_party.json_schema_compiler.idl_schema as idl_schema
14 import third_party.json_schema_compiler.idl_parser as idl_parser 15 import third_party.json_schema_compiler.idl_parser as idl_parser
15 16
16 class _LazySamplesGetter(object): 17 class _LazySamplesGetter(object):
17 """This class is needed so that an extensions API page does not have to fetch 18 """This class is needed so that an extensions API page does not have to fetch
(...skipping 12 matching lines...) Expand all
30 """ 31 """
31 class Factory(object): 32 class Factory(object):
32 def __init__(self, cache_builder, base_path, samples_factory): 33 def __init__(self, cache_builder, base_path, samples_factory):
33 self._permissions_cache = cache_builder.build(self._LoadPermissions) 34 self._permissions_cache = cache_builder.build(self._LoadPermissions)
34 self._json_cache = cache_builder.build(self._LoadJsonAPI) 35 self._json_cache = cache_builder.build(self._LoadJsonAPI)
35 self._idl_cache = cache_builder.build(self._LoadIdlAPI) 36 self._idl_cache = cache_builder.build(self._LoadIdlAPI)
36 self._samples_factory = samples_factory 37 self._samples_factory = samples_factory
37 self._base_path = base_path 38 self._base_path = base_path
38 39
39 def Create(self, request): 40 def Create(self, request):
40 return APIDataSource(self._permissions_cache, 41 return APIDataSource(self._permissions_cache.ScopeToRequest(),
41 self._json_cache, 42 self._json_cache.ScopeToRequest(),
42 self._idl_cache, 43 self._idl_cache.ScopeToRequest(),
43 self._base_path, 44 self._base_path,
44 self._samples_factory.Create(request)) 45 self._samples_factory.Create(request))
45 46
46 def _LoadPermissions(self, json_str): 47 def _LoadPermissions(self, json_str):
47 return json.loads(json_comment_eater.Nom(json_str)) 48 return json.loads(json_comment_eater.Nom(json_str))
48 49
49 def _LoadJsonAPI(self, api): 50 def _LoadJsonAPI(self, api):
50 return HandlebarDictGenerator(json.loads(json_comment_eater.Nom(api))[0]) 51 return HandlebarDictGenerator(json.loads(json_comment_eater.Nom(api))[0])
51 52
52 def _LoadIdlAPI(self, api): 53 def _LoadIdlAPI(self, api):
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 # http://crbug.com/142011. 90 # http://crbug.com/142011.
90 'samples': None # _LazySamplesGetter(path, self._samples) 91 'samples': None # _LazySamplesGetter(path, self._samples)
91 } 92 }
92 return_dict.update(handlebar.Generate()) 93 return_dict.update(handlebar.Generate())
93 return return_dict 94 return return_dict
94 95
95 def __getitem__(self, key): 96 def __getitem__(self, key):
96 return self.get(key) 97 return self.get(key)
97 98
98 def get(self, key): 99 def get(self, key):
100 start_time = time.time()
101 try:
102 return self._do_get(key)
103 finally:
104 logging.info("ApiDataSource: %sms", (time.time() - start_time) * 1000)
105
106 def _do_get(self, key):
99 path, ext = os.path.splitext(key) 107 path, ext = os.path.splitext(key)
100 unix_name = model.UnixName(path) 108 unix_name = model.UnixName(path)
101 json_path = unix_name + '.json' 109 json_path = unix_name + '.json'
102 idl_path = unix_name + '.idl' 110 idl_path = unix_name + '.idl'
103 try: 111 try:
104 return self._GenerateHandlebarContext( 112 return self._GenerateHandlebarContext(
105 self._json_cache.GetFromFile(self._base_path + '/' + json_path), 113 self._json_cache.GetFromFile(self._base_path + '/' + json_path),
106 path) 114 path)
107 except FileNotFoundError: 115 except FileNotFoundError:
108 try: 116 try:
109 return self._GenerateHandlebarContext( 117 return self._GenerateHandlebarContext(
110 self._idl_cache.GetFromFile(self._base_path + '/' + idl_path), 118 self._idl_cache.GetFromFile(self._base_path + '/' + idl_path),
111 path) 119 path)
112 except FileNotFoundError: 120 except FileNotFoundError:
113 raise 121 raise
OLDNEW
« no previous file with comments | « no previous file | chrome/common/extensions/docs/server2/api_list_data_source.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698