Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / chrome / common / extensions / docs / server2 / platform_bundle.py
blob0316c001a14cc24cd25a837866b11c2045cdf188
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):
20 def __init__(self):
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
31 '''
32 def __init__(self,
33 branch_utility,
34 compiled_fs_factory,
35 host_fs_at_master,
36 host_file_system_iterator,
37 object_store_creator,
38 base_path):
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.
51 if IsDevServer():
52 extension_samples_fs = EmptyDirFileSystem()
53 app_samples_fs = EmptyDirFileSystem()
54 else:
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(
61 extension_samples_fs,
62 app_samples_fs,
63 self._compiled_fs_factory,
64 self.GetReferenceResolver(platform),
65 self._base_path,
66 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,
75 platform)
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
81 # platform.
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,
87 platform,
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,
101 category=platform))
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,
112 platform,
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,
126 platform)
127 return self._platform_data[platform].api_categorizer
129 def Refresh(self):
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()