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
3 # found in the LICENSE file.
5 from operator
import itemgetter
7 import docs_server_utils
as utils
9 class APIListDataSource(object):
10 """ This class creates a list of chrome.* APIs and chrome.experimental.* APIs
11 for extensions and apps that are used in the api_index.html,
12 experimental.html, and private_apis.html pages.
14 An API is considered listable if it is listed in _api_features.json,
15 it has a corresponding HTML file in the public template path, and one of
16 the following conditions is met:
17 - It has no "dependencies" or "extension_types" properties in _api_features
18 - It has an "extension_types" property in _api_features with either/both
19 "extension"/"platform_app" values present.
20 - It has a dependency in _{api,manifest,permission}_features with an
21 "extension_types" property where either/both "extension"/"platform_app"
24 class Factory(object):
33 self
._file
_system
= file_system
34 self
._features
_bundle
= features_bundle
35 self
._api
_categorizer
= api_categorizer
36 self
._object
_store
_creator
= object_store_creator
37 self
._api
_models
= api_models
38 self
._availability
_finder
= availability_finder
40 def _GenerateAPIDict(self
):
42 def _GetChannelInfo(api_name
):
43 return self
._availability
_finder
.GetApiAvailability(api_name
)
45 def _GetApiPlatform(api_name
):
46 feature
= self
._features
_bundle
.GetAPIFeatures().Get()[api_name
]
47 return feature
['platforms']
49 def _MakeDictForPlatform(platform
):
51 'chrome': {'stable': [], 'beta': [], 'dev': [], 'trunk': []},
54 experimental_apis
= []
56 for api_name
, api_model
in self
._api
_models
.IterModels():
57 if not self
._api
_categorizer
.IsDocumented(platform
, api_name
):
61 'description': api_model
.description
,
62 'platforms': _GetApiPlatform(api_name
),
64 category
= self
._api
_categorizer
.GetCategory(platform
, api_name
)
65 if category
== 'chrome':
66 channel_info
= _GetChannelInfo(api_name
)
67 channel
= channel_info
.channel
68 if channel
== 'stable':
69 version
= channel_info
.version
70 api
['version'] = version
71 platform_dict
[category
][channel
].append(api
)
73 elif category
== 'experimental':
74 experimental_apis
.append(api
)
76 elif category
== 'private':
77 private_apis
.append(api
)
79 for channel
, apis_by_channel
in platform_dict
['chrome'].iteritems():
80 apis_by_channel
.sort(key
=itemgetter('name'))
81 utils
.MarkLast(apis_by_channel
)
82 platform_dict
['chrome'][channel
] = apis_by_channel
84 for key
, apis
in (('all', all_apis
),
85 ('private', private_apis
),
86 ('experimental', experimental_apis
)):
87 apis
.sort(key
=itemgetter('name'))
89 platform_dict
[key
] = apis
93 'apps': _MakeDictForPlatform('apps'),
94 'extensions': _MakeDictForPlatform('extensions'),
98 return APIListDataSource(self
, self
._object
_store
_creator
)
100 def __init__(self
, factory
, object_store_creator
):
101 self
._factory
= factory
102 self
._object
_store
= object_store_creator
.Create(APIListDataSource
)
104 def _GetCachedAPIData(self
):
105 data
= self
._object
_store
.Get('api_data').Get()
107 data
= self
._factory
._GenerateAPIDict
()
108 self
._object
_store
.Set('api_data', data
)
112 return self
._GetCachedAPIData
().get(key
)