OLD | NEW |
(Empty) | |
| 1 # Copyright (c) 2013 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. |
| 4 |
| 5 from file_system import FileNotFoundError |
| 6 import object_store |
| 7 |
| 8 class AvailabilityDataSource: |
| 9 """Uses API data sources generated by a ChromeVersionDataSource in order to |
| 10 search the filesystem for the earliest existence of a specified API throughout |
| 11 the different versions of Chrome; this constitutes an API's availability. |
| 12 """ |
| 13 |
| 14 def __init__(self, version_data_source, version, object_store): |
| 15 self._version_data_source = version_data_source |
| 16 self._version = version |
| 17 self._object_store = object_store |
| 18 |
| 19 def _CheckExistence(self, api_name, version): |
| 20 """Tries to 'get' an api from the filesystem, and reports whether or not it |
| 21 was successful. |
| 22 """ |
| 23 api_data_source = self._version_data_source.GetDataSourceForVersion( |
| 24 str(version)) |
| 25 try: |
| 26 api_data_source.TryGet(api_name) |
| 27 except FileNotFoundError: |
| 28 try: |
| 29 api_data_source.TryGet(api_name, try_non_unix=True) |
| 30 except FileNotFoundError: |
| 31 return False |
| 32 return True |
| 33 |
| 34 def FindEarliestAvailability(self, api_name): |
| 35 """Searches in descending order through filesystem caches tied to specific |
| 36 chrome version numbers and looks for the existence of a specified api, |
| 37 |api_name|. When an api is not found, returns the previous version number |
| 38 (the last known version where the api was found). |
| 39 """ |
| 40 availability = self._object_store.Get( |
| 41 api_name, |
| 42 object_store.AVAILABILITY_DATA_SOURCE).Get() |
| 43 |
| 44 if availability is not None: |
| 45 return availability |
| 46 elif availability is False: |
| 47 return None |
| 48 |
| 49 if self._version == 'trunk': |
| 50 if not self._CheckExistence(api_name, 'trunk'): |
| 51 # If the API wasn't found in trunk, then it isn't currently available. |
| 52 self._object_store.Set(api_name, |
| 53 False, |
| 54 object_store.AVAILABILITY_DATA_SOURCE) |
| 55 return None |
| 56 |
| 57 if self._version == 'trunk': |
| 58 latest_version = self._version_data_source.GetLatestVersionNumber() |
| 59 version_int = latest_version |
| 60 else: |
| 61 version_int = int(self._version) |
| 62 |
| 63 # Extension APIs are not present in the filesystem before version 18. |
| 64 while version_int >= 18: |
| 65 if not self._CheckExistence(api_name, version_int): |
| 66 break |
| 67 version_int -= 1 |
| 68 |
| 69 version_int += 1 |
| 70 # If the version number is greater than the current version of Chrome, then |
| 71 # the API was not found in the current version. |
| 72 if self._version == 'trunk': |
| 73 if version_int > latest_version: |
| 74 availability = 'trunk' |
| 75 else: |
| 76 availability = str(version_int) |
| 77 elif version_int <= int(self._version): |
| 78 availability = str(version_int) |
| 79 |
| 80 self._object_store.Set(api_name, |
| 81 availability, |
| 82 object_store.AVAILABILITY_DATA_SOURCE) |
| 83 return availability |
OLD | NEW |