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

Unified 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: Fixing issues with experimental_APIs Created 7 years, 9 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 side-by-side diff with in-line comments
Download patch
Index: chrome/common/extensions/docs/server2/availability_data_source.py
diff --git a/chrome/common/extensions/docs/server2/availability_data_source.py b/chrome/common/extensions/docs/server2/availability_data_source.py
new file mode 100644
index 0000000000000000000000000000000000000000..953c7132b81acbfdb1743caedbe243630026f838
--- /dev/null
+++ b/chrome/common/extensions/docs/server2/availability_data_source.py
@@ -0,0 +1,83 @@
+# Copyright (c) 2012 The Chromium Authors. All rights reserved.
cduvall 2013/03/28 22:18:35 2013 for all files
epeterson 2013/03/28 23:50:36 Done.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+from file_system import FileNotFoundError
+import object_store
+
+class AvailabilityDataSource:
+ """Uses API data sources generated by a ChromeVersionDataSource in order to
+ search the filesystem for the earliest existence of a specified API throughout
+ the different versions of Chrome; this constitutes an API's availability.
+ """
+
+ def __init__(self, version_data_source, version, object_store):
+ self._version_data_source = version_data_source
+ self._version = version
+ self._object_store = object_store
+
+ def _CheckExistence(self, api_name, version):
+ """Tries to 'get' an api from the filesystem, and reports whether or not it
+ was successful.
+ """
+ api_data_source = self._version_data_source.GetDataSourceForVersion(
+ str(version))
+ try:
+ api_data_source.TryGet(api_name)
+ except FileNotFoundError:
+ try:
+ api_data_source.TryGet(api_name, try_non_unix=True)
+ except FileNotFoundError:
+ return False
+ return True
+
+ def FindEarliestAvailability(self, api_name):
+ """Searches in descending order through filesystem caches tied to specific
+ chrome version numbers and looks for the existence of a specified api,
+ |api_name|. When an api is not found, returns the previous version number
+ (the last known version where the api was found).
+ """
+ availability = self._object_store.Get(
+ api_name,
+ object_store.AVAILABILITY_DATA_SOURCE).Get()
+
+ if availability is not None:
+ return availability
+ elif availability is False:
+ return None
+
+ if self._version == 'trunk':
+ if not self._CheckExistence(api_name, 'trunk'):
+ # If the API wasn't found in trunk, then it isn't currently available.
+ self._object_store.Set(api_name,
+ False,
+ object_store.AVAILABILITY_DATA_SOURCE)
+ return None
+
+ if self._version == 'trunk':
+ latest_version = self._version_data_source.GetLatestVersionNumber()
+ version_int = latest_version
+ else:
+ version_int = int(self._version)
+
+ # Extension APIs are not present in the filesystem before version 18.
+ while version_int >= 18:
+ if not self._CheckExistence(api_name, version_int):
+ break
+ version_int -= 1
+
+ version_int += 1
+ # If the version number is greater than the current version of Chrome, then
+ # the API was not found in the current version.
+ if self._version == 'trunk':
+ if version_int > latest_version:
+ availability = 'trunk'
+ else:
+ availability = str(version_int)
+ elif version_int <= int(self._version):
cduvall 2013/03/28 22:18:35 can this just be an else?
epeterson 2013/03/28 23:50:36 An else block would run if the generated version w
+ availability = str(version_int)
+
+ self._object_store.Set(api_name,
+ availability,
+ object_store.AVAILABILITY_DATA_SOURCE)
+ return availability

Powered by Google App Engine
This is Rietveld 408576698