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

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

Issue 10829348: Extensions Docs Server: Large performance increase (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_data_source_test.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
7 import os 6 import os
8 7
9 from file_system import FileNotFoundError 8 from file_system import FileNotFoundError
9 import file_system_cache as fs_cache
10 from handlebar_dict_generator import HandlebarDictGenerator 10 from handlebar_dict_generator import HandlebarDictGenerator
11 import third_party.json_schema_compiler.json_comment_eater as json_comment_eater 11 import third_party.json_schema_compiler.json_comment_eater as json_comment_eater
12 import third_party.json_schema_compiler.model as model 12 import third_party.json_schema_compiler.model as model
13 import third_party.json_schema_compiler.idl_schema as idl_schema 13 import third_party.json_schema_compiler.idl_schema as idl_schema
14 import third_party.json_schema_compiler.idl_parser as idl_parser 14 import third_party.json_schema_compiler.idl_parser as idl_parser
15 15
16 class _LazySamplesGetter(object): 16 class _LazySamplesGetter(object):
17 """This class is needed so that an extensions API page does not have to fetch 17 """This class is needed so that an extensions API page does not have to fetch
18 the apps samples page and vice versa. 18 the apps samples page and vice versa.
19 """ 19 """
20 def __init__(self, api_name, samples): 20 def __init__(self, api_name, samples):
21 self._api_name = api_name 21 self._api_name = api_name
22 self._samples = samples 22 self._samples = samples
23 23
24 def get(self, key): 24 def get(self, key):
25 return self._samples.FilterSamples(key, self._api_name) 25 return self._samples.FilterSamples(key, self._api_name)
26 26
27 class APIDataSource(object): 27 class APIDataSource(object):
28 """This class fetches and loads JSON APIs from the FileSystem passed in with 28 """This class fetches and loads JSON APIs from the FileSystem passed in with
29 |cache_builder|, so the APIs can be plugged into templates. 29 |cache_builder|, so the APIs can be plugged into templates.
30 """ 30 """
31 class Factory(object): 31 class Factory(object):
32 def __init__(self, cache_builder, base_path, samples_factory): 32 def __init__(self, cache_builder, base_path, samples_factory):
33 self._permissions_cache = cache_builder.build(self._LoadPermissions) 33 self._permissions_cache = cache_builder.build(self._LoadPermissions,
34 self._json_cache = cache_builder.build(self._LoadJsonAPI) 34 fs_cache.PERMS)
35 self._idl_cache = cache_builder.build(self._LoadIdlAPI) 35 self._json_cache = cache_builder.build(self._LoadJsonAPI,
36 fs_cache.JSON)
37 self._idl_cache = cache_builder.build(self._LoadIdlAPI,
38 fs_cache.IDL)
36 self._samples_factory = samples_factory 39 self._samples_factory = samples_factory
37 self._base_path = base_path 40 self._base_path = base_path
38 41
39 def Create(self, request): 42 def Create(self, request):
40 return APIDataSource(self._permissions_cache, 43 return APIDataSource(self._permissions_cache,
41 self._json_cache, 44 self._json_cache,
42 self._idl_cache, 45 self._idl_cache,
43 self._base_path, 46 self._base_path,
44 self._samples_factory.Create(request)) 47 self._samples_factory.Create(request))
45 48
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 return self._GenerateHandlebarContext( 107 return self._GenerateHandlebarContext(
105 self._json_cache.GetFromFile(self._base_path + '/' + json_path), 108 self._json_cache.GetFromFile(self._base_path + '/' + json_path),
106 path) 109 path)
107 except FileNotFoundError: 110 except FileNotFoundError:
108 try: 111 try:
109 return self._GenerateHandlebarContext( 112 return self._GenerateHandlebarContext(
110 self._idl_cache.GetFromFile(self._base_path + '/' + idl_path), 113 self._idl_cache.GetFromFile(self._base_path + '/' + idl_path),
111 path) 114 path)
112 except FileNotFoundError: 115 except FileNotFoundError:
113 raise 116 raise
OLDNEW
« no previous file with comments | « no previous file | chrome/common/extensions/docs/server2/api_data_source_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698