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

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

Issue 282103003: Moved IS_EPHEMERAL flag to extension prefs (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Minor refactoring. Added comments. Created 6 years, 7 months 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/strings/string_number_conversions.h" 9 #include "base/strings/string_number_conversions.h"
10 #include "base/strings/string_util.h" 10 #include "base/strings/string_util.h"
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 content::Details<const Extension>(details).ptr(); 204 content::Details<const Extension>(details).ptr();
205 RemoveNotificationForExtension(extension->id()); 205 RemoveNotificationForExtension(extension->id());
206 break; 206 break;
207 } 207 }
208 case chrome::NOTIFICATION_PROFILE_DESTROYED: { 208 case chrome::NOTIFICATION_PROFILE_DESTROYED: {
209 StopMonitoringAll(); 209 StopMonitoringAll();
210 break; 210 break;
211 } 211 }
212 default: 212 default:
213 NOTREACHED(); 213 NOTREACHED();
214 }; 214 }
215 } 215 }
216 216
217 void ExtensionStorageMonitor::OnExtensionLoaded( 217 void ExtensionStorageMonitor::OnExtensionLoaded(
218 content::BrowserContext* browser_context, 218 content::BrowserContext* browser_context,
219 const Extension* extension) { 219 const Extension* extension) {
220 DCHECK(extension); 220 DCHECK(extension);
221 StartMonitoringStorage(extension); 221 StartMonitoringStorage(extension);
222 } 222 }
223 223
224 void ExtensionStorageMonitor::OnExtensionUnloaded( 224 void ExtensionStorageMonitor::OnExtensionUnloaded(
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
317 317
318 void ExtensionStorageMonitor::OnNotificationButtonClick( 318 void ExtensionStorageMonitor::OnNotificationButtonClick(
319 const std::string& extension_id, int button_index) { 319 const std::string& extension_id, int button_index) {
320 switch (button_index) { 320 switch (button_index) {
321 case BUTTON_DISABLE_NOTIFICATION: { 321 case BUTTON_DISABLE_NOTIFICATION: {
322 DisableStorageMonitoring(extension_id); 322 DisableStorageMonitoring(extension_id);
323 break; 323 break;
324 } 324 }
325 default: 325 default:
326 NOTREACHED(); 326 NOTREACHED();
327 }; 327 }
328 } 328 }
329 329
330 void ExtensionStorageMonitor::DisableStorageMonitoring( 330 void ExtensionStorageMonitor::DisableStorageMonitoring(
331 const std::string& extension_id) { 331 const std::string& extension_id) {
332 StopMonitoringStorage(extension_id); 332 StopMonitoringStorage(extension_id);
333 333
334 ExtensionPrefs* prefs = ExtensionPrefs::Get(context_); 334 ExtensionPrefs* prefs = ExtensionPrefs::Get(context_);
335 DCHECK(prefs); 335 DCHECK(prefs);
336 prefs->SetStorageNotificationEnabled(extension_id, false); 336 prefs->SetStorageNotificationEnabled(extension_id, false);
337 337
338 message_center::MessageCenter::Get()->RemoveNotification( 338 message_center::MessageCenter::Get()->RemoveNotification(
339 GetNotificationId(extension_id), false); 339 GetNotificationId(extension_id), false);
340 } 340 }
341 341
342 void ExtensionStorageMonitor::StartMonitoringStorage( 342 void ExtensionStorageMonitor::StartMonitoringStorage(
343 const Extension* extension) { 343 const Extension* extension) {
344 if (!extension->HasAPIPermission(APIPermission::kUnlimitedStorage)) 344 if (!extension->HasAPIPermission(APIPermission::kUnlimitedStorage))
345 return; 345 return;
346 346
347 // Do not monitor storage for component extensions. 347 // Do not monitor storage for component extensions.
348 if (extension->location() == Manifest::COMPONENT) 348 if (extension->location() == Manifest::COMPONENT)
349 return; 349 return;
350 350
351 // First apply this feature only to experimental ephemeral apps. If it works
352 // well, roll it out to all extensions and apps.
353 if (!extension->is_ephemeral() && !enable_for_all_extensions_)
354 return;
355
356 ExtensionPrefs* prefs = ExtensionPrefs::Get(context_); 351 ExtensionPrefs* prefs = ExtensionPrefs::Get(context_);
357 DCHECK(prefs); 352 DCHECK(prefs);
353
354 // First apply this feature only to experimental ephemeral apps. If it works
355 // well, roll it out to all extensions and apps.
356 bool is_ephemeral = prefs->IsEphemeralApp(extension->id());
357 if (!is_ephemeral && !enable_for_all_extensions_)
358 return;
359
358 if (!prefs->IsStorageNotificationEnabled(extension->id())) 360 if (!prefs->IsStorageNotificationEnabled(extension->id()))
359 return; 361 return;
360 362
361 // Lazily create the storage monitor proxy on the IO thread. 363 // Lazily create the storage monitor proxy on the IO thread.
362 if (!storage_observer_.get()) { 364 if (!storage_observer_.get()) {
363 storage_observer_ = 365 storage_observer_ =
364 new StorageEventObserver(weak_ptr_factory_.GetWeakPtr()); 366 new StorageEventObserver(weak_ptr_factory_.GetWeakPtr());
365 } 367 }
366 368
367 GURL site_url = 369 GURL site_url =
368 extensions::util::GetSiteForExtensionId(extension->id(), context_); 370 extensions::util::GetSiteForExtensionId(extension->id(), context_);
369 content::StoragePartition* storage_partition = 371 content::StoragePartition* storage_partition =
370 content::BrowserContext::GetStoragePartitionForSite(context_, site_url); 372 content::BrowserContext::GetStoragePartitionForSite(context_, site_url);
371 DCHECK(storage_partition); 373 DCHECK(storage_partition);
372 scoped_refptr<quota::QuotaManager> quota_manager( 374 scoped_refptr<quota::QuotaManager> quota_manager(
373 storage_partition->GetQuotaManager()); 375 storage_partition->GetQuotaManager());
374 376
375 GURL storage_origin(site_url.GetOrigin()); 377 GURL storage_origin(site_url.GetOrigin());
376 if (extension->is_hosted_app()) 378 if (extension->is_hosted_app())
377 storage_origin = AppLaunchInfo::GetLaunchWebURL(extension).GetOrigin(); 379 storage_origin = AppLaunchInfo::GetLaunchWebURL(extension).GetOrigin();
378 380
379 int next_threshold = prefs->GetNextStorageThreshold(extension->id()); 381 int next_threshold = prefs->GetNextStorageThreshold(extension->id());
380 if (next_threshold == 0) { 382 if (next_threshold == 0) {
381 // The next threshold is written to the prefs after the initial threshold is 383 // The next threshold is written to the prefs after the initial threshold is
382 // exceeded. 384 // exceeded.
383 next_threshold = extension->is_ephemeral() ? initial_ephemeral_threshold_ 385 next_threshold = is_ephemeral ? initial_ephemeral_threshold_
384 : initial_extension_threshold_; 386 : initial_extension_threshold_;
385 } 387 }
386 388
387 BrowserThread::PostTask( 389 BrowserThread::PostTask(
388 BrowserThread::IO, 390 BrowserThread::IO,
389 FROM_HERE, 391 FROM_HERE,
390 base::Bind(&StorageEventObserver::StartObservingForExtension, 392 base::Bind(&StorageEventObserver::StartObservingForExtension,
391 storage_observer_, 393 storage_observer_,
392 quota_manager, 394 quota_manager,
393 extension->id(), 395 extension->id(),
394 storage_origin, 396 storage_origin,
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
445 message_center::MessageCenter* center = message_center::MessageCenter::Get(); 447 message_center::MessageCenter* center = message_center::MessageCenter::Get();
446 DCHECK(center); 448 DCHECK(center);
447 for (std::set<std::string>::iterator it = notified_extension_ids_.begin(); 449 for (std::set<std::string>::iterator it = notified_extension_ids_.begin();
448 it != notified_extension_ids_.end(); ++it) { 450 it != notified_extension_ids_.end(); ++it) {
449 center->RemoveNotification(GetNotificationId(*it), false); 451 center->RemoveNotification(GetNotificationId(*it), false);
450 } 452 }
451 notified_extension_ids_.clear(); 453 notified_extension_ids_.clear();
452 } 454 }
453 455
454 } // namespace extensions 456 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698