OLD | NEW |
---|---|
(Empty) | |
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 | |
3 # found in the LICENSE file. | |
4 | |
5 from file_system import FileNotFoundError | |
6 import object_store | |
7 | |
8 class AvailabilityDataSource: | |
9 def __init__(self, | |
10 version_data_source, | |
11 version_number, | |
12 object_store): | |
13 self._version_data_source = version_data_source | |
14 self._version_number = version_number | |
15 self._object_store = object_store | |
16 | |
17 def FindEarliestAvailability(self, api_name): | |
18 """Searches in descending order through filesystem caches tied to specific | |
19 chrome version numbers and looks for the existence of a specified api, | |
20 |api_name|. When an api is not found, returns the previous version number | |
21 (the last known version where the api was found). | |
22 """ | |
23 version = self._object_store.Get( | |
24 api_name, | |
25 object_store.AVAILABILITY_DATA_SOURCE).Get() | |
26 | |
27 if version is not None: | |
28 return version | |
29 | |
30 version = int(self._version_number) | |
cduvall
2013/03/21 18:43:53
dont reuse version as an int. Call it something el
epeterson
2013/03/25 19:35:11
Done.
| |
31 while version >= 18: #extension api's are not present before version 18 | |
cduvall
2013/03/21 18:43:53
Put comment above while
epeterson
2013/03/25 19:35:11
Done.
| |
32 api_data_source = self._version_data_source.GetDataSourceForVersion( | |
33 "%d" % version) | |
cduvall
2013/03/21 18:43:53
single quotes
epeterson
2013/03/25 19:35:11
Done.
| |
34 try: | |
35 api_data_source.tryGet(api_name) | |
36 version -= 1 | |
cduvall
2013/03/21 18:43:53
instead of doing version -= 1 in both places, use
epeterson
2013/03/25 19:35:11
I didn't want that piece of code to always execute
| |
37 except FileNotFoundError: | |
38 try: | |
39 api_data_source.tryGet(api_name, tryNonUnix=True) | |
40 version -= 1 | |
41 except FileNotFoundError: | |
42 break | |
43 | |
44 version += 1 | |
45 #if version > self._version_number: api was not found in the current version | |
46 version = "%d" % version | |
47 self._object_store.Set(api_name, | |
48 version, | |
49 object_store.AVAILABILITY_DATA_SOURCE) | |
50 return version | |
OLD | NEW |