import posixpath
-from compiled_file_system import SingleFile, Unicode
+from compiled_file_system import Cache, SingleFile, Unicode
from extensions_paths import API_PATHS
from features_bundle import HasParent, GetParentName
from file_system import FileNotFoundError
-from future import All, Future
+from future import All, Future, Race
from operator import itemgetter
+from path_util import Join
from platform_util import PlatformToExtensionType
-from schema_util import ProcessSchema
+from schema_processor import SchemaProcessor, SchemaProcessorFactory
from third_party.json_schema_compiler.json_schema import DeleteNodes
from third_party.json_schema_compiler.model import Namespace, UnixName
compiled_fs_factory,
file_system,
object_store_creator,
- platform):
+ platform,
+ schema_processor_factory):
self._features_bundle = features_bundle
self._platform = PlatformToExtensionType(platform)
self._model_cache = compiled_fs_factory.Create(
file_system, self._CreateAPIModel, APIModels, category=self._platform)
self._object_store = object_store_creator.Create(APIModels)
+ self._schema_processor = Future(callback=lambda:
+ schema_processor_factory.Create(False))
+ @Cache
@SingleFile
@Unicode
def _CreateAPIModel(self, path, data):
node['extension_types'] != 'all' and
self._platform not in node['extension_types'])
- schema = ProcessSchema(path, data)[0]
+ schema = self._schema_processor.Get().Process(path, data)[0]
if not schema:
raise ValueError('No schema for %s' % path)
return Namespace(DeleteNodes(
- schema, matcher=does_not_include_platform), schema['namespace'])
+ schema, matcher=does_not_include_platform), path)
def GetNames(self):
# API names appear alongside some of their methods/events/etc in the
return [name for name, feature in api_features.iteritems()
if not HasParent(name, feature, api_features)]
- def GetModel(self, api_name):
+ def _GetPotentialPathsForModel(self, api_name):
+ '''Returns the list of file system paths that the model for |api_name|
+ might be located at.
+ '''
# By default |api_name| is assumed to be given without a path or extension,
# so combinations of known paths and extension types will be searched.
api_extensions = ('.json', '.idl')
'devtools', file_name.replace(basename,
basename.replace('devtools_' , '')))
- futures = [self._model_cache.GetFromFile(
- posixpath.join(path, '%s%s' % (file_name, ext)))
- for ext in api_extensions
- for path in api_paths]
- def resolve():
- for future in futures:
- try:
- return future.Get()
- # Either the file wasn't found or there was no schema for the file
- except (FileNotFoundError, ValueError): pass
- # Propagate the first error if neither were found.
- futures[0].Get()
- return Future(callback=resolve)
+ return [Join(path, file_name + ext) for ext in api_extensions
+ for path in api_paths]
+
+ def GetModel(self, api_name):
+ futures = [self._model_cache.GetFromFile(path)
+ for path in self._GetPotentialPathsForModel(api_name)]
+ return Race(futures, except_pass=(FileNotFoundError, ValueError))
def GetContentScriptAPIs(self):
'''Creates a dict of APIs and nodes supported by content scripts in
return content_script_apis
return Future(callback=resolve)
- def Cron(self):
+ def Refresh(self):
futures = [self.GetModel(name) for name in self.GetNames()]
return All(futures, except_pass=(FileNotFoundError, ValueError))