| 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..3ee4aef2f3936f96c5d9faeac61c3fd5bd90a5f9 100644
|
| --- a/chrome/browser/extensions/extension_special_storage_policy.cc
|
| +++ b/chrome/browser/extensions/extension_special_storage_policy.cc
|
| @@ -7,26 +7,73 @@
|
| #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_status_code.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) {
|
| + if (code == storage::kQuotaStatusOk) {
|
| + // 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 =
|
| + browser_context ? // |browser_context| can be NULL in unittests.
|
| + content::BrowserContext::GetStoragePartitionForSite(browser_context,
|
| + launch_url) :
|
| + NULL;
|
| + 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 +148,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 +172,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))
|
|
|