| 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/browsing_data/browsing_data_remover.h" | 5 #include "chrome/browser/browsing_data/browsing_data_remover.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 #include <set> | 8 #include <set> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 #include "webkit/quota/quota_manager.h" | 67 #include "webkit/quota/quota_manager.h" |
| 68 #include "webkit/quota/quota_types.h" | 68 #include "webkit/quota/quota_types.h" |
| 69 #include "webkit/quota/special_storage_policy.h" | 69 #include "webkit/quota/special_storage_policy.h" |
| 70 | 70 |
| 71 using content::BrowserContext; | 71 using content::BrowserContext; |
| 72 using content::BrowserThread; | 72 using content::BrowserThread; |
| 73 using content::DOMStorageContext; | 73 using content::DOMStorageContext; |
| 74 using content::DownloadManager; | 74 using content::DownloadManager; |
| 75 using content::UserMetricsAction; | 75 using content::UserMetricsAction; |
| 76 | 76 |
| 77 bool BrowsingDataRemover::removing_ = false; | 77 bool BrowsingDataRemover::is_removing_ = false; |
| 78 | 78 |
| 79 BrowsingDataRemover::NotificationDetails::NotificationDetails() | 79 BrowsingDataRemover::NotificationDetails::NotificationDetails() |
| 80 : removal_begin(base::Time()), | 80 : removal_begin(base::Time()), |
| 81 removal_mask(-1), | 81 removal_mask(-1), |
| 82 origin_set_mask(-1) { | 82 origin_set_mask(-1) { |
| 83 } | 83 } |
| 84 | 84 |
| 85 BrowsingDataRemover::NotificationDetails::NotificationDetails( | 85 BrowsingDataRemover::NotificationDetails::NotificationDetails( |
| 86 const BrowsingDataRemover::NotificationDetails& details) | 86 const BrowsingDataRemover::NotificationDetails& details) |
| 87 : removal_begin(details.removal_begin), | 87 : removal_begin(details.removal_begin), |
| 88 removal_mask(details.removal_mask), | 88 removal_mask(details.removal_mask), |
| 89 origin_set_mask(details.origin_set_mask) { | 89 origin_set_mask(details.origin_set_mask) { |
| 90 } | 90 } |
| 91 | 91 |
| 92 BrowsingDataRemover::NotificationDetails::NotificationDetails( | 92 BrowsingDataRemover::NotificationDetails::NotificationDetails( |
| 93 base::Time removal_begin, | 93 base::Time removal_begin, |
| 94 int removal_mask, | 94 int removal_mask, |
| 95 int origin_set_mask) | 95 int origin_set_mask) |
| 96 : removal_begin(removal_begin), | 96 : removal_begin(removal_begin), |
| 97 removal_mask(removal_mask), | 97 removal_mask(removal_mask), |
| 98 origin_set_mask(origin_set_mask) { | 98 origin_set_mask(origin_set_mask) { |
| 99 } | 99 } |
| 100 | 100 |
| 101 BrowsingDataRemover::NotificationDetails::~NotificationDetails() {} | 101 BrowsingDataRemover::NotificationDetails::~NotificationDetails() {} |
| 102 | 102 |
| 103 // TODO(mkwst): We should have one constructor, not two. http://crbug.com/130732 | 103 // Static. |
| 104 BrowsingDataRemover* BrowsingDataRemover::CreateForUnboundedRange( |
| 105 Profile* profile) { |
| 106 return new BrowsingDataRemover(profile, base::Time(), base::Time::Max()); |
| 107 } |
| 108 |
| 109 // Static. |
| 110 BrowsingDataRemover* BrowsingDataRemover::CreateForRange(Profile* profile, |
| 111 base::Time start, base::Time end) { |
| 112 return new BrowsingDataRemover(profile, start, end); |
| 113 } |
| 114 |
| 115 // Static. |
| 116 BrowsingDataRemover* BrowsingDataRemover::CreateForPeriod(Profile* profile, |
| 117 TimePeriod period) { |
| 118 return new BrowsingDataRemover(profile, |
| 119 BrowsingDataRemover::CalculateBeginDeleteTime(period), |
| 120 base::Time::Max()); |
| 121 } |
| 122 |
| 104 BrowsingDataRemover::BrowsingDataRemover(Profile* profile, | 123 BrowsingDataRemover::BrowsingDataRemover(Profile* profile, |
| 105 base::Time delete_begin, | 124 base::Time delete_begin, |
| 106 base::Time delete_end) | 125 base::Time delete_end) |
| 107 : profile_(profile), | 126 : profile_(profile), |
| 108 quota_manager_(NULL), | 127 quota_manager_(NULL), |
| 109 dom_storage_context_(NULL), | 128 dom_storage_context_(NULL), |
| 110 special_storage_policy_(profile->GetExtensionSpecialStoragePolicy()), | 129 special_storage_policy_(profile->GetExtensionSpecialStoragePolicy()), |
| 111 delete_begin_(delete_begin), | 130 delete_begin_(delete_begin), |
| 112 delete_end_(delete_end), | 131 delete_end_(delete_end), |
| 113 next_cache_state_(STATE_NONE), | 132 next_cache_state_(STATE_NONE), |
| 114 cache_(NULL), | 133 cache_(NULL), |
| 115 main_context_getter_(profile->GetRequestContext()), | |
| 116 media_context_getter_(profile->GetMediaRequestContext()), | |
| 117 deauthorize_content_licenses_request_id_(0), | |
| 118 waiting_for_clear_cache_(false), | |
| 119 waiting_for_clear_nacl_cache_(false), | |
| 120 waiting_for_clear_cookies_count_(0), | |
| 121 waiting_for_clear_history_(false), | |
| 122 waiting_for_clear_local_storage_(false), | |
| 123 waiting_for_clear_networking_history_(false), | |
| 124 waiting_for_clear_server_bound_certs_(false), | |
| 125 waiting_for_clear_plugin_data_(false), | |
| 126 waiting_for_clear_quota_managed_data_(false), | |
| 127 waiting_for_clear_content_licenses_(false), | |
| 128 waiting_for_clear_form_(false), | |
| 129 remove_mask_(0), | |
| 130 remove_origin_(GURL()), | |
| 131 origin_set_mask_(0) { | |
| 132 DCHECK(profile); | |
| 133 // crbug.com/140910: Many places were calling this with base::Time() as | |
| 134 // delete_end, even though they should've used base::Time::Now(). Work around | |
| 135 // it here. New code should use base::Time::Now(). | |
| 136 DCHECK(delete_end_ != base::Time()); | |
| 137 if (delete_end_ == base::Time()) | |
| 138 delete_end_ = base::Time::Now(); | |
| 139 } | |
| 140 | |
| 141 BrowsingDataRemover::BrowsingDataRemover(Profile* profile, | |
| 142 TimePeriod time_period, | |
| 143 base::Time delete_end) | |
| 144 : profile_(profile), | |
| 145 quota_manager_(NULL), | |
| 146 dom_storage_context_(NULL), | |
| 147 special_storage_policy_(profile->GetExtensionSpecialStoragePolicy()), | |
| 148 delete_begin_(CalculateBeginDeleteTime(time_period)), | |
| 149 delete_end_(delete_end), | |
| 150 next_cache_state_(STATE_NONE), | |
| 151 cache_(NULL), | |
| 152 main_context_getter_(profile->GetRequestContext()), | 134 main_context_getter_(profile->GetRequestContext()), |
| 153 media_context_getter_(profile->GetMediaRequestContext()), | 135 media_context_getter_(profile->GetMediaRequestContext()), |
| 154 deauthorize_content_licenses_request_id_(0), | 136 deauthorize_content_licenses_request_id_(0), |
| 155 waiting_for_clear_cache_(false), | 137 waiting_for_clear_cache_(false), |
| 156 waiting_for_clear_nacl_cache_(false), | 138 waiting_for_clear_nacl_cache_(false), |
| 157 waiting_for_clear_cookies_count_(0), | 139 waiting_for_clear_cookies_count_(0), |
| 158 waiting_for_clear_history_(false), | 140 waiting_for_clear_history_(false), |
| 159 waiting_for_clear_local_storage_(false), | 141 waiting_for_clear_local_storage_(false), |
| 160 waiting_for_clear_networking_history_(false), | 142 waiting_for_clear_networking_history_(false), |
| 161 waiting_for_clear_server_bound_certs_(false), | 143 waiting_for_clear_server_bound_certs_(false), |
| 162 waiting_for_clear_plugin_data_(false), | 144 waiting_for_clear_plugin_data_(false), |
| 163 waiting_for_clear_quota_managed_data_(false), | 145 waiting_for_clear_quota_managed_data_(false), |
| 164 waiting_for_clear_content_licenses_(false), | 146 waiting_for_clear_content_licenses_(false), |
| 165 waiting_for_clear_form_(false), | 147 waiting_for_clear_form_(false), |
| 166 remove_mask_(0), | 148 remove_mask_(0), |
| 167 remove_origin_(GURL()), | 149 remove_origin_(GURL()), |
| 168 origin_set_mask_(0) { | 150 origin_set_mask_(0) { |
| 169 DCHECK(profile); | 151 DCHECK(profile); |
| 170 // crbug.com/140910: Many places were calling this with base::Time() as | 152 // crbug.com/140910: Many places were calling this with base::Time() as |
| 171 // delete_end, even though they should've used base::Time::Now(). Work around | 153 // delete_end, even though they should've used base::Time::Max(). Work around |
| 172 // it here. New code should use base::Time::Now(). | 154 // it here. New code should use base::Time::Max(). |
| 173 DCHECK(delete_end_ != base::Time()); | 155 DCHECK(delete_end_ != base::Time()); |
| 174 if (delete_end_ == base::Time()) | 156 if (delete_end_ == base::Time()) |
| 175 delete_end_ = base::Time::Now(); | 157 delete_end_ = base::Time::Max(); |
| 176 } | 158 } |
| 177 | 159 |
| 178 BrowsingDataRemover::~BrowsingDataRemover() { | 160 BrowsingDataRemover::~BrowsingDataRemover() { |
| 179 DCHECK(AllDone()); | 161 DCHECK(AllDone()); |
| 180 } | 162 } |
| 181 | 163 |
| 182 // Static. | 164 // Static. |
| 183 void BrowsingDataRemover::set_removing(bool removing) { | 165 void BrowsingDataRemover::set_removing(bool is_removing) { |
| 184 DCHECK(removing_ != removing); | 166 DCHECK(is_removing_ != is_removing); |
| 185 removing_ = removing; | 167 is_removing_ = is_removing; |
| 186 } | 168 } |
| 187 | 169 |
| 188 // Static. | 170 // Static. |
| 189 int BrowsingDataRemover::GenerateQuotaClientMask(int remove_mask) { | 171 int BrowsingDataRemover::GenerateQuotaClientMask(int remove_mask) { |
| 190 int quota_client_mask = 0; | 172 int quota_client_mask = 0; |
| 191 if (remove_mask & BrowsingDataRemover::REMOVE_FILE_SYSTEMS) | 173 if (remove_mask & BrowsingDataRemover::REMOVE_FILE_SYSTEMS) |
| 192 quota_client_mask |= quota::QuotaClient::kFileSystem; | 174 quota_client_mask |= quota::QuotaClient::kFileSystem; |
| 193 if (remove_mask & BrowsingDataRemover::REMOVE_WEBSQL) | 175 if (remove_mask & BrowsingDataRemover::REMOVE_WEBSQL) |
| 194 quota_client_mask |= quota::QuotaClient::kDatabase; | 176 quota_client_mask |= quota::QuotaClient::kDatabase; |
| 195 if (remove_mask & BrowsingDataRemover::REMOVE_APPCACHE) | 177 if (remove_mask & BrowsingDataRemover::REMOVE_APPCACHE) |
| (...skipping 730 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 926 BrowserThread::UI, FROM_HERE, | 908 BrowserThread::UI, FROM_HERE, |
| 927 base::Bind(&BrowsingDataRemover::OnClearedFormData, | 909 base::Bind(&BrowsingDataRemover::OnClearedFormData, |
| 928 base::Unretained(this))); | 910 base::Unretained(this))); |
| 929 } | 911 } |
| 930 | 912 |
| 931 void BrowsingDataRemover::OnClearedFormData() { | 913 void BrowsingDataRemover::OnClearedFormData() { |
| 932 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 914 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 933 waiting_for_clear_form_ = false; | 915 waiting_for_clear_form_ = false; |
| 934 NotifyAndDeleteIfDone(); | 916 NotifyAndDeleteIfDone(); |
| 935 } | 917 } |
| OLD | NEW |