Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #include "chrome/browser/extensions/extension_special_storage_policy.h" | 5 #include "chrome/browser/extensions/extension_special_storage_policy.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/memory/ref_counted.h" | |
| 11 #include "base/metrics/histogram.h" | |
| 10 #include "base/stl_util.h" | 12 #include "base/stl_util.h" |
| 11 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
| 12 #include "chrome/browser/content_settings/cookie_settings.h" | 14 #include "chrome/browser/content_settings/cookie_settings.h" |
| 13 #include "chrome/common/chrome_switches.h" | 15 #include "chrome/common/chrome_switches.h" |
| 14 #include "chrome/common/extensions/manifest_handlers/app_isolation_info.h" | 16 #include "chrome/common/extensions/manifest_handlers/app_isolation_info.h" |
| 17 #include "chrome/common/extensions/manifest_handlers/app_launch_info.h" | |
| 15 #include "chrome/common/url_constants.h" | 18 #include "chrome/common/url_constants.h" |
| 16 #include "components/content_settings/core/common/content_settings.h" | 19 #include "components/content_settings/core/common/content_settings.h" |
| 17 #include "components/content_settings/core/common/content_settings_types.h" | 20 #include "components/content_settings/core/common/content_settings_types.h" |
| 21 #include "content/public/browser/browser_context.h" | |
| 18 #include "content/public/browser/browser_thread.h" | 22 #include "content/public/browser/browser_thread.h" |
| 23 #include "content/public/browser/storage_partition.h" | |
| 19 #include "content/public/common/url_constants.h" | 24 #include "content/public/common/url_constants.h" |
| 20 #include "extensions/common/constants.h" | 25 #include "extensions/common/constants.h" |
| 21 #include "extensions/common/extension.h" | 26 #include "extensions/common/extension.h" |
| 22 #include "extensions/common/extension_set.h" | 27 #include "extensions/common/extension_set.h" |
| 23 #include "extensions/common/permissions/permissions_data.h" | 28 #include "extensions/common/permissions/permissions_data.h" |
| 29 #include "storage/browser/quota/quota_manager.h" | |
| 30 #include "storage/common/quota/quota_types.h" | |
| 24 | 31 |
| 25 using content::BrowserThread; | 32 using content::BrowserThread; |
| 26 using extensions::APIPermission; | 33 using extensions::APIPermission; |
| 27 using extensions::Extension; | 34 using extensions::Extension; |
| 28 using storage::SpecialStoragePolicy; | 35 using storage::SpecialStoragePolicy; |
| 29 | 36 |
| 37 namespace { | |
| 38 | |
| 39 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.
| |
| 40 // We're interested in the amount of space hosted apps are using. Record it | |
| 41 // when the extension is granted the unlimited storage permission (once per | |
| 42 // extension load, so on average once per run). | |
| 43 UMA_HISTOGRAM_MEMORY_KB("Extensions.HostedAppUnlimitedStorageUsage", usage); | |
| 44 } | |
| 45 | |
| 46 // Log the usage for a hosted app with unlimited storage. | |
| 47 void LogHostedAppUnlimitedStorageUsage( | |
| 48 scoped_refptr<const Extension> extension, | |
| 49 content::BrowserContext* browser_context) { | |
| 50 GURL launch_url = | |
| 51 extensions::AppLaunchInfo::GetLaunchWebURL(extension.get()).GetOrigin(); | |
| 52 content::StoragePartition* partition = | |
| 53 content::BrowserContext::GetStoragePartitionForSite(browser_context, | |
| 54 launch_url); | |
| 55 if (partition) { | |
| 56 // We only have to query for kStorageTypePersistent data usage, because apps | |
| 57 // cannot ask for any more temporary storage, according to | |
| 58 // https://developers.google.com/chrome/whitepapers/storage. | |
| 59 BrowserThread::PostTask( | |
| 60 BrowserThread::IO, | |
| 61 FROM_HERE, | |
| 62 base::Bind(&storage::QuotaManager::GetUsageAndQuotaForWebApps, | |
| 63 partition->GetQuotaManager(), | |
| 64 launch_url, | |
| 65 storage::kStorageTypePersistent, | |
| 66 base::Bind(&ReportQuotaUsage))); | |
| 67 } | |
| 68 } | |
| 69 | |
| 70 } // namespace | |
| 71 | |
| 30 ExtensionSpecialStoragePolicy::ExtensionSpecialStoragePolicy( | 72 ExtensionSpecialStoragePolicy::ExtensionSpecialStoragePolicy( |
| 31 CookieSettings* cookie_settings) | 73 CookieSettings* cookie_settings) |
| 32 : cookie_settings_(cookie_settings) {} | 74 : cookie_settings_(cookie_settings) {} |
| 33 | 75 |
| 34 ExtensionSpecialStoragePolicy::~ExtensionSpecialStoragePolicy() {} | 76 ExtensionSpecialStoragePolicy::~ExtensionSpecialStoragePolicy() {} |
| 35 | 77 |
| 36 bool ExtensionSpecialStoragePolicy::IsStorageProtected(const GURL& origin) { | 78 bool ExtensionSpecialStoragePolicy::IsStorageProtected(const GURL& origin) { |
| 37 if (origin.SchemeIs(extensions::kExtensionScheme)) | 79 if (origin.SchemeIs(extensions::kExtensionScheme)) |
| 38 return true; | 80 return true; |
| 39 base::AutoLock locker(lock_); | 81 base::AutoLock locker(lock_); |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 94 } | 136 } |
| 95 | 137 |
| 96 const extensions::ExtensionSet* | 138 const extensions::ExtensionSet* |
| 97 ExtensionSpecialStoragePolicy::ExtensionsProtectingOrigin( | 139 ExtensionSpecialStoragePolicy::ExtensionsProtectingOrigin( |
| 98 const GURL& origin) { | 140 const GURL& origin) { |
| 99 base::AutoLock locker(lock_); | 141 base::AutoLock locker(lock_); |
| 100 return protected_apps_.ExtensionsContaining(origin); | 142 return protected_apps_.ExtensionsContaining(origin); |
| 101 } | 143 } |
| 102 | 144 |
| 103 void ExtensionSpecialStoragePolicy::GrantRightsForExtension( | 145 void ExtensionSpecialStoragePolicy::GrantRightsForExtension( |
| 104 const extensions::Extension* extension) { | 146 const extensions::Extension* extension, |
| 147 content::BrowserContext* browser_context) { | |
| 105 DCHECK(extension); | 148 DCHECK(extension); |
| 106 if (!(NeedsProtection(extension) || | 149 if (!(NeedsProtection(extension) || |
| 107 extension->permissions_data()->HasAPIPermission( | 150 extension->permissions_data()->HasAPIPermission( |
| 108 APIPermission::kUnlimitedStorage) || | 151 APIPermission::kUnlimitedStorage) || |
| 109 extension->permissions_data()->HasAPIPermission( | 152 extension->permissions_data()->HasAPIPermission( |
| 110 APIPermission::kFileBrowserHandler) || | 153 APIPermission::kFileBrowserHandler) || |
| 111 extensions::AppIsolationInfo::HasIsolatedStorage(extension) || | 154 extensions::AppIsolationInfo::HasIsolatedStorage(extension) || |
| 112 extension->is_app())) { | 155 extension->is_app())) { |
| 113 return; | 156 return; |
| 114 } | 157 } |
| 115 | 158 |
| 116 int change_flags = 0; | 159 int change_flags = 0; |
| 117 { | 160 { |
| 118 base::AutoLock locker(lock_); | 161 base::AutoLock locker(lock_); |
| 119 if (NeedsProtection(extension) && protected_apps_.Add(extension)) | 162 if (NeedsProtection(extension) && protected_apps_.Add(extension)) |
| 120 change_flags |= SpecialStoragePolicy::STORAGE_PROTECTED; | 163 change_flags |= SpecialStoragePolicy::STORAGE_PROTECTED; |
| 121 // FIXME: Does GrantRightsForExtension imply |extension| is installed? | 164 // FIXME: Does GrantRightsForExtension imply |extension| is installed? |
| 122 if (extension->is_app()) | 165 if (extension->is_app()) |
| 123 installed_apps_.Add(extension); | 166 installed_apps_.Add(extension); |
| 124 | 167 |
| 125 if (extension->permissions_data()->HasAPIPermission( | 168 if (extension->permissions_data()->HasAPIPermission( |
| 126 APIPermission::kUnlimitedStorage) && | 169 APIPermission::kUnlimitedStorage) && |
| 127 unlimited_extensions_.Add(extension)) | 170 unlimited_extensions_.Add(extension)) { |
| 171 if (extension->is_hosted_app()) | |
| 172 LogHostedAppUnlimitedStorageUsage(extension, browser_context); | |
| 173 | |
| 128 change_flags |= SpecialStoragePolicy::STORAGE_UNLIMITED; | 174 change_flags |= SpecialStoragePolicy::STORAGE_UNLIMITED; |
| 175 } | |
| 129 | 176 |
| 130 if (extension->permissions_data()->HasAPIPermission( | 177 if (extension->permissions_data()->HasAPIPermission( |
| 131 APIPermission::kFileBrowserHandler)) | 178 APIPermission::kFileBrowserHandler)) |
| 132 file_handler_extensions_.Add(extension); | 179 file_handler_extensions_.Add(extension); |
| 133 | 180 |
| 134 if (extensions::AppIsolationInfo::HasIsolatedStorage(extension)) | 181 if (extensions::AppIsolationInfo::HasIsolatedStorage(extension)) |
| 135 isolated_extensions_.Add(extension); | 182 isolated_extensions_.Add(extension); |
| 136 } | 183 } |
| 137 | 184 |
| 138 if (change_flags) { | 185 if (change_flags) { |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 281 | 328 |
| 282 void ExtensionSpecialStoragePolicy::SpecialCollection::Clear() { | 329 void ExtensionSpecialStoragePolicy::SpecialCollection::Clear() { |
| 283 ClearCache(); | 330 ClearCache(); |
| 284 extensions_.Clear(); | 331 extensions_.Clear(); |
| 285 } | 332 } |
| 286 | 333 |
| 287 void ExtensionSpecialStoragePolicy::SpecialCollection::ClearCache() { | 334 void ExtensionSpecialStoragePolicy::SpecialCollection::ClearCache() { |
| 288 STLDeleteValues(&cached_results_); | 335 STLDeleteValues(&cached_results_); |
| 289 cached_results_.clear(); | 336 cached_results_.clear(); |
| 290 } | 337 } |
| OLD | NEW |