Home | History | Annotate | Download | only in extensions
      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
      3 // found in the LICENSE file.
      4 
      5 #include "chrome/browser/extensions/data_deleter.h"
      6 
      7 #include "chrome/browser/extensions/api/storage/settings_frontend.h"
      8 #include "chrome/browser/extensions/extension_service.h"
      9 #include "chrome/browser/profiles/profile.h"
     10 #include "chrome/common/extensions/extension.h"
     11 #include "content/public/browser/browser_context.h"
     12 #include "content/public/browser/browser_thread.h"
     13 #include "content/public/browser/storage_partition.h"
     14 #include "extensions/common/constants.h"
     15 #include "net/url_request/url_request_context_getter.h"
     16 
     17 using content::BrowserContext;
     18 using content::BrowserThread;
     19 using content::StoragePartition;
     20 
     21 namespace extensions {
     22 
     23 // static
     24 void DataDeleter::StartDeleting(Profile* profile,
     25                                 const std::string& extension_id,
     26                                 const GURL& storage_origin) {
     27   DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
     28   DCHECK(profile);
     29 
     30   const GURL& site = Extension::GetBaseURLFromExtensionId(extension_id);
     31 
     32   StoragePartition* partition =
     33       BrowserContext::GetStoragePartitionForSite(profile, site);
     34 
     35   if (storage_origin.SchemeIs(extensions::kExtensionScheme)) {
     36     // TODO(ajwong): Cookies are not properly isolated for
     37     // chrome-extension:// scheme.  (http://crbug.com/158386).
     38     //
     39     // However, no isolated apps actually can write to kExtensionScheme
     40     // origins. Thus, it is benign to delete from the
     41     // RequestContextForExtensions because there's nothing stored there. We
     42     // preserve this code path without checking for isolation because it's
     43     // simpler than special casing.  This code should go away once we merge
     44     // the various URLRequestContexts (http://crbug.com/159193).
     45     partition->ClearDataForOrigin(
     46         StoragePartition::REMOVE_DATA_MASK_ALL &
     47             (~StoragePartition::REMOVE_DATA_MASK_SHADER_CACHE),
     48         StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL,
     49         storage_origin,
     50         profile->GetRequestContextForExtensions());
     51   } else {
     52     // We don't need to worry about the media request context because that
     53     // shares the same cookie store as the main request context.
     54     partition->ClearDataForOrigin(
     55         StoragePartition::REMOVE_DATA_MASK_ALL &
     56             (~StoragePartition::REMOVE_DATA_MASK_SHADER_CACHE),
     57         StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL,
     58         storage_origin,
     59         partition->GetURLRequestContext());
     60   }
     61 
     62   // Begin removal of the settings for the current extension.
     63   profile->GetExtensionService()->settings_frontend()->
     64       DeleteStorageSoon(extension_id);
     65 }
     66 
     67 }  // namespace extensions
     68