Chromium Code Reviews| Index: chrome/browser/resources/settings/site_settings/website_usage_private_api.js |
| diff --git a/chrome/browser/resources/settings/site_settings/website_usage_private_api.js b/chrome/browser/resources/settings/site_settings/website_usage_private_api.js |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..9bb866ff0cb6a46acdfee49dec9df6465c52615f |
| --- /dev/null |
| +++ b/chrome/browser/resources/settings/site_settings/website_usage_private_api.js |
| @@ -0,0 +1,64 @@ |
| +// Copyright 2016 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. |
| + |
| +(function() { |
| +'use strict'; |
| + |
| +Polymer({ |
| + is: 'website-usage-private-api', |
| + |
| + properties: { |
| + /** |
| + * The amount of data used by the given website. |
| + */ |
| + websiteDataUsage: { |
| + type: String, |
| + notify: true, |
| + }, |
| + }, |
| + |
| + attached: function() { |
| + settings.WebsiteUsagePrivateApi.websiteUsagePolymerInstance = this; |
| + }, |
| + |
| + fetchUsageTotal: function(origin) { |
| + settings.WebsiteUsagePrivateApi.fetchUsageTotal(origin); |
| + }, |
| +}); |
| +})(); |
| + |
| +cr.define('settings.WebsiteUsagePrivateApi', function() { |
| + /** |
| + * @type {Object} An instance of the polymer object defined above. |
| + * All data will be set here. |
| + */ |
| + websiteUsagePolymerInstance = null; |
| + |
| + /** |
| + * Encapsulates the calls between JS and C++ to fetch how much storage the |
| + * origin is using. |
| + * Will update the data in |websiteUsagePolymerInstance|. |
| + */ |
| + fetchUsageTotal = function(origin) { |
| + chrome.send('fetchUsageTotal', [origin]); |
| + }; |
| + |
| + /** |
| + * Callback for when the usage total is known. |
| + * @param {string} usage The string showing how much data the given origin |
| + * is using. |
| + */ |
| + returnUsageTotal = function(usage) { |
| + var instance = settings.WebsiteUsagePrivateApi.websiteUsagePolymerInstance; |
| + if (instance == null) { |
| + return; |
| + } |
| + |
| + instance.websiteDataUsage = usage; |
|
michaelpg
2016/01/25 18:33:54
shouldn't we check that the origin is still the sa
Finnur
2016/01/26 15:54:53
Like so?
michaelpg
2016/01/27 06:37:46
Yeah, but no need to assert -- it's a valid sequen
Finnur
2016/01/27 10:27:26
Done.
|
| + }; |
| + |
| + return { websiteUsagePolymerInstance: websiteUsagePolymerInstance, |
| + fetchUsageTotal: fetchUsageTotal, |
| + returnUsageTotal: returnUsageTotal }; |
| +}); |