| OLD | NEW |
| 1 # Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 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 import os | 5 import os |
| 6 import posixpath | 6 import posixpath |
| 7 | 7 |
| 8 from compiled_file_system import SingleFile | 8 from compiled_file_system import SingleFile |
| 9 from extensions_paths import PUBLIC_TEMPLATES | 9 from extensions_paths import PUBLIC_TEMPLATES |
| 10 | 10 |
| 11 | 11 |
| 12 class APICategorizer(object): | 12 class APICategorizer(object): |
| 13 ''' This class gets api category from documented apis. | 13 ''' This class gets api category from documented apis. |
| 14 ''' | 14 ''' |
| 15 | 15 |
| 16 def __init__(self, file_system, compiled_fs_factory): | 16 def __init__(self, file_system, compiled_fs_factory, platform): |
| 17 self._file_system = file_system | 17 self._file_system = file_system |
| 18 self._cache = compiled_fs_factory.Create(file_system, | 18 self._cache = compiled_fs_factory.Create(file_system, |
| 19 self._CollectDocumentedAPIs, | 19 self._CollectDocumentedAPIs, |
| 20 APICategorizer) | 20 APICategorizer) |
| 21 self._platform = platform |
| 21 | 22 |
| 22 def _GenerateAPICategories(self, platform): | 23 def _GenerateAPICategories(self): |
| 23 return self._cache.GetFromFileListing( | 24 return self._cache.GetFromFileListing( |
| 24 posixpath.join(PUBLIC_TEMPLATES, platform) + '/').Get() | 25 posixpath.join(PUBLIC_TEMPLATES, self._platform) + '/').Get() |
| 25 | 26 |
| 26 @SingleFile | 27 @SingleFile |
| 27 def _CollectDocumentedAPIs(self, base_dir, files): | 28 def _CollectDocumentedAPIs(self, base_dir, files): |
| 28 public_templates = [] | 29 public_templates = [] |
| 29 for root, _, files in self._file_system.Walk(base_dir): | 30 for root, _, files in self._file_system.Walk(base_dir): |
| 30 public_templates.extend(posixpath.join(root, name) for name in files) | 31 public_templates.extend(posixpath.join(root, name) for name in files) |
| 31 template_names = set(os.path.splitext(name)[0].replace('_', '.') | 32 template_names = set(os.path.splitext(name)[0].replace('_', '.') |
| 32 for name in public_templates) | 33 for name in public_templates) |
| 33 return template_names | 34 return template_names |
| 34 | 35 |
| 35 def GetCategory(self, platform, api_name): | 36 def GetCategory(self, api_name): |
| 36 '''Return the type of api.'Chrome' means the public apis, | 37 '''Return the type of api.'Chrome' means the public apis, |
| 37 private means the api only used by chrome, and experimental means | 38 private means the api only used by chrome, and experimental means |
| 38 the apis with "experimental" prefix. | 39 the apis with "experimental" prefix. |
| 39 ''' | 40 ''' |
| 40 documented_apis = self._GenerateAPICategories(platform) | 41 documented_apis = self._GenerateAPICategories() |
| 41 if (api_name.endswith('Private') or | 42 if (api_name.endswith('Private') or |
| 42 api_name not in documented_apis): | 43 api_name not in documented_apis): |
| 43 return 'private' | 44 return 'private' |
| 44 if api_name.startswith('experimental.'): | 45 if api_name.startswith('experimental.'): |
| 45 return 'experimental' | 46 return 'experimental' |
| 46 return 'chrome' | 47 return 'chrome' |
| 47 | 48 |
| 48 def IsDocumented(self, platform, api_name): | 49 def IsDocumented(self, api_name): |
| 49 return (api_name in self._GenerateAPICategories(platform)) | 50 return (api_name in self._GenerateAPICategories()) |
| OLD | NEW |