| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 (function() { | 5 (function() { |
| 6 'use strict'; | 6 'use strict'; |
| 7 | 7 |
| 8 Polymer({ | 8 Polymer({ |
| 9 is: 'website-usage-private-api', | 9 is: 'website-usage-private-api', |
| 10 | 10 |
| 11 properties: { | 11 properties: { |
| 12 /** | 12 /** |
| 13 * The amount of data used by the given website. | 13 * The amount of data used by the given website. |
| 14 */ | 14 */ |
| 15 websiteDataUsage: { | 15 websiteDataUsage: { |
| 16 type: String, | 16 type: String, |
| 17 notify: true, | 17 notify: true, |
| 18 }, | 18 }, |
| 19 |
| 20 /** |
| 21 * The type of data used by the given website. |
| 22 */ |
| 23 websiteStorageType: { |
| 24 type: Number, |
| 25 notify: true, |
| 26 }, |
| 19 }, | 27 }, |
| 20 | 28 |
| 21 attached: function() { | 29 attached: function() { |
| 22 settings.WebsiteUsagePrivateApi.websiteUsagePolymerInstance = this; | 30 settings.WebsiteUsagePrivateApi.websiteUsagePolymerInstance = this; |
| 23 }, | 31 }, |
| 24 | 32 |
| 25 /** @param {string} host */ | 33 /** @param {string} host */ |
| 26 fetchUsageTotal: function(host) { | 34 fetchUsageTotal: function(host) { |
| 27 settings.WebsiteUsagePrivateApi.fetchUsageTotal(host); | 35 settings.WebsiteUsagePrivateApi.fetchUsageTotal(host); |
| 28 }, | 36 }, |
| 37 |
| 38 /** @param {string} origin */ |
| 39 clearUsage: function(origin, type) { |
| 40 settings.WebsiteUsagePrivateApi.clearUsage(origin, type); |
| 41 }, |
| 29 }); | 42 }); |
| 30 })(); | 43 })(); |
| 31 | 44 |
| 32 cr.define('settings.WebsiteUsagePrivateApi', function() { | 45 cr.define('settings.WebsiteUsagePrivateApi', function() { |
| 33 /** | 46 /** |
| 34 * @type {Object} An instance of the polymer object defined above. | 47 * @type {Object} An instance of the polymer object defined above. |
| 35 * All data will be set here. | 48 * All data will be set here. |
| 36 */ | 49 */ |
| 37 var websiteUsagePolymerInstance = null; | 50 var websiteUsagePolymerInstance = null; |
| 38 | 51 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 53 | 66 |
| 54 hostName_ = host; | 67 hostName_ = host; |
| 55 chrome.send('fetchUsageTotal', [host]); | 68 chrome.send('fetchUsageTotal', [host]); |
| 56 }; | 69 }; |
| 57 | 70 |
| 58 /** | 71 /** |
| 59 * Callback for when the usage total is known. | 72 * Callback for when the usage total is known. |
| 60 * @param {string} host The host that the usage was fetched for. | 73 * @param {string} host The host that the usage was fetched for. |
| 61 * @param {string} usage The string showing how much data the given host | 74 * @param {string} usage The string showing how much data the given host |
| 62 * is using. | 75 * is using. |
| 76 * @param {number} type The storage type. |
| 63 */ | 77 */ |
| 64 var returnUsageTotal = function(host, usage) { | 78 var returnUsageTotal = function(host, usage, type) { |
| 65 var instance = settings.WebsiteUsagePrivateApi.websiteUsagePolymerInstance; | 79 var instance = settings.WebsiteUsagePrivateApi.websiteUsagePolymerInstance; |
| 66 if (instance == null) | 80 if (instance == null) |
| 67 return; | 81 return; |
| 68 | 82 |
| 69 if (hostName_ == host) | 83 if (hostName_ == host) { |
| 70 instance.websiteDataUsage = usage; | 84 instance.websiteDataUsage = usage; |
| 85 instance.websiteStorageType = type; |
| 86 } |
| 87 }; |
| 88 |
| 89 /** |
| 90 * Deletes the storage being used for a given origin. |
| 91 * @param {string} origin The origin to delete storage for. |
| 92 * @param {number} type The type of storage to delete. |
| 93 */ |
| 94 var clearUsage = function(origin, type) { |
| 95 chrome.send('clearUsage', [origin, type]); |
| 71 }; | 96 }; |
| 72 | 97 |
| 73 return { websiteUsagePolymerInstance: websiteUsagePolymerInstance, | 98 return { websiteUsagePolymerInstance: websiteUsagePolymerInstance, |
| 74 fetchUsageTotal: fetchUsageTotal, | 99 fetchUsageTotal: fetchUsageTotal, |
| 75 returnUsageTotal: returnUsageTotal }; | 100 returnUsageTotal: returnUsageTotal, |
| 101 clearUsage: clearUsage, }; |
| 76 }); | 102 }); |
| OLD | NEW |