1 # Copyright 2013 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.
6 from compiled_file_system
import SingleFile
7 from extensions_paths
import PUBLIC_TEMPLATES
10 class APICategorizer(object):
11 ''' This class gets api category from documented apis.
14 def __init__(self
, file_system
, compiled_fs_factory
):
15 self
._file
_system
= file_system
16 self
._cache
= compiled_fs_factory
.Create(file_system
,
17 self
._CollectDocumentedAPIs
,
20 def _GenerateAPICategories(self
, platform
):
21 return self
._cache
.GetFromFileListing('%s/%s' % (PUBLIC_TEMPLATES
,
24 def _CollectDocumentedAPIs(self
, base_dir
, files
):
26 for root
, _
, files
in self
._file
_system
.Walk(base_dir
):
27 public_templates
.extend(
28 ('%s/%s' % (root
, name
)).lstrip('/') for name
in files
)
29 template_names
= set(os
.path
.splitext(name
)[0].replace('_', '.')
30 for name
in public_templates
)
33 def GetCategory(self
, platform
, api_name
):
34 '''Return the type of api.'Chrome' means the public apis,
35 private means the api only used by chrome, and experimental means
36 the apis with "experimental" prefix.
38 documented_apis
= self
._GenerateAPICategories
(platform
)
39 if (api_name
.endswith('Private') or
40 api_name
not in documented_apis
):
42 if api_name
.startswith('experimental.'):
46 def IsDocumented(self
, platform
, api_name
):
47 return (api_name
in self
._GenerateAPICategories
(platform
))