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

Side by Side Diff: chrome/common/extensions/docs/server2/api_list_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 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 9
9 from docs_server_utils import MarkLast, StringIdentity 10 from docs_server_utils import MarkLast
10 11
11 class APIListDataSource(DataSource): 12 class APIListDataSource(DataSource):
12 """ This class creates a list of chrome.* APIs and chrome.experimental.* APIs 13 """ This class creates a list of chrome.* APIs and chrome.experimental.* APIs
13 for extensions and apps that are used in the api_index.html, 14 for extensions and apps that are used in the api_index.html,
14 experimental.html, and private_apis.html pages. 15 experimental.html, and private_apis.html pages.
15 16
16 An API is considered listable if it is listed in _api_features.json, 17 An API is considered listable if it is listed in _api_features.json,
17 it has a corresponding HTML file in the public template path, and one of 18 it has a corresponding HTML file in the public template path, and one of
18 the following conditions is met: 19 the following conditions is met:
19 - It has no "dependencies" or "extension_types" properties in _api_features 20 - It has no "dependencies" or "extension_types" properties in _api_features
20 - It has an "extension_types" property in _api_features with either/both 21 - It has an "extension_types" property in _api_features with either/both
21 "extension"/"platform_app" values present. 22 "extension"/"platform_app" values present.
22 - It has a dependency in _{api,manifest,permission}_features with an 23 - It has a dependency in _{api,manifest,permission}_features with an
23 "extension_types" property where either/both "extension"/"platform_app" 24 "extension_types" property where either/both "extension"/"platform_app"
24 values are present. 25 values are present.
25 """ 26 """
26 def __init__(self, server_instance, _): 27 def __init__(self, server_instance, _):
27 self._features_bundle = server_instance.features_bundle 28 self._platform_bundle = server_instance.platform_bundle
28 self._api_models = server_instance.api_models
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, 31 APIListDataSource, category=self._platform_bundle.GetIdentity())
32 category=StringIdentity(self._features_bundle.GetIdentity(),
33 self._api_models.GetIdentity()))
34 self._api_categorizer = server_instance.api_categorizer
35 self._availability_finder = server_instance.availability_finder
36 32
37 def _GenerateAPIDict(self): 33 def _GenerateAPIDict(self):
38 def get_channel_info(api_name):
39 return self._availability_finder.GetAPIAvailability(api_name).channel_info
40
41 def get_api_platform(api_name):
42 feature = self._features_bundle.GetAPIFeatures().Get()[api_name]
43 return feature['platforms']
44
45 def make_dict_for_platform(platform): 34 def make_dict_for_platform(platform):
46 platform_dict = { 35 platform_dict = {
47 'chrome': {'stable': [], 'beta': [], 'dev': [], 'trunk': []}, 36 'chrome': {'stable': [], 'beta': [], 'dev': [], 'trunk': []},
48 } 37 }
49 private_apis = [] 38 private_apis = []
50 experimental_apis = [] 39 experimental_apis = []
51 all_apis = [] 40 all_apis = []
52 for api_name, api_model in self._api_models.IterModels(): 41 for api_name, api_model in self._platform_bundle.GetAPIModels(
53 if not self._api_categorizer.IsDocumented(platform, api_name): 42 platform).IterModels():
43 if not self._platform_bundle.GetAPICategorizer(platform).IsDocumented(
44 api_name):
54 continue 45 continue
55 api = { 46 api = {
56 'name': api_name, 47 'name': api_name,
57 'description': api_model.description, 48 'description': api_model.description,
58 'platforms': get_api_platform(api_name),
59 } 49 }
60 category = self._api_categorizer.GetCategory(platform, api_name) 50 category = self._platform_bundle.GetAPICategorizer(
51 platform).GetCategory(api_name)
61 if category == 'chrome': 52 if category == 'chrome':
62 channel_info = get_channel_info(api_name) 53 channel_info = self._platform_bundle.GetAvailabilityFinder(
54 platform).GetAPIAvailability(api_name).channel_info
63 channel = channel_info.channel 55 channel = channel_info.channel
64 if channel == 'stable': 56 if channel == 'stable':
65 version = channel_info.version 57 version = channel_info.version
66 api['version'] = version 58 api['version'] = version
67 platform_dict[category][channel].append(api) 59 platform_dict[category][channel].append(api)
68 all_apis.append(api) 60 all_apis.append(api)
69 elif category == 'experimental': 61 elif category == 'experimental':
70 experimental_apis.append(api) 62 experimental_apis.append(api)
71 all_apis.append(api) 63 all_apis.append(api)
72 elif category == 'private': 64 elif category == 'private':
73 private_apis.append(api) 65 private_apis.append(api)
74 66
75 for channel, apis_by_channel in platform_dict['chrome'].iteritems(): 67 for channel, apis_by_channel in platform_dict['chrome'].iteritems():
76 apis_by_channel.sort(key=itemgetter('name')) 68 apis_by_channel.sort(key=itemgetter('name'))
77 MarkLast(apis_by_channel) 69 MarkLast(apis_by_channel)
78 platform_dict['chrome'][channel] = apis_by_channel 70 platform_dict['chrome'][channel] = apis_by_channel
79 71
80 for key, apis in (('all', all_apis), 72 for key, apis in (('all', all_apis),
81 ('private', private_apis), 73 ('private', private_apis),
82 ('experimental', experimental_apis)): 74 ('experimental', experimental_apis)):
83 apis.sort(key=itemgetter('name')) 75 apis.sort(key=itemgetter('name'))
84 MarkLast(apis) 76 MarkLast(apis)
85 platform_dict[key] = apis 77 platform_dict[key] = apis
86 78
87 return platform_dict 79 return platform_dict
88 return { 80 return dict((platform, make_dict_for_platform(platform))
89 'apps': make_dict_for_platform('apps'), 81 for platform in GetPlatforms())
90 'extensions': make_dict_for_platform('extensions'),
91 }
92 82
93 def _GetCachedAPIData(self): 83 def _GetCachedAPIData(self):
94 data_future = self._object_store.Get('api_data') 84 data_future = self._object_store.Get('api_data')
95 def resolve(): 85 def resolve():
96 data = data_future.Get() 86 data = data_future.Get()
97 if data is None: 87 if data is None:
98 data = self._GenerateAPIDict() 88 data = self._GenerateAPIDict()
99 self._object_store.Set('api_data', data) 89 self._object_store.Set('api_data', data)
100 return data 90 return data
101 return Future(callback=resolve) 91 return Future(callback=resolve)
102 92
103 def get(self, key): 93 def get(self, key):
104 return self._GetCachedAPIData().Get().get(key) 94 return self._GetCachedAPIData().Get().get(key)
105 95
106 def Cron(self): 96 def Cron(self):
107 return self._GetCachedAPIData() 97 return self._GetCachedAPIData()
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698