| 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 logging | 5 import logging |
| 6 import traceback | 6 import traceback |
| 7 | 7 |
| 8 from data_source import DataSource | 8 from data_source import DataSource |
| 9 from extensions_paths import EXAMPLES | 9 from extensions_paths import EXAMPLES |
| 10 from future import All, Future | |
| 11 from jsc_view import CreateSamplesView | 10 from jsc_view import CreateSamplesView |
| 12 from platform_util import GetPlatforms | 11 from platform_util import GetPlatforms |
| 13 | 12 |
| 14 | 13 |
| 15 class SamplesDataSource(DataSource): | 14 class SamplesDataSource(DataSource): |
| 16 '''Constructs a list of samples and their respective files and api calls. | 15 '''Constructs a list of samples and their respective files and api calls. |
| 17 ''' | 16 ''' |
| 18 def __init__(self, server_instance, request): | 17 def __init__(self, server_instance, request): |
| 19 self._platform_bundle = server_instance.platform_bundle | 18 self._platform_bundle = server_instance.platform_bundle |
| 20 self._request = request | 19 self._request = request |
| 21 | 20 |
| 22 def _GetImpl(self, platform): | 21 def _GetImpl(self, platform): |
| 23 cache = self._platform_bundle.GetSamplesModel(platform).GetCache() | 22 cache = self._platform_bundle.GetSamplesModel(platform).GetCache() |
| 24 create_view = lambda samp_list: CreateSamplesView(samp_list, self._request) | 23 create_view = lambda samp_list: CreateSamplesView(samp_list, self._request) |
| 25 return cache.GetFromFileListing('' if platform == 'apps' | 24 return cache.GetFromFileListing('' if platform == 'apps' |
| 26 else EXAMPLES).Then(create_view) | 25 else EXAMPLES).Then(create_view) |
| 27 | 26 |
| 28 def get(self, platform): | 27 def get(self, platform): |
| 29 return self._GetImpl(platform).Get() | 28 return self._GetImpl(platform).Get() |
| 30 | 29 |
| 31 def GetRefreshPaths(self): | 30 def GetRefreshPaths(self): |
| 32 return [platform for platform in GetPlatforms()] | 31 return [platform for platform in GetPlatforms()] |
| 33 | 32 |
| 34 def Refresh(self, path): | 33 def Refresh(self, path): |
| 35 return self._GetImpl(path) | 34 return self._GetImpl(path) |
| OLD | NEW |