OLD | NEW |
---|---|
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 from data_source import DataSource | 5 from data_source import DataSource |
6 from future import Future | 6 from future import Future |
7 from operator import itemgetter | 7 from operator import itemgetter |
8 from platform_util import GetPlatforms | 8 from platform_util import GetPlatforms |
9 | 9 |
10 from docs_server_utils import MarkFirstAndLast, MarkLast | 10 from docs_server_utils import MarkFirstAndLast, MarkLast |
(...skipping 14 matching lines...) Expand all Loading... | |
25 values are present. | 25 values are present. |
26 """ | 26 """ |
27 def __init__(self, server_instance, _): | 27 def __init__(self, server_instance, _): |
28 self._platform_bundle = server_instance.platform_bundle | 28 self._platform_bundle = server_instance.platform_bundle |
29 self._object_store = server_instance.object_store_creator.Create( | 29 self._object_store = server_instance.object_store_creator.Create( |
30 # Update the model when the API or Features model updates. | 30 # Update the model when the API or Features model updates. |
31 APIListDataSource, category=self._platform_bundle.GetIdentity()) | 31 APIListDataSource, category=self._platform_bundle.GetIdentity()) |
32 | 32 |
33 def _GenerateAPIDict(self): | 33 def _GenerateAPIDict(self): |
34 def make_list_for_content_scripts(): | 34 def make_list_for_content_scripts(): |
35 content_script_apis = self._platform_bundle.GetAPIModels( | 35 def convert_to_list(content_script_apis): |
36 'extensions').GetContentScriptAPIs().Get() | 36 content_script_apis_list = [csa.__dict__ for api_name, csa |
37 content_script_apis_list = [csa.__dict__ for api_name, csa | 37 in content_script_apis.iteritems() |
38 in content_script_apis.iteritems() | 38 if self._platform_bundle.GetAPICategorizer( |
39 if self._platform_bundle.GetAPICategorizer( | 39 'extensions').IsDocumented(api_name)] |
40 'extensions').IsDocumented(api_name)] | 40 content_script_apis_list.sort(key=itemgetter('name')) |
41 for csa in content_script_apis_list: | |
42 restricted_nodes = csa['restrictedTo'] | |
43 if restricted_nodes: | |
44 restricted_nodes.sort(key=itemgetter('node')) | |
45 MarkFirstAndLast(restricted_nodes) | |
46 else: | |
47 del csa['restrictedTo'] | |
48 return content_script_apis_list | |
41 | 49 |
42 content_script_apis_list.sort(key=itemgetter('name')) | 50 return (self._platform_bundle.GetAPIModels('extensions') |
43 for csa in content_script_apis_list: | 51 .GetContentScriptAPIs() |
44 restricted_nodes = csa['restrictedTo'] | 52 .Then(convert_to_list)) |
45 if restricted_nodes: | |
46 restricted_nodes.sort(key=itemgetter('node')) | |
47 MarkFirstAndLast(restricted_nodes) | |
48 else: | |
49 del csa['restrictedTo'] | |
50 return content_script_apis_list | |
51 | 53 |
52 def make_dict_for_platform(platform): | 54 def make_dict_for_platform(platform): |
53 platform_dict = { | 55 platform_dict = { |
54 'chrome': {'stable': [], 'beta': [], 'dev': [], 'trunk': []}, | 56 'chrome': {'stable': [], 'beta': [], 'dev': [], 'trunk': []}, |
55 } | 57 } |
56 private_apis = [] | 58 private_apis = [] |
57 experimental_apis = [] | 59 experimental_apis = [] |
58 all_apis = [] | 60 all_apis = [] |
59 for api_name, api_model in self._platform_bundle.GetAPIModels( | 61 for api_name, api_model in self._platform_bundle.GetAPIModels( |
60 platform).IterModels(): | 62 platform).IterModels(): |
not at google - send to devlin
2014/08/05 18:47:18
IterModels() might be a problem, it's an implicit
| |
61 if not self._platform_bundle.GetAPICategorizer(platform).IsDocumented( | 63 if not self._platform_bundle.GetAPICategorizer(platform).IsDocumented( |
62 api_name): | 64 api_name): |
63 continue | 65 continue |
64 api = { | 66 api = { |
65 'name': api_name, | 67 'name': api_name, |
66 'description': api_model.description, | 68 'description': api_model.description, |
67 } | 69 } |
68 category = self._platform_bundle.GetAPICategorizer( | 70 category = self._platform_bundle.GetAPICategorizer( |
69 platform).GetCategory(api_name) | 71 platform).GetCategory(api_name) |
70 if category == 'chrome': | 72 if category == 'chrome': |
(...skipping 17 matching lines...) Expand all Loading... | |
88 platform_dict['chrome'][channel] = apis_by_channel | 90 platform_dict['chrome'][channel] = apis_by_channel |
89 | 91 |
90 for key, apis in (('all', all_apis), | 92 for key, apis in (('all', all_apis), |
91 ('private', private_apis), | 93 ('private', private_apis), |
92 ('experimental', experimental_apis)): | 94 ('experimental', experimental_apis)): |
93 apis.sort(key=itemgetter('name')) | 95 apis.sort(key=itemgetter('name')) |
94 MarkLast(apis) | 96 MarkLast(apis) |
95 platform_dict[key] = apis | 97 platform_dict[key] = apis |
96 | 98 |
97 return platform_dict | 99 return platform_dict |
98 api_dict = dict((platform, make_dict_for_platform(platform)) | 100 |
99 for platform in GetPlatforms()) | 101 def make_api_dict(content_script_apis): |
100 api_dict['contentScripts'] = make_list_for_content_scripts() | 102 api_dict = dict((platform, make_dict_for_platform(platform)) |
101 return api_dict | 103 for platform in GetPlatforms()) |
104 api_dict['contentScripts'] = content_script_apis | |
105 return api_dict | |
106 | |
107 return make_list_for_content_scripts().Then(make_api_dict) | |
102 | 108 |
103 def _GetCachedAPIData(self): | 109 def _GetCachedAPIData(self): |
104 data_future = self._object_store.Get('api_data') | 110 def persist_and_return(data): |
105 def resolve(): | 111 self._object_store.Set('api_data', data) |
106 data = data_future.Get() | 112 return data |
113 def return_or_generate(data): | |
107 if data is None: | 114 if data is None: |
108 data = self._GenerateAPIDict() | 115 return self._GenerateAPIDict().Then(persist_and_return) |
109 self._object_store.Set('api_data', data) | |
110 return data | 116 return data |
111 return Future(callback=resolve) | 117 return self._object_store.Get('api_data').Then(return_or_generate) |
112 | 118 |
113 def get(self, key): | 119 def get(self, key): |
114 return self._GetCachedAPIData().Get().get(key) | 120 return self._GetCachedAPIData().Get().get(key) |
115 | 121 |
116 def Cron(self): | 122 def Cron(self): |
117 return self._GetCachedAPIData() | 123 return self._GetCachedAPIData() |
OLD | NEW |