Home | History | Annotate | Download | only in browsing_data
      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/browsing_data/browsing_data_remover.h"
      6 
      7 #include <map>
      8 #include <set>
      9 #include <string>
     10 
     11 #include "base/bind.h"
     12 #include "base/bind_helpers.h"
     13 #include "base/callback.h"
     14 #include "base/logging.h"
     15 #include "base/prefs/pref_service.h"
     16 #include "chrome/browser/autofill/personal_data_manager_factory.h"
     17 #include "chrome/browser/browser_process.h"
     18 #include "chrome/browser/browsing_data/browsing_data_helper.h"
     19 #include "chrome/browser/chrome_notification_types.h"
     20 #include "chrome/browser/content_settings/host_content_settings_map.h"
     21 #include "chrome/browser/domain_reliability/service_factory.h"
     22 #include "chrome/browser/download/download_prefs.h"
     23 #include "chrome/browser/download/download_service_factory.h"
     24 #include "chrome/browser/history/history_service.h"
     25 #include "chrome/browser/history/history_service_factory.h"
     26 #include "chrome/browser/io_thread.h"
     27 #include "chrome/browser/media/media_device_id_salt.h"
     28 #include "chrome/browser/net/predictor.h"
     29 #include "chrome/browser/password_manager/password_store_factory.h"
     30 #include "chrome/browser/predictors/logged_in_predictor_table.h"
     31 #include "chrome/browser/predictors/predictor_database.h"
     32 #include "chrome/browser/predictors/predictor_database_factory.h"
     33 #include "chrome/browser/prerender/prerender_manager.h"
     34 #include "chrome/browser/prerender/prerender_manager_factory.h"
     35 #include "chrome/browser/profiles/profile.h"
     36 #include "chrome/browser/safe_browsing/safe_browsing_service.h"
     37 #include "chrome/browser/search_engines/template_url_service_factory.h"
     38 #include "chrome/browser/sessions/session_service.h"
     39 #include "chrome/browser/sessions/session_service_factory.h"
     40 #include "chrome/browser/sessions/tab_restore_service.h"
     41 #include "chrome/browser/sessions/tab_restore_service_factory.h"
     42 #include "chrome/browser/webdata/web_data_service_factory.h"
     43 #include "chrome/common/pref_names.h"
     44 #include "chrome/common/url_constants.h"
     45 #include "components/autofill/core/browser/personal_data_manager.h"
     46 #include "components/autofill/core/browser/webdata/autofill_webdata_service.h"
     47 #include "components/domain_reliability/service.h"
     48 #include "components/nacl/browser/nacl_browser.h"
     49 #include "components/nacl/browser/pnacl_host.h"
     50 #include "components/password_manager/core/browser/password_store.h"
     51 #include "components/power/origin_power_map.h"
     52 #include "components/power/origin_power_map_factory.h"
     53 #include "components/search_engines/template_url_service.h"
     54 #include "components/web_cache/browser/web_cache_manager.h"
     55 #include "content/public/browser/browser_thread.h"
     56 #include "content/public/browser/dom_storage_context.h"
     57 #include "content/public/browser/download_manager.h"
     58 #include "content/public/browser/local_storage_usage_info.h"
     59 #include "content/public/browser/notification_service.h"
     60 #include "content/public/browser/plugin_data_remover.h"
     61 #include "content/public/browser/session_storage_usage_info.h"
     62 #include "content/public/browser/ssl_host_state_delegate.h"
     63 #include "content/public/browser/storage_partition.h"
     64 #include "content/public/browser/user_metrics.h"
     65 #include "net/base/net_errors.h"
     66 #include "net/base/sdch_manager.h"
     67 #include "net/cookies/cookie_store.h"
     68 #include "net/disk_cache/disk_cache.h"
     69 #include "net/http/http_cache.h"
     70 #include "net/http/transport_security_state.h"
     71 #include "net/ssl/channel_id_service.h"
     72 #include "net/ssl/channel_id_store.h"
     73 #include "net/url_request/url_request_context.h"
     74 #include "net/url_request/url_request_context_getter.h"
     75 #include "storage/browser/quota/quota_manager.h"
     76 #include "storage/browser/quota/special_storage_policy.h"
     77 #include "storage/common/quota/quota_types.h"
     78 
     79 #if defined(OS_CHROMEOS)
     80 #include "chrome/browser/chromeos/profiles/profile_helper.h"
     81 #include "chromeos/attestation/attestation_constants.h"
     82 #include "chromeos/dbus/cryptohome_client.h"
     83 #include "chromeos/dbus/dbus_thread_manager.h"
     84 #include "components/user_manager/user.h"
     85 #endif
     86 
     87 #if defined(ENABLE_EXTENSIONS)
     88 #include "chrome/browser/apps/ephemeral_app_service.h"
     89 #include "chrome/browser/extensions/activity_log/activity_log.h"
     90 #include "chrome/browser/extensions/extension_service.h"
     91 #include "chrome/browser/extensions/extension_special_storage_policy.h"
     92 #endif
     93 
     94 #if defined(ENABLE_WEBRTC)
     95 #include "chrome/browser/media/webrtc_log_list.h"
     96 #include "chrome/browser/media/webrtc_log_util.h"
     97 #endif
     98 
     99 using base::UserMetricsAction;
    100 using content::BrowserContext;
    101 using content::BrowserThread;
    102 using content::DOMStorageContext;
    103 
    104 bool BrowsingDataRemover::is_removing_ = false;
    105 
    106 BrowsingDataRemover::CompletionInhibitor*
    107     BrowsingDataRemover::completion_inhibitor_ = NULL;
    108 
    109 // Helper to create callback for BrowsingDataRemover::DoesOriginMatchMask.
    110 // Static.
    111 bool DoesOriginMatchMask(
    112     int origin_set_mask,
    113     const GURL& origin,
    114     storage::SpecialStoragePolicy* special_storage_policy) {
    115   return BrowsingDataHelper::DoesOriginMatchMask(
    116       origin, origin_set_mask, special_storage_policy);
    117 }
    118 
    119 BrowsingDataRemover::NotificationDetails::NotificationDetails()
    120     : removal_begin(base::Time()),
    121       removal_mask(-1),
    122       origin_set_mask(-1) {
    123 }
    124 
    125 BrowsingDataRemover::NotificationDetails::NotificationDetails(
    126     const BrowsingDataRemover::NotificationDetails& details)
    127     : removal_begin(details.removal_begin),
    128       removal_mask(details.removal_mask),
    129       origin_set_mask(details.origin_set_mask) {
    130 }
    131 
    132 BrowsingDataRemover::NotificationDetails::NotificationDetails(
    133     base::Time removal_begin,
    134     int removal_mask,
    135     int origin_set_mask)
    136     : removal_begin(removal_begin),
    137       removal_mask(removal_mask),
    138       origin_set_mask(origin_set_mask) {
    139 }
    140 
    141 BrowsingDataRemover::NotificationDetails::~NotificationDetails() {}
    142 
    143 // Static.
    144 BrowsingDataRemover* BrowsingDataRemover::CreateForUnboundedRange(
    145     Profile* profile) {
    146   return new BrowsingDataRemover(profile, base::Time(), base::Time::Max());
    147 }
    148 
    149 // Static.
    150 BrowsingDataRemover* BrowsingDataRemover::CreateForRange(Profile* profile,
    151     base::Time start, base::Time end) {
    152   return new BrowsingDataRemover(profile, start, end);
    153 }
    154 
    155 // Static.
    156 BrowsingDataRemover* BrowsingDataRemover::CreateForPeriod(Profile* profile,
    157     TimePeriod period) {
    158   switch (period) {
    159     case LAST_HOUR:
    160       content::RecordAction(
    161           UserMetricsAction("ClearBrowsingData_LastHour"));
    162       break;
    163     case LAST_DAY:
    164       content::RecordAction(
    165           UserMetricsAction("ClearBrowsingData_LastDay"));
    166       break;
    167     case LAST_WEEK:
    168       content::RecordAction(
    169           UserMetricsAction("ClearBrowsingData_LastWeek"));
    170       break;
    171     case FOUR_WEEKS:
    172       content::RecordAction(
    173           UserMetricsAction("ClearBrowsingData_LastMonth"));
    174       break;
    175     case EVERYTHING:
    176       content::RecordAction(
    177           UserMetricsAction("ClearBrowsingData_Everything"));
    178       break;
    179   }
    180   return new BrowsingDataRemover(profile,
    181       BrowsingDataRemover::CalculateBeginDeleteTime(period),
    182       base::Time::Max());
    183 }
    184 
    185 BrowsingDataRemover::BrowsingDataRemover(Profile* profile,
    186                                          base::Time delete_begin,
    187                                          base::Time delete_end)
    188     : profile_(profile),
    189       delete_begin_(delete_begin),
    190       delete_end_(delete_end),
    191       next_cache_state_(STATE_NONE),
    192       cache_(NULL),
    193       main_context_getter_(profile->GetRequestContext()),
    194       media_context_getter_(profile->GetMediaRequestContext()),
    195       deauthorize_content_licenses_request_id_(0),
    196       waiting_for_clear_autofill_origin_urls_(false),
    197       waiting_for_clear_cache_(false),
    198       waiting_for_clear_channel_ids_(false),
    199       waiting_for_clear_content_licenses_(false),
    200       waiting_for_clear_cookies_count_(0),
    201       waiting_for_clear_domain_reliability_monitor_(false),
    202       waiting_for_clear_form_(false),
    203       waiting_for_clear_history_(false),
    204       waiting_for_clear_hostname_resolution_cache_(false),
    205       waiting_for_clear_keyword_data_(false),
    206       waiting_for_clear_logged_in_predictor_(false),
    207       waiting_for_clear_nacl_cache_(false),
    208       waiting_for_clear_network_predictor_(false),
    209       waiting_for_clear_networking_history_(false),
    210       waiting_for_clear_platform_keys_(false),
    211       waiting_for_clear_plugin_data_(false),
    212       waiting_for_clear_pnacl_cache_(false),
    213       waiting_for_clear_storage_partition_data_(false),
    214 #if defined(ENABLE_WEBRTC)
    215       waiting_for_clear_webrtc_logs_(false),
    216 #endif
    217       remove_mask_(0),
    218       remove_origin_(GURL()),
    219       origin_set_mask_(0),
    220       storage_partition_for_testing_(NULL) {
    221   DCHECK(profile);
    222   // crbug.com/140910: Many places were calling this with base::Time() as
    223   // delete_end, even though they should've used base::Time::Max(). Work around
    224   // it here. New code should use base::Time::Max().
    225   DCHECK(delete_end_ != base::Time());
    226   if (delete_end_ == base::Time())
    227     delete_end_ = base::Time::Max();
    228 }
    229 
    230 BrowsingDataRemover::~BrowsingDataRemover() {
    231   DCHECK(AllDone());
    232 }
    233 
    234 // Static.
    235 void BrowsingDataRemover::set_removing(bool is_removing) {
    236   DCHECK(is_removing_ != is_removing);
    237   is_removing_ = is_removing;
    238 }
    239 
    240 void BrowsingDataRemover::Remove(int remove_mask, int origin_set_mask) {
    241   RemoveImpl(remove_mask, GURL(), origin_set_mask);
    242 }
    243 
    244 void BrowsingDataRemover::RemoveImpl(int remove_mask,
    245                                      const GURL& origin,
    246                                      int origin_set_mask) {
    247   DCHECK_CURRENTLY_ON(BrowserThread::UI);
    248   set_removing(true);
    249   remove_mask_ = remove_mask;
    250   remove_origin_ = origin;
    251   origin_set_mask_ = origin_set_mask;
    252 
    253   PrefService* prefs = profile_->GetPrefs();
    254   bool may_delete_history = prefs->GetBoolean(
    255       prefs::kAllowDeletingBrowserHistory);
    256 
    257   // All the UI entry points into the BrowsingDataRemover should be disabled,
    258   // but this will fire if something was missed or added.
    259   DCHECK(may_delete_history ||
    260       (!(remove_mask & REMOVE_HISTORY) && !(remove_mask & REMOVE_DOWNLOADS)));
    261 
    262   if (origin_set_mask_ & BrowsingDataHelper::UNPROTECTED_WEB) {
    263     content::RecordAction(
    264         UserMetricsAction("ClearBrowsingData_MaskContainsUnprotectedWeb"));
    265   }
    266   if (origin_set_mask_ & BrowsingDataHelper::PROTECTED_WEB) {
    267     content::RecordAction(
    268         UserMetricsAction("ClearBrowsingData_MaskContainsProtectedWeb"));
    269   }
    270   if (origin_set_mask_ & BrowsingDataHelper::EXTENSION) {
    271     content::RecordAction(
    272         UserMetricsAction("ClearBrowsingData_MaskContainsExtension"));
    273   }
    274   // If this fires, we added a new BrowsingDataHelper::OriginSetMask without
    275   // updating the user metrics above.
    276   COMPILE_ASSERT(
    277       BrowsingDataHelper::ALL == (BrowsingDataHelper::UNPROTECTED_WEB |
    278                                   BrowsingDataHelper::PROTECTED_WEB |
    279                                   BrowsingDataHelper::EXTENSION),
    280       forgotten_to_add_origin_mask_type);
    281 
    282   if ((remove_mask & REMOVE_HISTORY) && may_delete_history) {
    283     HistoryService* history_service = HistoryServiceFactory::GetForProfile(
    284         profile_, Profile::EXPLICIT_ACCESS);
    285     if (history_service) {
    286       std::set<GURL> restrict_urls;
    287       if (!remove_origin_.is_empty())
    288         restrict_urls.insert(remove_origin_);
    289       content::RecordAction(UserMetricsAction("ClearBrowsingData_History"));
    290       waiting_for_clear_history_ = true;
    291 
    292       history_service->ExpireLocalAndRemoteHistoryBetween(
    293           restrict_urls, delete_begin_, delete_end_,
    294           base::Bind(&BrowsingDataRemover::OnHistoryDeletionDone,
    295                      base::Unretained(this)),
    296           &history_task_tracker_);
    297 
    298 #if defined(ENABLE_EXTENSIONS)
    299       // The extension activity contains details of which websites extensions
    300       // were active on. It therefore indirectly stores details of websites a
    301       // user has visited so best clean from here as well.
    302       extensions::ActivityLog::GetInstance(profile_)->RemoveURLs(restrict_urls);
    303 #endif
    304     }
    305 
    306     // The power consumption history by origin contains details of websites
    307     // that were visited.
    308     power::OriginPowerMap* origin_power_map =
    309         power::OriginPowerMapFactory::GetForBrowserContext(profile_);
    310     if (origin_power_map)
    311       origin_power_map->ClearOriginMap();
    312 
    313     // Need to clear the host cache and accumulated speculative data, as it also
    314     // reveals some history: we have no mechanism to track when these items were
    315     // created, so we'll clear them all. Better safe than sorry.
    316     if (g_browser_process->io_thread()) {
    317       waiting_for_clear_hostname_resolution_cache_ = true;
    318       BrowserThread::PostTask(
    319           BrowserThread::IO, FROM_HERE,
    320           base::Bind(
    321               &BrowsingDataRemover::ClearHostnameResolutionCacheOnIOThread,
    322               base::Unretained(this),
    323               g_browser_process->io_thread()));
    324     }
    325     if (profile_->GetNetworkPredictor()) {
    326       waiting_for_clear_network_predictor_ = true;
    327       BrowserThread::PostTask(
    328           BrowserThread::IO, FROM_HERE,
    329           base::Bind(&BrowsingDataRemover::ClearNetworkPredictorOnIOThread,
    330                      base::Unretained(this),
    331                      profile_->GetNetworkPredictor()));
    332     }
    333 
    334     // As part of history deletion we also delete the auto-generated keywords.
    335     TemplateURLService* keywords_model =
    336         TemplateURLServiceFactory::GetForProfile(profile_);
    337     if (keywords_model && !keywords_model->loaded()) {
    338       template_url_sub_ = keywords_model->RegisterOnLoadedCallback(
    339           base::Bind(&BrowsingDataRemover::OnKeywordsLoaded,
    340                      base::Unretained(this)));
    341       keywords_model->Load();
    342       waiting_for_clear_keyword_data_ = true;
    343     } else if (keywords_model) {
    344       keywords_model->RemoveAutoGeneratedForOriginBetween(remove_origin_,
    345           delete_begin_, delete_end_);
    346     }
    347 
    348     // The PrerenderManager keeps history of prerendered pages, so clear that.
    349     // It also may have a prerendered page. If so, the page could be
    350     // considered to have a small amount of historical information, so delete
    351     // it, too.
    352     prerender::PrerenderManager* prerender_manager =
    353         prerender::PrerenderManagerFactory::GetForProfile(profile_);
    354     if (prerender_manager) {
    355       prerender_manager->ClearData(
    356           prerender::PrerenderManager::CLEAR_PRERENDER_CONTENTS |
    357           prerender::PrerenderManager::CLEAR_PRERENDER_HISTORY);
    358     }
    359 
    360     // If the caller is removing history for all hosts, then clear ancillary
    361     // historical information.
    362     if (remove_origin_.is_empty()) {
    363       // We also delete the list of recently closed tabs. Since these expire,
    364       // they can't be more than a day old, so we can simply clear them all.
    365       TabRestoreService* tab_service =
    366           TabRestoreServiceFactory::GetForProfile(profile_);
    367       if (tab_service) {
    368         tab_service->ClearEntries();
    369         tab_service->DeleteLastSession();
    370       }
    371 
    372 #if defined(ENABLE_SESSION_SERVICE)
    373       // We also delete the last session when we delete the history.
    374       SessionService* session_service =
    375           SessionServiceFactory::GetForProfile(profile_);
    376       if (session_service)
    377         session_service->DeleteLastSession();
    378 #endif
    379     }
    380 
    381     // The saved Autofill profiles and credit cards can include the origin from
    382     // which these profiles and credit cards were learned.  These are a form of
    383     // history, so clear them as well.
    384     scoped_refptr<autofill::AutofillWebDataService> web_data_service =
    385         WebDataServiceFactory::GetAutofillWebDataForProfile(
    386             profile_, Profile::EXPLICIT_ACCESS);
    387     if (web_data_service.get()) {
    388       waiting_for_clear_autofill_origin_urls_ = true;
    389       web_data_service->RemoveOriginURLsModifiedBetween(
    390           delete_begin_, delete_end_);
    391       // The above calls are done on the UI thread but do their work on the DB
    392       // thread. So wait for it.
    393       BrowserThread::PostTaskAndReply(
    394           BrowserThread::DB, FROM_HERE,
    395           base::Bind(&base::DoNothing),
    396           base::Bind(&BrowsingDataRemover::OnClearedAutofillOriginURLs,
    397                      base::Unretained(this)));
    398 
    399       autofill::PersonalDataManager* data_manager =
    400           autofill::PersonalDataManagerFactory::GetForProfile(profile_);
    401       if (data_manager)
    402         data_manager->Refresh();
    403     }
    404 
    405 #if defined(ENABLE_WEBRTC)
    406     waiting_for_clear_webrtc_logs_ = true;
    407     BrowserThread::PostTaskAndReply(
    408         BrowserThread::FILE,
    409         FROM_HERE,
    410         base::Bind(
    411             &WebRtcLogUtil::DeleteOldAndRecentWebRtcLogFiles,
    412             WebRtcLogList::GetWebRtcLogDirectoryForProfile(profile_->GetPath()),
    413             delete_begin_),
    414         base::Bind(&BrowsingDataRemover::OnClearedWebRtcLogs,
    415                    base::Unretained(this)));
    416 #endif
    417 
    418     // The SSL Host State that tracks SSL interstitial "proceed" decisions may
    419     // include origins that the user has visited, so it must be cleared.
    420     if (profile_->GetSSLHostStateDelegate())
    421       profile_->GetSSLHostStateDelegate()->Clear();
    422   }
    423 
    424   if ((remove_mask & REMOVE_DOWNLOADS) && may_delete_history) {
    425     content::RecordAction(UserMetricsAction("ClearBrowsingData_Downloads"));
    426     content::DownloadManager* download_manager =
    427         BrowserContext::GetDownloadManager(profile_);
    428     download_manager->RemoveDownloadsBetween(delete_begin_, delete_end_);
    429     DownloadPrefs* download_prefs = DownloadPrefs::FromDownloadManager(
    430         download_manager);
    431     download_prefs->SetSaveFilePath(download_prefs->DownloadPath());
    432   }
    433 
    434   uint32 storage_partition_remove_mask = 0;
    435 
    436   // We ignore the REMOVE_COOKIES request if UNPROTECTED_WEB is not set,
    437   // so that callers who request REMOVE_SITE_DATA with PROTECTED_WEB
    438   // don't accidentally remove the cookies that are associated with the
    439   // UNPROTECTED_WEB origin. This is necessary because cookies are not separated
    440   // between UNPROTECTED_WEB and PROTECTED_WEB.
    441   if (remove_mask & REMOVE_COOKIES &&
    442       origin_set_mask_ & BrowsingDataHelper::UNPROTECTED_WEB) {
    443     content::RecordAction(UserMetricsAction("ClearBrowsingData_Cookies"));
    444 
    445     storage_partition_remove_mask |=
    446         content::StoragePartition::REMOVE_DATA_MASK_COOKIES;
    447 
    448     // Also delete the LoggedIn Predictor, which tries to keep track of which
    449     // sites a user is logged into.
    450     ClearLoggedInPredictor();
    451 
    452 #if defined(FULL_SAFE_BROWSING) || defined(MOBILE_SAFE_BROWSING)
    453     // Clear the safebrowsing cookies only if time period is for "all time".  It
    454     // doesn't make sense to apply the time period of deleting in the last X
    455     // hours/days to the safebrowsing cookies since they aren't the result of
    456     // any user action.
    457     if (delete_begin_ == base::Time()) {
    458       SafeBrowsingService* sb_service =
    459           g_browser_process->safe_browsing_service();
    460       if (sb_service) {
    461         net::URLRequestContextGetter* sb_context =
    462             sb_service->url_request_context();
    463         ++waiting_for_clear_cookies_count_;
    464         BrowserThread::PostTask(
    465             BrowserThread::IO, FROM_HERE,
    466             base::Bind(&BrowsingDataRemover::ClearCookiesOnIOThread,
    467                        base::Unretained(this), base::Unretained(sb_context)));
    468       }
    469     }
    470 #endif
    471     MediaDeviceIDSalt::Reset(profile_->GetPrefs());
    472   }
    473 
    474   // Channel IDs are not separated for protected and unprotected web
    475   // origins. We check the origin_set_mask_ to prevent unintended deletion.
    476   if (remove_mask & REMOVE_CHANNEL_IDS &&
    477       origin_set_mask_ & BrowsingDataHelper::UNPROTECTED_WEB) {
    478     content::RecordAction(
    479         UserMetricsAction("ClearBrowsingData_ChannelIDs"));
    480     // Since we are running on the UI thread don't call GetURLRequestContext().
    481     net::URLRequestContextGetter* rq_context = profile_->GetRequestContext();
    482     if (rq_context) {
    483       waiting_for_clear_channel_ids_ = true;
    484       BrowserThread::PostTask(
    485           BrowserThread::IO, FROM_HERE,
    486           base::Bind(&BrowsingDataRemover::ClearChannelIDsOnIOThread,
    487                      base::Unretained(this), base::Unretained(rq_context)));
    488     }
    489   }
    490 
    491   if (remove_mask & REMOVE_LOCAL_STORAGE) {
    492     storage_partition_remove_mask |=
    493         content::StoragePartition::REMOVE_DATA_MASK_LOCAL_STORAGE;
    494   }
    495 
    496   if (remove_mask & REMOVE_INDEXEDDB) {
    497     storage_partition_remove_mask |=
    498         content::StoragePartition::REMOVE_DATA_MASK_INDEXEDDB;
    499   }
    500   if (remove_mask & REMOVE_WEBSQL) {
    501     storage_partition_remove_mask |=
    502         content::StoragePartition::REMOVE_DATA_MASK_WEBSQL;
    503   }
    504   if (remove_mask & REMOVE_APPCACHE) {
    505     storage_partition_remove_mask |=
    506         content::StoragePartition::REMOVE_DATA_MASK_APPCACHE;
    507   }
    508   if (remove_mask & REMOVE_SERVICE_WORKERS) {
    509     storage_partition_remove_mask |=
    510         content::StoragePartition::REMOVE_DATA_MASK_SERVICE_WORKERS;
    511   }
    512   if (remove_mask & REMOVE_FILE_SYSTEMS) {
    513     storage_partition_remove_mask |=
    514         content::StoragePartition::REMOVE_DATA_MASK_FILE_SYSTEMS;
    515   }
    516 
    517 #if defined(ENABLE_PLUGINS)
    518   // Plugin is data not separated for protected and unprotected web origins. We
    519   // check the origin_set_mask_ to prevent unintended deletion.
    520   if (remove_mask & REMOVE_PLUGIN_DATA &&
    521       origin_set_mask_ & BrowsingDataHelper::UNPROTECTED_WEB) {
    522     content::RecordAction(UserMetricsAction("ClearBrowsingData_LSOData"));
    523 
    524     waiting_for_clear_plugin_data_ = true;
    525     if (!plugin_data_remover_.get())
    526       plugin_data_remover_.reset(content::PluginDataRemover::Create(profile_));
    527     base::WaitableEvent* event =
    528         plugin_data_remover_->StartRemoving(delete_begin_);
    529 
    530     base::WaitableEventWatcher::EventCallback watcher_callback =
    531         base::Bind(&BrowsingDataRemover::OnWaitableEventSignaled,
    532                    base::Unretained(this));
    533     watcher_.StartWatching(event, watcher_callback);
    534   }
    535 #endif
    536 
    537 #if defined(OS_ANDROID)
    538   if (remove_mask & REMOVE_APP_BANNER_DATA) {
    539     profile_->GetHostContentSettingsMap()->ClearSettingsForOneType(
    540         CONTENT_SETTINGS_TYPE_APP_BANNER);
    541   }
    542 #endif
    543 
    544   if (remove_mask & REMOVE_PASSWORDS) {
    545     content::RecordAction(UserMetricsAction("ClearBrowsingData_Passwords"));
    546     password_manager::PasswordStore* password_store =
    547         PasswordStoreFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS)
    548             .get();
    549 
    550     if (password_store)
    551       password_store->RemoveLoginsCreatedBetween(delete_begin_, delete_end_);
    552   }
    553 
    554   if (remove_mask & REMOVE_FORM_DATA) {
    555     content::RecordAction(UserMetricsAction("ClearBrowsingData_Autofill"));
    556     scoped_refptr<autofill::AutofillWebDataService> web_data_service =
    557         WebDataServiceFactory::GetAutofillWebDataForProfile(
    558             profile_, Profile::EXPLICIT_ACCESS);
    559 
    560     if (web_data_service.get()) {
    561       waiting_for_clear_form_ = true;
    562       web_data_service->RemoveFormElementsAddedBetween(delete_begin_,
    563           delete_end_);
    564       web_data_service->RemoveAutofillDataModifiedBetween(
    565           delete_begin_, delete_end_);
    566       // The above calls are done on the UI thread but do their work on the DB
    567       // thread. So wait for it.
    568       BrowserThread::PostTaskAndReply(
    569           BrowserThread::DB, FROM_HERE,
    570           base::Bind(&base::DoNothing),
    571           base::Bind(&BrowsingDataRemover::OnClearedFormData,
    572                      base::Unretained(this)));
    573 
    574       autofill::PersonalDataManager* data_manager =
    575           autofill::PersonalDataManagerFactory::GetForProfile(profile_);
    576       if (data_manager)
    577         data_manager->Refresh();
    578     }
    579   }
    580 
    581   if (remove_mask & REMOVE_CACHE) {
    582     // Tell the renderers to clear their cache.
    583     web_cache::WebCacheManager::GetInstance()->ClearCache();
    584 
    585     // Invoke DoClearCache on the IO thread.
    586     waiting_for_clear_cache_ = true;
    587     content::RecordAction(UserMetricsAction("ClearBrowsingData_Cache"));
    588 
    589     BrowserThread::PostTask(
    590         BrowserThread::IO, FROM_HERE,
    591         base::Bind(&BrowsingDataRemover::ClearCacheOnIOThread,
    592                    base::Unretained(this)));
    593 
    594 #if !defined(DISABLE_NACL)
    595     waiting_for_clear_nacl_cache_ = true;
    596 
    597     BrowserThread::PostTask(
    598         BrowserThread::IO, FROM_HERE,
    599         base::Bind(&BrowsingDataRemover::ClearNaClCacheOnIOThread,
    600                    base::Unretained(this)));
    601 
    602     waiting_for_clear_pnacl_cache_ = true;
    603     BrowserThread::PostTask(
    604         BrowserThread::IO, FROM_HERE,
    605         base::Bind(&BrowsingDataRemover::ClearPnaclCacheOnIOThread,
    606                    base::Unretained(this), delete_begin_, delete_end_));
    607 #endif
    608 
    609     // The PrerenderManager may have a page actively being prerendered, which
    610     // is essentially a preemptively cached page.
    611     prerender::PrerenderManager* prerender_manager =
    612         prerender::PrerenderManagerFactory::GetForProfile(profile_);
    613     if (prerender_manager) {
    614       prerender_manager->ClearData(
    615           prerender::PrerenderManager::CLEAR_PRERENDER_CONTENTS);
    616     }
    617 
    618     // Tell the shader disk cache to clear.
    619     content::RecordAction(UserMetricsAction("ClearBrowsingData_ShaderCache"));
    620     storage_partition_remove_mask |=
    621         content::StoragePartition::REMOVE_DATA_MASK_SHADER_CACHE;
    622 
    623     storage_partition_remove_mask |=
    624         content::StoragePartition::REMOVE_DATA_MASK_WEBRTC_IDENTITY;
    625 
    626 #if defined(ENABLE_EXTENSIONS)
    627     // Clear the ephemeral apps cache.
    628     EphemeralAppService::Get(profile_)->ClearCachedApps();
    629 #endif
    630   }
    631 
    632   if (storage_partition_remove_mask) {
    633     waiting_for_clear_storage_partition_data_ = true;
    634 
    635     content::StoragePartition* storage_partition;
    636     if (storage_partition_for_testing_)
    637       storage_partition = storage_partition_for_testing_;
    638     else
    639       storage_partition = BrowserContext::GetDefaultStoragePartition(profile_);
    640 
    641     uint32 quota_storage_remove_mask =
    642         ~content::StoragePartition::QUOTA_MANAGED_STORAGE_MASK_PERSISTENT;
    643 
    644     if (delete_begin_ == base::Time() ||
    645         origin_set_mask_ &
    646           (BrowsingDataHelper::PROTECTED_WEB | BrowsingDataHelper::EXTENSION)) {
    647       // If we're deleting since the beginning of time, or we're removing
    648       // protected origins, then remove persistent quota data.
    649       quota_storage_remove_mask |=
    650           content::StoragePartition::QUOTA_MANAGED_STORAGE_MASK_PERSISTENT;
    651     }
    652 
    653     storage_partition->ClearData(
    654         storage_partition_remove_mask,
    655         quota_storage_remove_mask,
    656         remove_origin_,
    657         base::Bind(&DoesOriginMatchMask, origin_set_mask_),
    658         delete_begin_,
    659         delete_end_,
    660         base::Bind(&BrowsingDataRemover::OnClearedStoragePartitionData,
    661                    base::Unretained(this)));
    662   }
    663 
    664 #if defined(ENABLE_PLUGINS)
    665   if (remove_mask & REMOVE_CONTENT_LICENSES) {
    666     content::RecordAction(
    667         UserMetricsAction("ClearBrowsingData_ContentLicenses"));
    668 
    669     waiting_for_clear_content_licenses_ = true;
    670     if (!pepper_flash_settings_manager_.get()) {
    671       pepper_flash_settings_manager_.reset(
    672           new PepperFlashSettingsManager(this, profile_));
    673     }
    674     deauthorize_content_licenses_request_id_ =
    675         pepper_flash_settings_manager_->DeauthorizeContentLicenses(prefs);
    676 #if defined(OS_CHROMEOS)
    677     // On Chrome OS, also delete any content protection platform keys.
    678     user_manager::User* user =
    679         chromeos::ProfileHelper::Get()->GetUserByProfile(profile_);
    680     if (!user) {
    681       LOG(WARNING) << "Failed to find user for current profile.";
    682     } else {
    683       chromeos::DBusThreadManager::Get()->GetCryptohomeClient()->
    684           TpmAttestationDeleteKeys(
    685               chromeos::attestation::KEY_USER,
    686               user->email(),
    687               chromeos::attestation::kContentProtectionKeyPrefix,
    688               base::Bind(&BrowsingDataRemover::OnClearPlatformKeys,
    689                          base::Unretained(this)));
    690       waiting_for_clear_platform_keys_ = true;
    691     }
    692 #endif
    693   }
    694 #endif
    695 
    696   // Remove omnibox zero-suggest cache results.
    697   if ((remove_mask & (REMOVE_CACHE | REMOVE_COOKIES)))
    698     prefs->SetString(prefs::kZeroSuggestCachedResults, std::string());
    699 
    700   // Always wipe accumulated network related data (TransportSecurityState and
    701   // HttpServerPropertiesManager data).
    702   waiting_for_clear_networking_history_ = true;
    703   profile_->ClearNetworkingHistorySince(
    704       delete_begin_,
    705       base::Bind(&BrowsingDataRemover::OnClearedNetworkingHistory,
    706                  base::Unretained(this)));
    707 
    708   if (remove_mask & (REMOVE_COOKIES | REMOVE_HISTORY)) {
    709     domain_reliability::DomainReliabilityService* service =
    710       domain_reliability::DomainReliabilityServiceFactory::
    711           GetForBrowserContext(profile_);
    712     if (service) {
    713       domain_reliability::DomainReliabilityClearMode mode;
    714       if (remove_mask & REMOVE_COOKIES)
    715         mode = domain_reliability::CLEAR_CONTEXTS;
    716       else
    717         mode = domain_reliability::CLEAR_BEACONS;
    718 
    719       waiting_for_clear_domain_reliability_monitor_ = true;
    720       service->ClearBrowsingData(
    721           mode,
    722           base::Bind(&BrowsingDataRemover::OnClearedDomainReliabilityMonitor,
    723                      base::Unretained(this)));
    724     }
    725   }
    726 }
    727 
    728 void BrowsingDataRemover::AddObserver(Observer* observer) {
    729   observer_list_.AddObserver(observer);
    730 }
    731 
    732 void BrowsingDataRemover::RemoveObserver(Observer* observer) {
    733   observer_list_.RemoveObserver(observer);
    734 }
    735 
    736 void BrowsingDataRemover::OnHistoryDeletionDone() {
    737   waiting_for_clear_history_ = false;
    738   NotifyAndDeleteIfDone();
    739 }
    740 
    741 void BrowsingDataRemover::OverrideStoragePartitionForTesting(
    742     content::StoragePartition* storage_partition) {
    743   storage_partition_for_testing_ = storage_partition;
    744 }
    745 
    746 base::Time BrowsingDataRemover::CalculateBeginDeleteTime(
    747     TimePeriod time_period) {
    748   base::TimeDelta diff;
    749   base::Time delete_begin_time = base::Time::Now();
    750   switch (time_period) {
    751     case LAST_HOUR:
    752       diff = base::TimeDelta::FromHours(1);
    753       break;
    754     case LAST_DAY:
    755       diff = base::TimeDelta::FromHours(24);
    756       break;
    757     case LAST_WEEK:
    758       diff = base::TimeDelta::FromHours(7*24);
    759       break;
    760     case FOUR_WEEKS:
    761       diff = base::TimeDelta::FromHours(4*7*24);
    762       break;
    763     case EVERYTHING:
    764       delete_begin_time = base::Time();
    765       break;
    766     default:
    767       NOTREACHED() << L"Missing item";
    768       break;
    769   }
    770   return delete_begin_time - diff;
    771 }
    772 
    773 bool BrowsingDataRemover::AllDone() {
    774   return !waiting_for_clear_autofill_origin_urls_ &&
    775          !waiting_for_clear_cache_ &&
    776          !waiting_for_clear_content_licenses_ &&
    777          !waiting_for_clear_channel_ids_ &&
    778          !waiting_for_clear_cookies_count_ &&
    779          !waiting_for_clear_domain_reliability_monitor_ &&
    780          !waiting_for_clear_form_ &&
    781          !waiting_for_clear_history_ &&
    782          !waiting_for_clear_hostname_resolution_cache_ &&
    783          !waiting_for_clear_keyword_data_ &&
    784          !waiting_for_clear_logged_in_predictor_ &&
    785          !waiting_for_clear_nacl_cache_ &&
    786          !waiting_for_clear_network_predictor_ &&
    787          !waiting_for_clear_networking_history_ &&
    788          !waiting_for_clear_platform_keys_ &&
    789          !waiting_for_clear_plugin_data_ &&
    790          !waiting_for_clear_pnacl_cache_ &&
    791 #if defined(ENABLE_WEBRTC)
    792          !waiting_for_clear_webrtc_logs_ &&
    793 #endif
    794          !waiting_for_clear_storage_partition_data_;
    795 }
    796 
    797 void BrowsingDataRemover::OnKeywordsLoaded() {
    798   // Deletes the entries from the model, and if we're not waiting on anything
    799   // else notifies observers and deletes this BrowsingDataRemover.
    800   TemplateURLService* model =
    801       TemplateURLServiceFactory::GetForProfile(profile_);
    802   model->RemoveAutoGeneratedBetween(delete_begin_, delete_end_);
    803   waiting_for_clear_keyword_data_ = false;
    804   template_url_sub_.reset();
    805   NotifyAndDeleteIfDone();
    806 }
    807 
    808 void BrowsingDataRemover::NotifyAndDelete() {
    809   set_removing(false);
    810 
    811   // Send global notification, then notify any explicit observers.
    812   BrowsingDataRemover::NotificationDetails details(delete_begin_, remove_mask_,
    813       origin_set_mask_);
    814   content::NotificationService::current()->Notify(
    815       chrome::NOTIFICATION_BROWSING_DATA_REMOVED,
    816       content::Source<Profile>(profile_),
    817       content::Details<BrowsingDataRemover::NotificationDetails>(&details));
    818 
    819   FOR_EACH_OBSERVER(Observer, observer_list_, OnBrowsingDataRemoverDone());
    820 
    821   // History requests aren't happy if you delete yourself from the callback.
    822   // As such, we do a delete later.
    823   base::MessageLoop::current()->DeleteSoon(FROM_HERE, this);
    824 }
    825 
    826 void BrowsingDataRemover::NotifyAndDeleteIfDone() {
    827   // TODO(brettw) http://crbug.com/305259: This should also observe session
    828   // clearing (what about other things such as passwords, etc.?) and wait for
    829   // them to complete before continuing.
    830 
    831   if (!AllDone())
    832     return;
    833 
    834   if (completion_inhibitor_) {
    835     completion_inhibitor_->OnBrowsingDataRemoverWouldComplete(
    836         this,
    837         base::Bind(&BrowsingDataRemover::NotifyAndDelete,
    838                    base::Unretained(this)));
    839   } else {
    840     NotifyAndDelete();
    841   }
    842 }
    843 
    844 void BrowsingDataRemover::OnClearedHostnameResolutionCache() {
    845   DCHECK_CURRENTLY_ON(BrowserThread::UI);
    846   waiting_for_clear_hostname_resolution_cache_ = false;
    847   NotifyAndDeleteIfDone();
    848 }
    849 
    850 void BrowsingDataRemover::ClearHostnameResolutionCacheOnIOThread(
    851     IOThread* io_thread) {
    852   DCHECK_CURRENTLY_ON(BrowserThread::IO);
    853 
    854   io_thread->ClearHostCache();
    855 
    856   // Notify the UI thread that we are done.
    857   BrowserThread::PostTask(
    858       BrowserThread::UI,
    859       FROM_HERE,
    860       base::Bind(&BrowsingDataRemover::OnClearedHostnameResolutionCache,
    861                  base::Unretained(this)));
    862 }
    863 
    864 void BrowsingDataRemover::OnClearedLoggedInPredictor() {
    865   DCHECK_CURRENTLY_ON(BrowserThread::UI);
    866   DCHECK(waiting_for_clear_logged_in_predictor_);
    867   waiting_for_clear_logged_in_predictor_ = false;
    868   NotifyAndDeleteIfDone();
    869 }
    870 
    871 void BrowsingDataRemover::ClearLoggedInPredictor() {
    872   DCHECK_CURRENTLY_ON(BrowserThread::UI);
    873   DCHECK(!waiting_for_clear_logged_in_predictor_);
    874 
    875   predictors::PredictorDatabase* predictor_db =
    876       predictors::PredictorDatabaseFactory::GetForProfile(profile_);
    877   if (!predictor_db)
    878     return;
    879 
    880   predictors::LoggedInPredictorTable* logged_in_table =
    881       predictor_db->logged_in_table().get();
    882   if (!logged_in_table)
    883     return;
    884 
    885   waiting_for_clear_logged_in_predictor_ = true;
    886 
    887   BrowserThread::PostTaskAndReply(
    888       BrowserThread::DB,
    889       FROM_HERE,
    890       base::Bind(&predictors::LoggedInPredictorTable::DeleteAllCreatedBetween,
    891                  logged_in_table,
    892                  delete_begin_,
    893                  delete_end_),
    894       base::Bind(&BrowsingDataRemover::OnClearedLoggedInPredictor,
    895                  base::Unretained(this)));
    896 }
    897 
    898 void BrowsingDataRemover::OnClearedNetworkPredictor() {
    899   DCHECK_CURRENTLY_ON(BrowserThread::UI);
    900   waiting_for_clear_network_predictor_ = false;
    901   NotifyAndDeleteIfDone();
    902 }
    903 
    904 void BrowsingDataRemover::ClearNetworkPredictorOnIOThread(
    905     chrome_browser_net::Predictor* predictor) {
    906   DCHECK_CURRENTLY_ON(BrowserThread::IO);
    907   DCHECK(predictor);
    908 
    909   predictor->DiscardInitialNavigationHistory();
    910   predictor->DiscardAllResults();
    911 
    912   // Notify the UI thread that we are done.
    913   BrowserThread::PostTask(
    914       BrowserThread::UI,
    915       FROM_HERE,
    916       base::Bind(&BrowsingDataRemover::OnClearedNetworkPredictor,
    917                  base::Unretained(this)));
    918 }
    919 
    920 void BrowsingDataRemover::OnClearedNetworkingHistory() {
    921   DCHECK_CURRENTLY_ON(BrowserThread::UI);
    922   waiting_for_clear_networking_history_ = false;
    923   NotifyAndDeleteIfDone();
    924 }
    925 
    926 void BrowsingDataRemover::ClearedCache() {
    927   waiting_for_clear_cache_ = false;
    928 
    929   NotifyAndDeleteIfDone();
    930 }
    931 
    932 void BrowsingDataRemover::ClearCacheOnIOThread() {
    933   // This function should be called on the IO thread.
    934   DCHECK_CURRENTLY_ON(BrowserThread::IO);
    935   DCHECK_EQ(STATE_NONE, next_cache_state_);
    936   DCHECK(main_context_getter_.get());
    937   DCHECK(media_context_getter_.get());
    938 
    939   next_cache_state_ = STATE_CREATE_MAIN;
    940   DoClearCache(net::OK);
    941 }
    942 
    943 // The expected state sequence is STATE_NONE --> STATE_CREATE_MAIN -->
    944 // STATE_DELETE_MAIN --> STATE_CREATE_MEDIA --> STATE_DELETE_MEDIA -->
    945 // STATE_DONE, and any errors are ignored.
    946 void BrowsingDataRemover::DoClearCache(int rv) {
    947   DCHECK_NE(STATE_NONE, next_cache_state_);
    948 
    949   while (rv != net::ERR_IO_PENDING && next_cache_state_ != STATE_NONE) {
    950     switch (next_cache_state_) {
    951       case STATE_CREATE_MAIN:
    952       case STATE_CREATE_MEDIA: {
    953         // Get a pointer to the cache.
    954         net::URLRequestContextGetter* getter =
    955             (next_cache_state_ == STATE_CREATE_MAIN)
    956                 ? main_context_getter_.get()
    957                 : media_context_getter_.get();
    958         net::HttpCache* http_cache =
    959             getter->GetURLRequestContext()->http_transaction_factory()->
    960                 GetCache();
    961 
    962         next_cache_state_ = (next_cache_state_ == STATE_CREATE_MAIN) ?
    963                                 STATE_DELETE_MAIN : STATE_DELETE_MEDIA;
    964 
    965         // Clear QUIC server information from memory and the disk cache.
    966         http_cache->GetSession()->quic_stream_factory()->
    967             ClearCachedStatesInCryptoConfig();
    968 
    969         // Clear SDCH dictionary state.
    970         net::SdchManager* sdch_manager =
    971             getter->GetURLRequestContext()->sdch_manager();
    972         // The test is probably overkill, since chrome should always have an
    973         // SdchManager.  But in general the URLRequestContext  is *not*
    974         // guaranteed to have an SdchManager, so checking is wise.
    975         if (sdch_manager)
    976           sdch_manager->ClearData();
    977 
    978         rv = http_cache->GetBackend(
    979             &cache_, base::Bind(&BrowsingDataRemover::DoClearCache,
    980                                 base::Unretained(this)));
    981         break;
    982       }
    983       case STATE_DELETE_MAIN:
    984       case STATE_DELETE_MEDIA: {
    985         next_cache_state_ = (next_cache_state_ == STATE_DELETE_MAIN) ?
    986                                 STATE_CREATE_MEDIA : STATE_DONE;
    987 
    988         // |cache_| can be null if it cannot be initialized.
    989         if (cache_) {
    990           if (delete_begin_.is_null()) {
    991             rv = cache_->DoomAllEntries(
    992                 base::Bind(&BrowsingDataRemover::DoClearCache,
    993                            base::Unretained(this)));
    994           } else {
    995             rv = cache_->DoomEntriesBetween(
    996                 delete_begin_, delete_end_,
    997                 base::Bind(&BrowsingDataRemover::DoClearCache,
    998                            base::Unretained(this)));
    999           }
   1000           cache_ = NULL;
   1001         }
   1002         break;
   1003       }
   1004       case STATE_DONE: {
   1005         cache_ = NULL;
   1006         next_cache_state_ = STATE_NONE;
   1007 
   1008         // Notify the UI thread that we are done.
   1009         BrowserThread::PostTask(
   1010             BrowserThread::UI, FROM_HERE,
   1011             base::Bind(&BrowsingDataRemover::ClearedCache,
   1012                        base::Unretained(this)));
   1013         return;
   1014       }
   1015       default: {
   1016         NOTREACHED() << "bad state";
   1017         next_cache_state_ = STATE_NONE;  // Stop looping.
   1018         return;
   1019       }
   1020     }
   1021   }
   1022 }
   1023 
   1024 #if !defined(DISABLE_NACL)
   1025 void BrowsingDataRemover::ClearedNaClCache() {
   1026   // This function should be called on the UI thread.
   1027   DCHECK_CURRENTLY_ON(BrowserThread::UI);
   1028 
   1029   waiting_for_clear_nacl_cache_ = false;
   1030 
   1031   NotifyAndDeleteIfDone();
   1032 }
   1033 
   1034 void BrowsingDataRemover::ClearedNaClCacheOnIOThread() {
   1035   // This function should be called on the IO thread.
   1036   DCHECK_CURRENTLY_ON(BrowserThread::IO);
   1037 
   1038   // Notify the UI thread that we are done.
   1039   BrowserThread::PostTask(
   1040       BrowserThread::UI, FROM_HERE,
   1041       base::Bind(&BrowsingDataRemover::ClearedNaClCache,
   1042                  base::Unretained(this)));
   1043 }
   1044 
   1045 void BrowsingDataRemover::ClearNaClCacheOnIOThread() {
   1046   DCHECK_CURRENTLY_ON(BrowserThread::IO);
   1047 
   1048   nacl::NaClBrowser::GetInstance()->ClearValidationCache(
   1049       base::Bind(&BrowsingDataRemover::ClearedNaClCacheOnIOThread,
   1050                  base::Unretained(this)));
   1051 }
   1052 
   1053 void BrowsingDataRemover::ClearedPnaclCache() {
   1054   // This function should be called on the UI thread.
   1055   DCHECK_CURRENTLY_ON(BrowserThread::UI);
   1056 
   1057   waiting_for_clear_pnacl_cache_ = false;
   1058 
   1059   NotifyAndDeleteIfDone();
   1060 }
   1061 
   1062 void BrowsingDataRemover::ClearedPnaclCacheOnIOThread() {
   1063   // This function should be called on the IO thread.
   1064   DCHECK_CURRENTLY_ON(BrowserThread::IO);
   1065 
   1066   // Notify the UI thread that we are done.
   1067   BrowserThread::PostTask(
   1068       BrowserThread::UI, FROM_HERE,
   1069       base::Bind(&BrowsingDataRemover::ClearedPnaclCache,
   1070                  base::Unretained(this)));
   1071 }
   1072 
   1073 void BrowsingDataRemover::ClearPnaclCacheOnIOThread(base::Time begin,
   1074                                                     base::Time end) {
   1075   DCHECK_CURRENTLY_ON(BrowserThread::IO);
   1076 
   1077   pnacl::PnaclHost::GetInstance()->ClearTranslationCacheEntriesBetween(
   1078       begin, end,
   1079       base::Bind(&BrowsingDataRemover::ClearedPnaclCacheOnIOThread,
   1080                  base::Unretained(this)));
   1081 }
   1082 #endif
   1083 
   1084 void BrowsingDataRemover::OnWaitableEventSignaled(
   1085     base::WaitableEvent* waitable_event) {
   1086   waiting_for_clear_plugin_data_ = false;
   1087   NotifyAndDeleteIfDone();
   1088 }
   1089 
   1090 #if defined(ENABLE_PLUGINS)
   1091 void BrowsingDataRemover::OnDeauthorizeContentLicensesCompleted(
   1092     uint32 request_id,
   1093     bool /* success */) {
   1094   DCHECK(waiting_for_clear_content_licenses_);
   1095   DCHECK_EQ(request_id, deauthorize_content_licenses_request_id_);
   1096 
   1097   waiting_for_clear_content_licenses_ = false;
   1098   NotifyAndDeleteIfDone();
   1099 }
   1100 #endif
   1101 
   1102 #if defined(OS_CHROMEOS)
   1103 void BrowsingDataRemover::OnClearPlatformKeys(
   1104     chromeos::DBusMethodCallStatus call_status,
   1105     bool result) {
   1106   DCHECK(waiting_for_clear_platform_keys_);
   1107   if (call_status != chromeos::DBUS_METHOD_CALL_SUCCESS || !result) {
   1108     LOG(ERROR) << "Failed to clear platform keys.";
   1109   }
   1110   waiting_for_clear_platform_keys_ = false;
   1111   NotifyAndDeleteIfDone();
   1112 }
   1113 #endif
   1114 
   1115 void BrowsingDataRemover::OnClearedCookies(int num_deleted) {
   1116   if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) {
   1117     BrowserThread::PostTask(
   1118         BrowserThread::UI, FROM_HERE,
   1119         base::Bind(&BrowsingDataRemover::OnClearedCookies,
   1120                    base::Unretained(this), num_deleted));
   1121     return;
   1122   }
   1123 
   1124   DCHECK_GT(waiting_for_clear_cookies_count_, 0);
   1125   --waiting_for_clear_cookies_count_;
   1126   NotifyAndDeleteIfDone();
   1127 }
   1128 
   1129 void BrowsingDataRemover::ClearCookiesOnIOThread(
   1130     net::URLRequestContextGetter* rq_context) {
   1131   DCHECK_CURRENTLY_ON(BrowserThread::IO);
   1132   net::CookieStore* cookie_store = rq_context->
   1133       GetURLRequestContext()->cookie_store();
   1134   cookie_store->DeleteAllCreatedBetweenAsync(
   1135       delete_begin_, delete_end_,
   1136       base::Bind(&BrowsingDataRemover::OnClearedCookies,
   1137                  base::Unretained(this)));
   1138 }
   1139 
   1140 void BrowsingDataRemover::ClearChannelIDsOnIOThread(
   1141     net::URLRequestContextGetter* rq_context) {
   1142   DCHECK_CURRENTLY_ON(BrowserThread::IO);
   1143   net::ChannelIDService* channel_id_service =
   1144       rq_context->GetURLRequestContext()->channel_id_service();
   1145   channel_id_service->GetChannelIDStore()->DeleteAllCreatedBetween(
   1146       delete_begin_, delete_end_,
   1147       base::Bind(&BrowsingDataRemover::OnClearedChannelIDsOnIOThread,
   1148                  base::Unretained(this), base::Unretained(rq_context)));
   1149 }
   1150 
   1151 void BrowsingDataRemover::OnClearedChannelIDsOnIOThread(
   1152     net::URLRequestContextGetter* rq_context) {
   1153   // Need to close open SSL connections which may be using the channel ids we
   1154   // are deleting.
   1155   // TODO(mattm): http://crbug.com/166069 Make the server bound cert
   1156   // service/store have observers that can notify relevant things directly.
   1157   rq_context->GetURLRequestContext()->ssl_config_service()->
   1158       NotifySSLConfigChange();
   1159   BrowserThread::PostTask(
   1160       BrowserThread::UI, FROM_HERE,
   1161       base::Bind(&BrowsingDataRemover::OnClearedChannelIDs,
   1162                  base::Unretained(this)));
   1163 }
   1164 
   1165 void BrowsingDataRemover::OnClearedChannelIDs() {
   1166   DCHECK_CURRENTLY_ON(BrowserThread::UI);
   1167   waiting_for_clear_channel_ids_ = false;
   1168   NotifyAndDeleteIfDone();
   1169 }
   1170 
   1171 void BrowsingDataRemover::OnClearedFormData() {
   1172   DCHECK_CURRENTLY_ON(BrowserThread::UI);
   1173   waiting_for_clear_form_ = false;
   1174   NotifyAndDeleteIfDone();
   1175 }
   1176 
   1177 void BrowsingDataRemover::OnClearedAutofillOriginURLs() {
   1178   DCHECK_CURRENTLY_ON(BrowserThread::UI);
   1179   waiting_for_clear_autofill_origin_urls_ = false;
   1180   NotifyAndDeleteIfDone();
   1181 }
   1182 
   1183 void BrowsingDataRemover::OnClearedStoragePartitionData() {
   1184   DCHECK_CURRENTLY_ON(BrowserThread::UI);
   1185   waiting_for_clear_storage_partition_data_ = false;
   1186   NotifyAndDeleteIfDone();
   1187 }
   1188 
   1189 #if defined(ENABLE_WEBRTC)
   1190 void BrowsingDataRemover::OnClearedWebRtcLogs() {
   1191   DCHECK_CURRENTLY_ON(BrowserThread::UI);
   1192   waiting_for_clear_webrtc_logs_ = false;
   1193   NotifyAndDeleteIfDone();
   1194 }
   1195 #endif
   1196 
   1197 void BrowsingDataRemover::OnClearedDomainReliabilityMonitor() {
   1198   DCHECK_CURRENTLY_ON(BrowserThread::UI);
   1199   waiting_for_clear_domain_reliability_monitor_ = false;
   1200   NotifyAndDeleteIfDone();
   1201 }
   1202