| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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/site_data_counter.h" | 5 #include "chrome/browser/browsing_data/site_data_counter.h" |
| 6 | 6 |
| 7 #include "chrome/browser/browsing_data/site_data_counting_helper.h" | 7 #include "chrome/browser/browsing_data/site_data_counting_helper.h" |
| 8 #include "components/browsing_data/core/pref_names.h" | 8 #include "components/browsing_data/core/pref_names.h" |
| 9 #include "content/public/browser/browser_thread.h" | 9 #include "content/public/browser/browser_thread.h" |
| 10 | 10 |
| 11 using content::BrowserThread; | 11 using content::BrowserThread; |
| 12 | 12 |
| 13 SiteDataCounter::SiteDataCounter(Profile* profile) | 13 SiteDataCounter::SiteDataCounter(Profile* profile) |
| 14 : profile_(profile), weak_ptr_factory_(this) {} | 14 : profile_(profile), weak_ptr_factory_(this) {} |
| 15 | 15 |
| 16 SiteDataCounter::~SiteDataCounter() {} | 16 SiteDataCounter::~SiteDataCounter() {} |
| 17 | 17 |
| 18 const char* SiteDataCounter::GetPrefName() const { | 18 const char* SiteDataCounter::GetPrefName() const { |
| 19 return browsing_data::prefs::kDeleteCookies; | 19 return browsing_data::prefs::kDeleteCookies; |
| 20 } | 20 } |
| 21 | 21 |
| 22 void SiteDataCounter::Count() { | 22 void SiteDataCounter::Count() { |
| 23 // Cancel existing requests. |
| 24 weak_ptr_factory_.InvalidateWeakPtrs(); |
| 23 base::Time begin = GetPeriodStart(); | 25 base::Time begin = GetPeriodStart(); |
| 24 auto done_callback = | 26 auto done_callback = |
| 25 base::Bind(&SiteDataCounter::Done, weak_ptr_factory_.GetWeakPtr()); | 27 base::Bind(&SiteDataCounter::Done, weak_ptr_factory_.GetWeakPtr()); |
| 26 // Use a helper class that owns itself to avoid issues when SiteDataCounter is | 28 // Use a helper class that owns itself to avoid issues when SiteDataCounter is |
| 27 // deleted before counting finished. | 29 // deleted before counting finished. |
| 28 auto* helper = new SiteDataCountingHelper(profile_, begin, done_callback); | 30 auto* helper = new SiteDataCountingHelper(profile_, begin, done_callback); |
| 29 helper->CountAndDestroySelfWhenFinished(); | 31 helper->CountAndDestroySelfWhenFinished(); |
| 30 } | 32 } |
| 31 | 33 |
| 32 void SiteDataCounter::Done(int origin_count) { | 34 void SiteDataCounter::Done(int origin_count) { |
| 33 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 35 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 34 ReportResult(origin_count); | 36 ReportResult(origin_count); |
| 35 } | 37 } |
| OLD | NEW |