| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "base/bind.h" | 5 #include "base/bind.h" |
| 6 #include "components/browsing_data/core/pref_names.h" | 6 #include "components/browsing_data/core/pref_names.h" |
| 7 #include "ios/chrome/browser/browsing_data/cache_counter.h" | 7 #include "ios/chrome/browser/browsing_data/cache_counter.h" |
| 8 #include "ios/web/public/browser_state.h" | 8 #include "ios/web/public/browser_state.h" |
| 9 #include "ios/web/public/web_thread.h" | 9 #include "ios/web/public/web_thread.h" |
| 10 #include "net/base/completion_callback.h" | 10 #include "net/base/completion_callback.h" |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 103 Step next_step_; | 103 Step next_step_; |
| 104 scoped_refptr<net::URLRequestContextGetter> context_getter_; | 104 scoped_refptr<net::URLRequestContextGetter> context_getter_; |
| 105 net::CompletionCallback result_callback_; | 105 net::CompletionCallback result_callback_; |
| 106 int result_; | 106 int result_; |
| 107 disk_cache::Backend* backend_; | 107 disk_cache::Backend* backend_; |
| 108 }; | 108 }; |
| 109 | 109 |
| 110 } // namespace | 110 } // namespace |
| 111 | 111 |
| 112 CacheCounter::CacheCounter(web::BrowserState* browser_state) | 112 CacheCounter::CacheCounter(web::BrowserState* browser_state) |
| 113 : pending_(false), browser_state_(browser_state), weak_ptr_factory_(this) {} | 113 : browser_state_(browser_state), weak_ptr_factory_(this) {} |
| 114 | 114 |
| 115 CacheCounter::~CacheCounter() {} | 115 CacheCounter::~CacheCounter() {} |
| 116 | 116 |
| 117 const char* CacheCounter::GetPrefName() const { | 117 const char* CacheCounter::GetPrefName() const { |
| 118 return browsing_data::prefs::kDeleteCache; | 118 return browsing_data::prefs::kDeleteCache; |
| 119 } | 119 } |
| 120 | 120 |
| 121 void CacheCounter::Count() { | 121 void CacheCounter::Count() { |
| 122 // TODO(msramek): disk_cache::Backend currently does not implement counting | 122 // TODO(msramek): disk_cache::Backend currently does not implement counting |
| 123 // for subsets of cache, only for the entire cache. Thus, we ignore the time | 123 // for subsets of cache, only for the entire cache. Thus, we ignore the time |
| 124 // period setting and always request counting for the unbounded time interval. | 124 // period setting and always request counting for the unbounded time interval. |
| 125 // It is up to the UI to interpret the results for finite time intervals as | 125 // It is up to the UI to interpret the results for finite time intervals as |
| 126 // upper estimates. | 126 // upper estimates. |
| 127 pending_ = true; | |
| 128 | |
| 129 // IOThreadCacheCounter deletes itself when done. | 127 // IOThreadCacheCounter deletes itself when done. |
| 130 (new IOThreadCacheCounter(browser_state_->GetRequestContext(), | 128 (new IOThreadCacheCounter(browser_state_->GetRequestContext(), |
| 131 base::Bind(&CacheCounter::OnCacheSizeCalculated, | 129 base::Bind(&CacheCounter::OnCacheSizeCalculated, |
| 132 weak_ptr_factory_.GetWeakPtr()))) | 130 weak_ptr_factory_.GetWeakPtr()))) |
| 133 ->Count(); | 131 ->Count(); |
| 134 } | 132 } |
| 135 | 133 |
| 136 void CacheCounter::OnCacheSizeCalculated(int result_bytes) { | 134 void CacheCounter::OnCacheSizeCalculated(int result_bytes) { |
| 137 pending_ = false; | |
| 138 | |
| 139 // A value less than 0 means a net error code. | 135 // A value less than 0 means a net error code. |
| 140 if (result_bytes < 0) | 136 if (result_bytes < 0) |
| 141 return; | 137 return; |
| 142 | 138 |
| 143 ReportResult(result_bytes); | 139 ReportResult(result_bytes); |
| 144 } | 140 } |
| OLD | NEW |