| OLD | NEW |
| 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2012 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 hashlib | 5 import hashlib |
| 6 import json | 6 import json |
| 7 import logging | 7 import logging |
| 8 import posixpath | 8 import posixpath |
| 9 import re | 9 import re |
| 10 import traceback | 10 import traceback |
| 11 | 11 |
| 12 from compiled_file_system import CompiledFileSystem | 12 from compiled_file_system import CompiledFileSystem |
| 13 import third_party.json_schema_compiler.json_comment_eater as json_comment_eater | 13 import third_party.json_schema_compiler.json_comment_eater as json_comment_eater |
| 14 import third_party.json_schema_compiler.model as model | 14 import third_party.json_schema_compiler.model as model |
| 15 import url_constants | 15 import url_constants |
| 16 | 16 |
| 17 DEFAULT_ICON_PATH = 'images/sample-default-icon.png' | 17 DEFAULT_ICON_PATH = 'images/sample-default-icon.png' |
| 18 | 18 |
| 19 class SamplesDataSource(object): | 19 class SamplesDataSource(object): |
| 20 '''Constructs a list of samples and their respective files and api calls. | 20 '''Constructs a list of samples and their respective files and api calls. |
| 21 ''' | 21 ''' |
| 22 class Factory(object): | 22 class Factory(object): |
| 23 '''A factory to create SamplesDataSource instances bound to individual | 23 '''A factory to create SamplesDataSource instances bound to individual |
| 24 Requests. | 24 Requests. |
| 25 ''' | 25 ''' |
| 26 def __init__(self, | 26 def __init__(self, |
| 27 host_file_system, | 27 host_file_system, |
| 28 compiled_host_fs_factory, | |
| 29 app_samples_file_system, | 28 app_samples_file_system, |
| 30 compiled_app_samples_fs_factory, | 29 compiled_fs_factory, |
| 31 ref_resolver_factory, | 30 ref_resolver_factory, |
| 32 extension_samples_path, | 31 extension_samples_path, |
| 33 base_path): | 32 base_path): |
| 34 self._host_file_system = host_file_system | 33 self._host_file_system = host_file_system |
| 35 self._app_samples_file_system = app_samples_file_system | 34 self._app_samples_file_system = app_samples_file_system |
| 36 self._ref_resolver = ref_resolver_factory.Create() | 35 self._ref_resolver = ref_resolver_factory.Create() |
| 37 self._extension_samples_path = extension_samples_path | 36 self._extension_samples_path = extension_samples_path |
| 38 self._base_path = base_path | 37 self._base_path = base_path |
| 39 self._extensions_cache = compiled_host_fs_factory.Create( | 38 self._extensions_cache = compiled_fs_factory.Create( |
| 39 host_file_system, |
| 40 self._MakeSamplesList, | 40 self._MakeSamplesList, |
| 41 SamplesDataSource, | 41 SamplesDataSource, |
| 42 category='extensions') | 42 category='extensions') |
| 43 self._apps_cache = compiled_app_samples_fs_factory.Create( | 43 self._apps_cache = compiled_fs_factory.Create( |
| 44 app_samples_file_system, |
| 44 lambda *args: self._MakeSamplesList(*args, is_apps=True), | 45 lambda *args: self._MakeSamplesList(*args, is_apps=True), |
| 45 SamplesDataSource, | 46 SamplesDataSource, |
| 46 category='apps') | 47 category='apps') |
| 47 | 48 |
| 48 def Create(self, request): | 49 def Create(self, request): |
| 49 '''Returns a new SamplesDataSource bound to |request|. | 50 '''Returns a new SamplesDataSource bound to |request|. |
| 50 ''' | 51 ''' |
| 51 return SamplesDataSource(self._extensions_cache, | 52 return SamplesDataSource(self._extensions_cache, |
| 52 self._apps_cache, | 53 self._apps_cache, |
| 53 self._extension_samples_path, | 54 self._extension_samples_path, |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 241 else: | 242 else: |
| 242 dict_['id'] = self._GetSampleId(name) | 243 dict_['id'] = self._GetSampleId(name) |
| 243 return_list.append(dict_) | 244 return_list.append(dict_) |
| 244 return return_list | 245 return return_list |
| 245 | 246 |
| 246 def get(self, key): | 247 def get(self, key): |
| 247 return { | 248 return { |
| 248 'apps': lambda: self._CreateSamplesDict('apps'), | 249 'apps': lambda: self._CreateSamplesDict('apps'), |
| 249 'extensions': lambda: self._CreateSamplesDict('extensions') | 250 'extensions': lambda: self._CreateSamplesDict('extensions') |
| 250 }.get(key, lambda: {})() | 251 }.get(key, lambda: {})() |
| OLD | NEW |