| 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 json | 5 import json |
| 6 import logging | 6 import logging |
| 7 import posixpath | 7 import posixpath |
| 8 import re | 8 import re |
| 9 import traceback | 9 import traceback |
| 10 | 10 |
| 11 from extensions_paths import EXAMPLES | 11 from extensions_paths import EXAMPLES |
| 12 import third_party.json_schema_compiler.json_comment_eater as json_comment_eater | 12 import third_party.json_schema_compiler.json_comment_eater as json_comment_eater |
| 13 import url_constants | 13 import url_constants |
| 14 | 14 |
| 15 | 15 |
| 16 _DEFAULT_ICON_PATH = 'images/sample-default-icon.png' | 16 _DEFAULT_ICON_PATH = 'images/sample-default-icon.png' |
| 17 | 17 |
| 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 app_samples_file_system, | 28 app_samples_file_system, |
| 29 compiled_fs_factory, | 29 compiled_fs_factory, |
| 30 ref_resolver_factory, | 30 ref_resolver, |
| 31 base_path): | 31 base_path): |
| 32 self._host_file_system = host_file_system | 32 self._host_file_system = host_file_system |
| 33 self._app_samples_file_system = app_samples_file_system | 33 self._app_samples_file_system = app_samples_file_system |
| 34 self._ref_resolver = ref_resolver_factory.Create() | 34 self._ref_resolver = ref_resolver |
| 35 self._base_path = base_path | 35 self._base_path = base_path |
| 36 self._extensions_cache = compiled_fs_factory.Create( | 36 self._extensions_cache = compiled_fs_factory.Create( |
| 37 host_file_system, | 37 host_file_system, |
| 38 self._MakeSamplesList, | 38 self._MakeSamplesList, |
| 39 SamplesDataSource, | 39 SamplesDataSource, |
| 40 category='extensions') | 40 category='extensions') |
| 41 self._extensions_text_cache = compiled_fs_factory.ForUnicode( | 41 self._extensions_text_cache = compiled_fs_factory.ForUnicode( |
| 42 host_file_system) | 42 host_file_system) |
| 43 self._apps_cache = compiled_fs_factory.Create( | 43 self._apps_cache = compiled_fs_factory.Create( |
| 44 app_samples_file_system, | 44 app_samples_file_system, |
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 243 else: | 243 else: |
| 244 dict_['id'] = self._GetSampleId(name) | 244 dict_['id'] = self._GetSampleId(name) |
| 245 return_list.append(dict_) | 245 return_list.append(dict_) |
| 246 return return_list | 246 return return_list |
| 247 | 247 |
| 248 def get(self, key): | 248 def get(self, key): |
| 249 return { | 249 return { |
| 250 'apps': lambda: self._CreateSamplesDict('apps'), | 250 'apps': lambda: self._CreateSamplesDict('apps'), |
| 251 'extensions': lambda: self._CreateSamplesDict('extensions') | 251 'extensions': lambda: self._CreateSamplesDict('extensions') |
| 252 }.get(key, lambda: {})() | 252 }.get(key, lambda: {})() |
| OLD | NEW |