Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(130)

Side by Side Diff: chrome/common/extensions/docs/server2/availability_data_source.py

Issue 12996003: Dynamically generate a heading for Extension Docs API pages (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Updates to HasAPI in APIDataSource Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 """Calls APIDataSource's HasAPI method on an API from the filesystem,
21 which will report whether or not the API was found in the current branch.
22 """
23 api_data_source = self._version_data_source.GetDataSourceForVersion(
24 str(version))
25 return api_data_source.HasAPI(api_name)
26
27 def FindEarliestAvailability(self, api_name):
28 """Searches in descending order through filesystem caches tied to specific
29 chrome version numbers and looks for the existence of a specified api,
30 |api_name|. When an api is not found, returns the previous version number
31 (the last known version where the api was found).
32 """
33 availability = self._object_store.Get(
34 api_name,
35 object_store.AVAILABILITY_DATA_SOURCE).Get()
36
37 if availability is not None:
38 return availability
39 elif availability is False:
40 return None
41
42 if self._version == 'trunk':
43 if not self._CheckExistence(api_name, 'trunk'):
44 # If the API wasn't found in trunk, then it isn't currently available.
45 self._object_store.Set(api_name,
46 False,
47 object_store.AVAILABILITY_DATA_SOURCE)
48 return None
49
50 if self._version == 'trunk':
51 latest_version = self._version_data_source.GetLatestVersionNumber()
52 version_int = latest_version
53 else:
54 version_int = int(self._version)
55
56 # Extension APIs are not present in the filesystem before version 18.
57 while version_int >= 18:
58 if not self._CheckExistence(api_name, version_int):
59 break
60 version_int -= 1
61
62 version_int += 1
63 # If the version number is greater than the current version of Chrome, then
64 # the API was not found in the current version.
65 if self._version == 'trunk':
66 if version_int > latest_version:
67 availability = 'trunk'
68 else:
69 availability = str(version_int)
70 elif version_int <= int(self._version):
71 availability = str(version_int)
72
73 self._object_store.Set(api_name,
74 availability,
75 object_store.AVAILABILITY_DATA_SOURCE)
76 return availability
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698