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

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: 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..8c524adf0dcc29ad1648e16cec24f7b09185897e
--- /dev/null
+++ b/chrome/common/extensions/docs/server2/availability_data_source.py
@@ -0,0 +1,50 @@
+# Copyright (c) 2012 The Chromium Authors. All rights reserved.
+# 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:
+ def __init__(self,
+ version_data_source,
+ version_number,
+ object_store):
+ self._version_data_source = version_data_source
+ self._version_number = version_number
+ self._object_store = object_store
+
+ 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).
+ """
+ version = self._object_store.Get(
+ api_name,
+ object_store.AVAILABILITY_DATA_SOURCE).Get()
+
+ if version is not None:
+ return version
+
+ 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.
+ 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.
+ api_data_source = self._version_data_source.GetDataSourceForVersion(
+ "%d" % version)
cduvall 2013/03/21 18:43:53 single quotes
epeterson 2013/03/25 19:35:11 Done.
+ try:
+ api_data_source.tryGet(api_name)
+ 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
+ except FileNotFoundError:
+ try:
+ api_data_source.tryGet(api_name, tryNonUnix=True)
+ version -= 1
+ except FileNotFoundError:
+ break
+
+ version += 1
+ #if version > self._version_number: api was not found in the current version
+ version = "%d" % version
+ self._object_store.Set(api_name,
+ version,
+ object_store.AVAILABILITY_DATA_SOURCE)
+ return version

Powered by Google App Engine
This is Rietveld 408576698