Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Side by Side Diff: chrome/browser/extensions/extension_storage_monitor.cc

Issue 1497193002: Remove all the ephemeral apps code. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Self review, Devlin review. Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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_storage_monitor.h" 5 #include "chrome/browser/extensions/extension_storage_monitor.h"
6 6
7 #include <map> 7 #include <map>
8 8
9 #include "base/metrics/histogram.h" 9 #include "base/metrics/histogram.h"
10 #include "base/strings/string_number_conversions.h" 10 #include "base/strings/string_number_conversions.h"
(...skipping 28 matching lines...) Expand all
39 39
40 using content::BrowserThread; 40 using content::BrowserThread;
41 41
42 namespace extensions { 42 namespace extensions {
43 43
44 namespace { 44 namespace {
45 45
46 // The rate at which we would like to observe storage events. 46 // The rate at which we would like to observe storage events.
47 const int kStorageEventRateSec = 30; 47 const int kStorageEventRateSec = 30;
48 48
49 // Set the thresholds for the first notification. Ephemeral apps have a lower 49 // Set the thresholds for the first notification. Once a threshold is exceeded,
50 // threshold than installed extensions and apps. Once a threshold is exceeded,
51 // it will be doubled to throttle notifications. 50 // it will be doubled to throttle notifications.
52 const int64 kMBytes = 1024 * 1024; 51 const int64 kMBytes = 1024 * 1024;
53 const int64 kEphemeralAppInitialThreshold = 250 * kMBytes;
54 const int64 kExtensionInitialThreshold = 1000 * kMBytes; 52 const int64 kExtensionInitialThreshold = 1000 * kMBytes;
55 53
56 // Notifications have an ID so that we can update them. 54 // Notifications have an ID so that we can update them.
57 const char kNotificationIdFormat[] = "ExtensionStorageMonitor-$1-$2"; 55 const char kNotificationIdFormat[] = "ExtensionStorageMonitor-$1-$2";
58 const char kSystemNotifierId[] = "ExtensionStorageMonitor"; 56 const char kSystemNotifierId[] = "ExtensionStorageMonitor";
59 57
60 // A preference that stores the next threshold for displaying a notification 58 // A preference that stores the next threshold for displaying a notification
61 // when an extension or app consumes excessive disk space. This will not be 59 // when an extension or app consumes excessive disk space. This will not be
62 // set until the extension/app reaches the initial threshold. 60 // set until the extension/app reaches the initial threshold.
63 const char kPrefNextStorageThreshold[] = "next_storage_threshold"; 61 const char kPrefNextStorageThreshold[] = "next_storage_threshold";
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
270 // static 268 // static
271 ExtensionStorageMonitor* ExtensionStorageMonitor::Get( 269 ExtensionStorageMonitor* ExtensionStorageMonitor::Get(
272 content::BrowserContext* context) { 270 content::BrowserContext* context) {
273 return ExtensionStorageMonitorFactory::GetForBrowserContext(context); 271 return ExtensionStorageMonitorFactory::GetForBrowserContext(context);
274 } 272 }
275 273
276 ExtensionStorageMonitor::ExtensionStorageMonitor( 274 ExtensionStorageMonitor::ExtensionStorageMonitor(
277 content::BrowserContext* context) 275 content::BrowserContext* context)
278 : enable_for_all_extensions_(false), 276 : enable_for_all_extensions_(false),
279 initial_extension_threshold_(kExtensionInitialThreshold), 277 initial_extension_threshold_(kExtensionInitialThreshold),
280 initial_ephemeral_threshold_(kEphemeralAppInitialThreshold),
281 observer_rate_(base::TimeDelta::FromSeconds(kStorageEventRateSec)), 278 observer_rate_(base::TimeDelta::FromSeconds(kStorageEventRateSec)),
282 context_(context), 279 context_(context),
283 extension_prefs_(ExtensionPrefs::Get(context)), 280 extension_prefs_(ExtensionPrefs::Get(context)),
284 extension_registry_observer_(this), 281 extension_registry_observer_(this),
285 weak_ptr_factory_(this) { 282 weak_ptr_factory_(this) {
286 DCHECK(extension_prefs_); 283 DCHECK(extension_prefs_);
287 284
288 registrar_.Add(this, chrome::NOTIFICATION_PROFILE_DESTROYED, 285 registrar_.Add(this, chrome::NOTIFICATION_PROFILE_DESTROYED,
289 content::Source<content::BrowserContext>(context_)); 286 content::Source<content::BrowserContext>(context_));
290 287
(...skipping 26 matching lines...) Expand all
317 content::BrowserContext* browser_context, 314 content::BrowserContext* browser_context,
318 const Extension* extension, 315 const Extension* extension,
319 UnloadedExtensionInfo::Reason reason) { 316 UnloadedExtensionInfo::Reason reason) {
320 StopMonitoringStorage(extension->id()); 317 StopMonitoringStorage(extension->id());
321 } 318 }
322 319
323 void ExtensionStorageMonitor::OnExtensionWillBeInstalled( 320 void ExtensionStorageMonitor::OnExtensionWillBeInstalled(
324 content::BrowserContext* browser_context, 321 content::BrowserContext* browser_context,
325 const Extension* extension, 322 const Extension* extension,
326 bool is_update, 323 bool is_update,
327 bool from_ephemeral,
328 const std::string& old_name) { 324 const std::string& old_name) {
329 // If an ephemeral app was promoted to a regular installed app, we may need to 325 if (!ShouldMonitorStorageFor(extension))
330 // increase its next threshold.
331 if (!from_ephemeral || !ShouldMonitorStorageFor(extension))
332 return; 326 return;
333 327
334 if (!enable_for_all_extensions_) { 328 if (!enable_for_all_extensions_) {
335 // If monitoring is not enabled for installed extensions, just stop 329 // If monitoring is not enabled for installed extensions, just stop
336 // monitoring. 330 // monitoring.
337 SetNextStorageThreshold(extension->id(), 0); 331 SetNextStorageThreshold(extension->id(), 0);
338 StopMonitoringStorage(extension->id()); 332 StopMonitoringStorage(extension->id());
339 return; 333 return;
340 } 334 }
341 335
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
487 481
488 message_center::MessageCenter::Get()->RemoveNotification( 482 message_center::MessageCenter::Get()->RemoveNotification(
489 GetNotificationId(extension_id), false); 483 GetNotificationId(extension_id), false);
490 } 484 }
491 485
492 void ExtensionStorageMonitor::StartMonitoringStorage( 486 void ExtensionStorageMonitor::StartMonitoringStorage(
493 const Extension* extension) { 487 const Extension* extension) {
494 if (!ShouldMonitorStorageFor(extension)) 488 if (!ShouldMonitorStorageFor(extension))
495 return; 489 return;
496 490
497 // First apply this feature only to experimental ephemeral apps. If it works 491 bool should_enforce = (enable_for_all_extensions_) &&
498 // well, roll it out to all extensions and apps. 492 IsStorageNotificationEnabled(extension->id());
499 bool should_enforce =
500 (enable_for_all_extensions_ ||
501 extension_prefs_->IsEphemeralApp(extension->id())) &&
502 IsStorageNotificationEnabled(extension->id());
503 493
504 bool for_metrics = ShouldGatherMetricsFor(extension); 494 bool for_metrics = ShouldGatherMetricsFor(extension);
505 495
506 if (!should_enforce && !for_metrics) 496 if (!should_enforce && !for_metrics)
507 return; // Don't track this extension. 497 return; // Don't track this extension.
508 498
509 // Lazily create the storage monitor proxy on the IO thread. 499 // Lazily create the storage monitor proxy on the IO thread.
510 if (!storage_observer_.get()) { 500 if (!storage_observer_.get()) {
511 storage_observer_ = 501 storage_observer_ =
512 new StorageEventObserver(weak_ptr_factory_.GetWeakPtr()); 502 new StorageEventObserver(weak_ptr_factory_.GetWeakPtr());
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
609 extension, extensions::UNINSTALL_REASON_STORAGE_THRESHOLD_EXCEEDED, 599 extension, extensions::UNINSTALL_REASON_STORAGE_THRESHOLD_EXCEEDED,
610 UNINSTALL_SOURCE_STORAGE_THRESHOLD_EXCEEDED); 600 UNINSTALL_SOURCE_STORAGE_THRESHOLD_EXCEEDED);
611 } 601 }
612 602
613 int64 ExtensionStorageMonitor::GetNextStorageThreshold( 603 int64 ExtensionStorageMonitor::GetNextStorageThreshold(
614 const std::string& extension_id) const { 604 const std::string& extension_id) const {
615 int next_threshold = GetNextStorageThresholdFromPrefs(extension_id); 605 int next_threshold = GetNextStorageThresholdFromPrefs(extension_id);
616 if (next_threshold == 0) { 606 if (next_threshold == 0) {
617 // The next threshold is written to the prefs after the initial threshold is 607 // The next threshold is written to the prefs after the initial threshold is
618 // exceeded. 608 // exceeded.
619 next_threshold = extension_prefs_->IsEphemeralApp(extension_id) 609 next_threshold = initial_extension_threshold_;
620 ? initial_ephemeral_threshold_
621 : initial_extension_threshold_;
622 } 610 }
623 return next_threshold; 611 return next_threshold;
624 } 612 }
625 613
626 void ExtensionStorageMonitor::SetNextStorageThreshold( 614 void ExtensionStorageMonitor::SetNextStorageThreshold(
627 const std::string& extension_id, 615 const std::string& extension_id,
628 int64 next_threshold) { 616 int64 next_threshold) {
629 extension_prefs_->UpdateExtensionPref( 617 extension_prefs_->UpdateExtensionPref(
630 extension_id, 618 extension_id,
631 kPrefNextStorageThreshold, 619 kPrefNextStorageThreshold,
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
664 void ExtensionStorageMonitor::SetStorageNotificationEnabled( 652 void ExtensionStorageMonitor::SetStorageNotificationEnabled(
665 const std::string& extension_id, 653 const std::string& extension_id,
666 bool enable_notifications) { 654 bool enable_notifications) {
667 extension_prefs_->UpdateExtensionPref( 655 extension_prefs_->UpdateExtensionPref(
668 extension_id, 656 extension_id,
669 kPrefDisableStorageNotifications, 657 kPrefDisableStorageNotifications,
670 enable_notifications ? NULL : new base::FundamentalValue(true)); 658 enable_notifications ? NULL : new base::FundamentalValue(true));
671 } 659 }
672 660
673 } // namespace extensions 661 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698