• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.
4
5import os
6from compiled_file_system import SingleFile
7from extensions_paths import PUBLIC_TEMPLATES
8
9
10class APICategorizer(object):
11  ''' This class gets api category from documented apis.
12  '''
13
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,
18                                             APICategorizer)
19
20  def _GenerateAPICategories(self, platform):
21    return self._cache.GetFromFileListing('%s/%s' % (PUBLIC_TEMPLATES,
22                                                     platform)).Get()
23  @SingleFile
24  def _CollectDocumentedAPIs(self, base_dir, files):
25    public_templates = []
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)
31    return template_names
32
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.
37    '''
38    documented_apis = self._GenerateAPICategories(platform)
39    if (api_name.endswith('Private') or
40        api_name not in documented_apis):
41      return 'private'
42    if api_name.startswith('experimental.'):
43      return 'experimental'
44    return 'chrome'
45
46  def IsDocumented(self, platform, api_name):
47    return (api_name in self._GenerateAPICategories(platform))