Suppress tabs permission warning if there is already a browsingHistory warning.
[chromium-blink-merge.git] / chrome / common / extensions / docs / server2 / whats_new_data_source.py
blob7d67a204b0760b68afea0aa106c0bbcf696b0d8c
1 # Copyright 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.
5 from itertools import groupby
6 from operator import itemgetter
7 import posixpath
9 from data_source import DataSource
10 from extensions_paths import JSON_TEMPLATES, PUBLIC_TEMPLATES
11 from future import Future
14 class WhatsNewDataSource(DataSource):
15 ''' This class creates a list of "what is new" by chrome version.
16 '''
18 def __init__(self, server_instance, _):
19 self._parse_cache = server_instance.compiled_fs_factory.ForJson(
20 server_instance.host_file_system_provider.GetTrunk())
21 self._object_store = server_instance.object_store_creator.Create(
22 WhatsNewDataSource)
23 self._api_models = server_instance.api_models
24 self._availability_finder = server_instance.availability_finder
25 self._api_categorizer = server_instance.api_categorizer
27 def _GenerateChangesListWithVersion(self, platform, whats_new_json):
28 return [{
29 'id': change_id,
30 'type': change['type'],
31 'description': change['description'],
32 'version': change['version']
33 } for change_id, change in whats_new_json.iteritems()]
35 def _GetApiVersion(self, platform, api_name):
36 version = None
37 category = self._api_categorizer.GetCategory(platform, api_name)
38 if category == 'chrome':
39 channel_info = self._availability_finder.GetApiAvailability(api_name)
40 channel = channel_info.channel
41 if channel == 'stable':
42 version = channel_info.version
43 return version
45 def _GenerateApiListWithVersion(self, platform):
46 data = []
47 for api_name, api_model in self._api_models.IterModels():
48 version = self._GetApiVersion(platform, api_name)
49 if version:
50 api = {
51 'name': api_name,
52 'description': api_model.description,
53 'version' : version,
54 'type': 'apis',
56 data.append(api)
57 data.sort(key=itemgetter('version'))
58 return data
60 def _GenerateWhatsNewDict(self):
61 whats_new_json_future = self._parse_cache.GetFromFile(
62 posixpath.join(JSON_TEMPLATES, 'whats_new.json'))
63 def _MakeDictByPlatform(platform):
64 whats_new_json = whats_new_json_future.Get()
65 platform_list = []
66 apis = self._GenerateApiListWithVersion(platform)
67 apis.extend(self._GenerateChangesListWithVersion(platform,
68 whats_new_json))
69 apis.sort(key=itemgetter('version'), reverse=True)
70 for version, group in groupby(apis, key=itemgetter('version')):
71 whats_new_by_version = {
72 'version': version,
74 for item in group:
75 item_type = item['type']
76 if item_type not in whats_new_by_version:
77 whats_new_by_version[item_type] = []
78 whats_new_by_version[item_type].append(item)
79 platform_list.append(whats_new_by_version)
80 return platform_list
82 def resolve():
83 return {
84 'apps': _MakeDictByPlatform('apps'),
85 'extensions': _MakeDictByPlatform('extensions')
87 return Future(callback=resolve)
89 def _GetCachedWhatsNewData(self):
90 data = self._object_store.Get('whats_new_data').Get()
91 if data is None:
92 data = self._GenerateWhatsNewDict().Get()
93 self._object_store.Set('whats_new_data', data)
94 return data
96 def get(self, key):
97 return self._GetCachedWhatsNewData().get(key)
99 def Cron(self):
100 return self._GenerateWhatsNewDict()