Chromium Code Reviews| Index: chrome/browser/extensions/extension_special_storage_policy.cc |
| diff --git a/chrome/browser/extensions/extension_special_storage_policy.cc b/chrome/browser/extensions/extension_special_storage_policy.cc |
| index c0e5be9ba02f5b9188f7aadb65fc2e0e6e133a83..4b8d41e47daef2fb0f2f1c428a57b35accc47691 100644 |
| --- a/chrome/browser/extensions/extension_special_storage_policy.cc |
| +++ b/chrome/browser/extensions/extension_special_storage_policy.cc |
| @@ -7,26 +7,68 @@ |
| #include "base/bind.h" |
| #include "base/command_line.h" |
| #include "base/logging.h" |
| +#include "base/memory/ref_counted.h" |
| +#include "base/metrics/histogram.h" |
| #include "base/stl_util.h" |
| #include "base/strings/utf_string_conversions.h" |
| #include "chrome/browser/content_settings/cookie_settings.h" |
| #include "chrome/common/chrome_switches.h" |
| #include "chrome/common/extensions/manifest_handlers/app_isolation_info.h" |
| +#include "chrome/common/extensions/manifest_handlers/app_launch_info.h" |
| #include "chrome/common/url_constants.h" |
| #include "components/content_settings/core/common/content_settings.h" |
| #include "components/content_settings/core/common/content_settings_types.h" |
| +#include "content/public/browser/browser_context.h" |
| #include "content/public/browser/browser_thread.h" |
| +#include "content/public/browser/storage_partition.h" |
| #include "content/public/common/url_constants.h" |
| #include "extensions/common/constants.h" |
| #include "extensions/common/extension.h" |
| #include "extensions/common/extension_set.h" |
| #include "extensions/common/permissions/permissions_data.h" |
| +#include "storage/browser/quota/quota_manager.h" |
| +#include "storage/common/quota/quota_types.h" |
| using content::BrowserThread; |
| using extensions::APIPermission; |
| using extensions::Extension; |
| using storage::SpecialStoragePolicy; |
| +namespace { |
| + |
| +void ReportQuotaUsage(storage::QuotaStatusCode code, int64 usage, int64 quota) { |
|
Jeffrey Yasskin
2014/09/29 21:50:22
Handle status codes other than kQuotaStatusOk, pro
Devlin
2014/09/29 22:44:30
Done.
|
| + // We're interested in the amount of space hosted apps are using. Record it |
| + // when the extension is granted the unlimited storage permission (once per |
| + // extension load, so on average once per run). |
| + UMA_HISTOGRAM_MEMORY_KB("Extensions.HostedAppUnlimitedStorageUsage", usage); |
| +} |
| + |
| +// Log the usage for a hosted app with unlimited storage. |
| +void LogHostedAppUnlimitedStorageUsage( |
| + scoped_refptr<const Extension> extension, |
| + content::BrowserContext* browser_context) { |
| + GURL launch_url = |
| + extensions::AppLaunchInfo::GetLaunchWebURL(extension.get()).GetOrigin(); |
| + content::StoragePartition* partition = |
| + content::BrowserContext::GetStoragePartitionForSite(browser_context, |
| + launch_url); |
| + if (partition) { |
| + // We only have to query for kStorageTypePersistent data usage, because apps |
| + // cannot ask for any more temporary storage, according to |
| + // https://developers.google.com/chrome/whitepapers/storage. |
| + BrowserThread::PostTask( |
| + BrowserThread::IO, |
| + FROM_HERE, |
| + base::Bind(&storage::QuotaManager::GetUsageAndQuotaForWebApps, |
| + partition->GetQuotaManager(), |
| + launch_url, |
| + storage::kStorageTypePersistent, |
| + base::Bind(&ReportQuotaUsage))); |
| + } |
| +} |
| + |
| +} // namespace |
| + |
| ExtensionSpecialStoragePolicy::ExtensionSpecialStoragePolicy( |
| CookieSettings* cookie_settings) |
| : cookie_settings_(cookie_settings) {} |
| @@ -101,7 +143,8 @@ ExtensionSpecialStoragePolicy::ExtensionsProtectingOrigin( |
| } |
| void ExtensionSpecialStoragePolicy::GrantRightsForExtension( |
| - const extensions::Extension* extension) { |
| + const extensions::Extension* extension, |
| + content::BrowserContext* browser_context) { |
| DCHECK(extension); |
| if (!(NeedsProtection(extension) || |
| extension->permissions_data()->HasAPIPermission( |
| @@ -124,8 +167,12 @@ void ExtensionSpecialStoragePolicy::GrantRightsForExtension( |
| if (extension->permissions_data()->HasAPIPermission( |
| APIPermission::kUnlimitedStorage) && |
| - unlimited_extensions_.Add(extension)) |
| + unlimited_extensions_.Add(extension)) { |
| + if (extension->is_hosted_app()) |
| + LogHostedAppUnlimitedStorageUsage(extension, browser_context); |
| + |
| change_flags |= SpecialStoragePolicy::STORAGE_UNLIMITED; |
| + } |
| if (extension->permissions_data()->HasAPIPermission( |
| APIPermission::kFileBrowserHandler)) |