1 # Copyright 2014 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 api_categorizer
import APICategorizer
6 from api_models
import APIModels
7 from availability_finder
import AvailabilityFinder
8 from empty_dir_file_system
import EmptyDirFileSystem
9 from environment
import IsDevServer
10 from features_bundle
import FeaturesBundle
11 from future
import All
12 from platform_util
import GetPlatforms
, PlatformToExtensionType
13 from reference_resolver
import ReferenceResolver
14 from samples_model
import SamplesModel
15 from future
import Future
16 from schema_processor
import SchemaProcessorFactory
19 class _PlatformData(object):
21 self
.features_bundle
= None
22 self
.api_models
= None
23 self
.reference_resolver
= None
24 self
.availability_finder
= None
25 self
.api_categorizer
= None
26 self
.samples_model
= None
29 class PlatformBundle(object):
30 '''Creates various objects for different platforms
36 host_file_system_iterator
,
39 self
._branch
_utility
= branch_utility
40 self
._compiled
_fs
_factory
= compiled_fs_factory
41 self
._host
_fs
_at
_master
= host_fs_at_master
42 self
._host
_file
_system
_iterator
= host_file_system_iterator
43 self
._object
_store
_creator
= object_store_creator
44 self
._base
_path
= base_path
45 self
._platform
_data
= dict((p
, _PlatformData()) for p
in GetPlatforms())
47 def GetSamplesModel(self
, platform
):
48 if self
._platform
_data
[platform
].samples_model
is None:
49 # Note: samples are super slow in the dev server because it doesn't
50 # support async fetch, so disable them.
52 extension_samples_fs
= EmptyDirFileSystem()
53 app_samples_fs
= EmptyDirFileSystem()
55 extension_samples_fs
= self
._host
_fs
_at
_master
56 # TODO(kalman): Re-enable the apps samples, see http://crbug.com/344097.
57 app_samples_fs
= EmptyDirFileSystem()
58 #app_samples_fs = github_file_system_provider.Create(
59 # 'GoogleChrome', 'chrome-app-samples')
60 self
._platform
_data
[platform
].samples_model
= SamplesModel(
63 self
._compiled
_fs
_factory
,
64 self
.GetReferenceResolver(platform
),
67 return self
._platform
_data
[platform
].samples_model
69 def GetFeaturesBundle(self
, platform
):
70 if self
._platform
_data
[platform
].features_bundle
is None:
71 self
._platform
_data
[platform
].features_bundle
= FeaturesBundle(
72 self
._host
_fs
_at
_master
,
73 self
._compiled
_fs
_factory
,
74 self
._object
_store
_creator
,
76 return self
._platform
_data
[platform
].features_bundle
78 def GetAPIModels(self
, platform
):
79 if self
._platform
_data
[platform
].api_models
is None:
80 # TODO(danielj41): Filter APIModels data here rather than passing the
82 self
._platform
_data
[platform
].api_models
= APIModels(
83 self
.GetFeaturesBundle(platform
),
84 self
._compiled
_fs
_factory
,
85 self
._host
_fs
_at
_master
,
86 self
._object
_store
_creator
,
88 SchemaProcessorFactory(
89 Future(callback
=lambda: self
.GetReferenceResolver(platform
)),
90 Future(callback
=lambda: self
.GetAPIModels(platform
)),
91 Future(callback
=lambda: self
.GetFeaturesBundle(platform
)),
92 self
._compiled
_fs
_factory
,
93 self
._host
_fs
_at
_master
))
94 return self
._platform
_data
[platform
].api_models
96 def GetReferenceResolver(self
, platform
):
97 if self
._platform
_data
[platform
].reference_resolver
is None:
98 self
._platform
_data
[platform
].reference_resolver
= ReferenceResolver(
99 self
.GetAPIModels(platform
),
100 self
._object
_store
_creator
.Create(ReferenceResolver
,
102 return self
._platform
_data
[platform
].reference_resolver
104 def GetAvailabilityFinder(self
, platform
):
105 if self
._platform
_data
[platform
].availability_finder
is None:
106 self
._platform
_data
[platform
].availability_finder
= AvailabilityFinder(
107 self
._branch
_utility
,
108 self
._compiled
_fs
_factory
,
109 self
._host
_file
_system
_iterator
,
110 self
._host
_fs
_at
_master
,
111 self
._object
_store
_creator
,
113 SchemaProcessorFactory(
114 Future(callback
=lambda: self
.GetReferenceResolver(platform
)),
115 Future(callback
=lambda: self
.GetAPIModels(platform
)),
116 Future(callback
=lambda: self
.GetFeaturesBundle(platform
)),
117 self
._compiled
_fs
_factory
,
118 self
._host
_fs
_at
_master
))
119 return self
._platform
_data
[platform
].availability_finder
121 def GetAPICategorizer(self
, platform
):
122 if self
._platform
_data
[platform
].api_categorizer
is None:
123 self
._platform
_data
[platform
].api_categorizer
= APICategorizer(
124 self
._host
_fs
_at
_master
,
125 self
._compiled
_fs
_factory
,
127 return self
._platform
_data
[platform
].api_categorizer
130 return All(self
.GetAPIModels(platform
).Refresh()
131 for platform
in self
._platform
_data
.keys())
133 def GetIdentity(self
):
134 return self
._host
_fs
_at
_master
.GetIdentity()