OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 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 (function() { |
| 6 'use strict'; |
| 7 |
| 8 Polymer({ |
| 9 is: 'website-usage-private-api', |
| 10 |
| 11 properties: { |
| 12 /** |
| 13 * The amount of data used by the given website. |
| 14 */ |
| 15 websiteDataUsage: { |
| 16 type: String, |
| 17 notify: true, |
| 18 }, |
| 19 }, |
| 20 |
| 21 attached: function() { |
| 22 settings.WebsiteUsagePrivateApi.websiteUsagePolymerInstance = this; |
| 23 }, |
| 24 |
| 25 fetchUsageTotal: function(origin) { |
| 26 settings.WebsiteUsagePrivateApi.fetchUsageTotal(origin); |
| 27 }, |
| 28 }); |
| 29 })(); |
| 30 |
| 31 cr.define('settings.WebsiteUsagePrivateApi', function() { |
| 32 /** |
| 33 * @type {Object} An instance of the polymer object defined above. |
| 34 * All data will be set here. |
| 35 */ |
| 36 websiteUsagePolymerInstance = null; |
| 37 |
| 38 /** |
| 39 * Encapsulates the calls between JS and C++ to fetch how much storage the |
| 40 * origin is using. |
| 41 * Will update the data in |websiteUsagePolymerInstance|. |
| 42 */ |
| 43 fetchUsageTotal = function(origin) { |
| 44 chrome.send('fetchUsageTotal', [origin]); |
| 45 }; |
| 46 |
| 47 /** |
| 48 * Callback for when the usage total is known. |
| 49 * @param {string} usage The string showing how much data the given origin |
| 50 * is using. |
| 51 */ |
| 52 returnUsageTotal = function(usage) { |
| 53 var instance = settings.WebsiteUsagePrivateApi.websiteUsagePolymerInstance; |
| 54 if (instance == null) { |
| 55 return; |
| 56 } |
| 57 |
| 58 instance.websiteDataUsage = usage; |
| 59 }; |
| 60 |
| 61 return { websiteUsagePolymerInstance: websiteUsagePolymerInstance, |
| 62 fetchUsageTotal: fetchUsageTotal, |
| 63 returnUsageTotal: returnUsageTotal }; |
| 64 }); |
OLD | NEW |