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 "components/offline_pages/offline_page_model_impl.h" | 5 #include "components/offline_pages/core/offline_page_model_impl.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <limits> | 8 #include <limits> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
11 #include "base/files/file_util.h" | 11 #include "base/files/file_util.h" |
12 #include "base/location.h" | 12 #include "base/location.h" |
13 #include "base/logging.h" | 13 #include "base/logging.h" |
14 #include "base/metrics/histogram_macros.h" | 14 #include "base/metrics/histogram_macros.h" |
15 #include "base/rand_util.h" | 15 #include "base/rand_util.h" |
16 #include "base/sequenced_task_runner.h" | 16 #include "base/sequenced_task_runner.h" |
17 #include "base/strings/string16.h" | 17 #include "base/strings/string16.h" |
18 #include "base/strings/string_number_conversions.h" | 18 #include "base/strings/string_number_conversions.h" |
19 #include "base/threading/thread_task_runner_handle.h" | 19 #include "base/threading/thread_task_runner_handle.h" |
20 #include "base/time/clock.h" | 20 #include "base/time/clock.h" |
21 #include "base/time/time.h" | 21 #include "base/time/time.h" |
22 #include "components/offline_pages/archive_manager.h" | 22 #include "components/offline_pages/core/archive_manager.h" |
23 #include "components/offline_pages/client_namespace_constants.h" | 23 #include "components/offline_pages/core/client_namespace_constants.h" |
24 #include "components/offline_pages/client_policy_controller.h" | 24 #include "components/offline_pages/core/client_policy_controller.h" |
25 #include "components/offline_pages/offline_page_item.h" | 25 #include "components/offline_pages/core/offline_page_item.h" |
26 #include "components/offline_pages/offline_page_model_query.h" | 26 #include "components/offline_pages/core/offline_page_model_query.h" |
27 #include "components/offline_pages/offline_page_storage_manager.h" | 27 #include "components/offline_pages/core/offline_page_storage_manager.h" |
28 #include "url/gurl.h" | 28 #include "url/gurl.h" |
29 | 29 |
30 using ArchiverResult = offline_pages::OfflinePageArchiver::ArchiverResult; | 30 using ArchiverResult = offline_pages::OfflinePageArchiver::ArchiverResult; |
31 using ClearStorageCallback = | 31 using ClearStorageCallback = |
32 offline_pages::OfflinePageStorageManager::ClearStorageCallback; | 32 offline_pages::OfflinePageStorageManager::ClearStorageCallback; |
33 using ClearStorageResult = | 33 using ClearStorageResult = |
34 offline_pages::OfflinePageStorageManager::ClearStorageResult; | 34 offline_pages::OfflinePageStorageManager::ClearStorageResult; |
35 | 35 |
36 namespace offline_pages { | 36 namespace offline_pages { |
37 | 37 |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
121 1.0 * storage_stats.total_archives_size / | 121 1.0 * storage_stats.total_archives_size / |
122 (storage_stats.total_archives_size + storage_stats.free_disk_space) * | 122 (storage_stats.total_archives_size + storage_stats.free_disk_space) * |
123 100); | 123 100); |
124 UMA_HISTOGRAM_PERCENTAGE( | 124 UMA_HISTOGRAM_PERCENTAGE( |
125 "OfflinePages.DeletePage.TotalPageSizeAsPercentageOfFreeSpace", | 125 "OfflinePages.DeletePage.TotalPageSizeAsPercentageOfFreeSpace", |
126 percentage_of_free); | 126 percentage_of_free); |
127 } | 127 } |
128 } | 128 } |
129 | 129 |
130 void ReportSavePageResultHistogramAfterSave(const ClientId& client_id, | 130 void ReportSavePageResultHistogramAfterSave(const ClientId& client_id, |
131 SavePageResult result) { | 131 SavePageResult result) { |
132 // The histogram below is an expansion of the UMA_HISTOGRAM_ENUMERATION | 132 // The histogram below is an expansion of the UMA_HISTOGRAM_ENUMERATION |
133 // macro adapted to allow for a dynamically suffixed histogram name. | 133 // macro adapted to allow for a dynamically suffixed histogram name. |
134 // Note: The factory creates and owns the histogram. | 134 // Note: The factory creates and owns the histogram. |
135 base::HistogramBase* histogram = base::LinearHistogram::FactoryGet( | 135 base::HistogramBase* histogram = base::LinearHistogram::FactoryGet( |
136 AddHistogramSuffix(client_id, "OfflinePages.SavePageResult"), | 136 AddHistogramSuffix(client_id, "OfflinePages.SavePageResult"), 1, |
137 1, | |
138 static_cast<int>(SavePageResult::RESULT_COUNT), | 137 static_cast<int>(SavePageResult::RESULT_COUNT), |
139 static_cast<int>(SavePageResult::RESULT_COUNT) + 1, | 138 static_cast<int>(SavePageResult::RESULT_COUNT) + 1, |
140 base::HistogramBase::kUmaTargetedHistogramFlag); | 139 base::HistogramBase::kUmaTargetedHistogramFlag); |
141 histogram->Add(static_cast<int>(result)); | 140 histogram->Add(static_cast<int>(result)); |
142 } | 141 } |
143 | 142 |
144 // Goes through the list of offline pages, compiling the following two metrics: | 143 // Goes through the list of offline pages, compiling the following two metrics: |
145 // - a count of the pages with the same URL | 144 // - a count of the pages with the same URL |
146 // - The difference between the |created_before| time and the creation time of | 145 // - The difference between the |created_before| time and the creation time of |
147 // the page with the closest creation time before |created_before|. | 146 // the page with the closest creation time before |created_before|. |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
193 AddHistogramSuffix(offline_page.client_id, "OfflinePages.SavePageTime"), | 192 AddHistogramSuffix(offline_page.client_id, "OfflinePages.SavePageTime"), |
194 base::TimeDelta::FromMilliseconds(1), base::TimeDelta::FromSeconds(10), | 193 base::TimeDelta::FromMilliseconds(1), base::TimeDelta::FromSeconds(10), |
195 50, base::HistogramBase::kUmaTargetedHistogramFlag); | 194 50, base::HistogramBase::kUmaTargetedHistogramFlag); |
196 histogram->AddTime(save_time - offline_page.creation_time); | 195 histogram->AddTime(save_time - offline_page.creation_time); |
197 | 196 |
198 // The histogram below is an expansion of the UMA_HISTOGRAM_CUSTOM_COUNTS | 197 // The histogram below is an expansion of the UMA_HISTOGRAM_CUSTOM_COUNTS |
199 // macro adapted to allow for a dynamically suffixed histogram name. | 198 // macro adapted to allow for a dynamically suffixed histogram name. |
200 // Note: The factory creates and owns the histogram. | 199 // Note: The factory creates and owns the histogram. |
201 // Reported as Kb between 1Kb and 10Mb. | 200 // Reported as Kb between 1Kb and 10Mb. |
202 histogram = base::Histogram::FactoryGet( | 201 histogram = base::Histogram::FactoryGet( |
203 AddHistogramSuffix(offline_page.client_id, "OfflinePages.PageSize"), | 202 AddHistogramSuffix(offline_page.client_id, "OfflinePages.PageSize"), 1, |
204 1, 10000, 50, base::HistogramBase::kUmaTargetedHistogramFlag); | 203 10000, 50, base::HistogramBase::kUmaTargetedHistogramFlag); |
205 histogram->Add(offline_page.file_size / 1024); | 204 histogram->Add(offline_page.file_size / 1024); |
206 | 205 |
207 if (offline_page.client_id.name_space == kDownloadNamespace) { | 206 if (offline_page.client_id.name_space == kDownloadNamespace) { |
208 int matching_url_count; | 207 int matching_url_count; |
209 base::TimeDelta time_since_most_recent_duplicate; | 208 base::TimeDelta time_since_most_recent_duplicate; |
210 if (GetMatchingURLCountAndMostRecentCreationTime( | 209 if (GetMatchingURLCountAndMostRecentCreationTime( |
211 offline_pages, offline_page.client_id.name_space, offline_page.url, | 210 offline_pages, offline_page.client_id.name_space, offline_page.url, |
212 offline_page.creation_time, &matching_url_count, | 211 offline_page.creation_time, &matching_url_count, |
213 &time_since_most_recent_duplicate)) { | 212 &time_since_most_recent_duplicate)) { |
214 // Using CUSTOM_COUNTS instead of time-oriented histogram to record | 213 // Using CUSTOM_COUNTS instead of time-oriented histogram to record |
(...skipping 27 matching lines...) Expand all Loading... |
242 &remaining_pages_with_url, nullptr); | 241 &remaining_pages_with_url, nullptr); |
243 UMA_HISTOGRAM_CUSTOM_COUNTS( | 242 UMA_HISTOGRAM_CUSTOM_COUNTS( |
244 "OfflinePages.DownloadDeletedPageDuplicateCount", | 243 "OfflinePages.DownloadDeletedPageDuplicateCount", |
245 remaining_pages_with_url, 1, 20, 10); | 244 remaining_pages_with_url, 1, 20, 10); |
246 } | 245 } |
247 | 246 |
248 // The histograms below are an expansion of the UMA_HISTOGRAM_CUSTOM_COUNTS | 247 // The histograms below are an expansion of the UMA_HISTOGRAM_CUSTOM_COUNTS |
249 // macro adapted to allow for a dynamically suffixed histogram name. | 248 // macro adapted to allow for a dynamically suffixed histogram name. |
250 // Note: The factory creates and owns the histogram. | 249 // Note: The factory creates and owns the histogram. |
251 base::HistogramBase* histogram = base::Histogram::FactoryGet( | 250 base::HistogramBase* histogram = base::Histogram::FactoryGet( |
252 AddHistogramSuffix(client_id, "OfflinePages.PageLifetime"), | 251 AddHistogramSuffix(client_id, "OfflinePages.PageLifetime"), 1, |
253 1, max_minutes, 100, base::HistogramBase::kUmaTargetedHistogramFlag); | 252 max_minutes, 100, base::HistogramBase::kUmaTargetedHistogramFlag); |
254 histogram->Add((delete_time - page.creation_time).InMinutes()); | 253 histogram->Add((delete_time - page.creation_time).InMinutes()); |
255 | 254 |
256 histogram = base::Histogram::FactoryGet( | 255 histogram = base::Histogram::FactoryGet( |
257 AddHistogramSuffix( | 256 AddHistogramSuffix(client_id, |
258 client_id, "OfflinePages.DeletePage.TimeSinceLastOpen"), | 257 "OfflinePages.DeletePage.TimeSinceLastOpen"), |
259 1, max_minutes, 100, base::HistogramBase::kUmaTargetedHistogramFlag); | 258 1, max_minutes, 100, base::HistogramBase::kUmaTargetedHistogramFlag); |
260 histogram->Add((delete_time - page.last_access_time).InMinutes()); | 259 histogram->Add((delete_time - page.last_access_time).InMinutes()); |
261 | 260 |
262 histogram = base::Histogram::FactoryGet( | 261 histogram = base::Histogram::FactoryGet( |
263 AddHistogramSuffix( | 262 AddHistogramSuffix(client_id, |
264 client_id, "OfflinePages.DeletePage.LastOpenToCreated"), | 263 "OfflinePages.DeletePage.LastOpenToCreated"), |
265 1, max_minutes, 100, base::HistogramBase::kUmaTargetedHistogramFlag); | 264 1, max_minutes, 100, base::HistogramBase::kUmaTargetedHistogramFlag); |
266 histogram->Add((page.last_access_time - page.creation_time).InMinutes()); | 265 histogram->Add((page.last_access_time - page.creation_time).InMinutes()); |
267 | 266 |
268 // Reported as Kb between 1Kb and 10Mb. | 267 // Reported as Kb between 1Kb and 10Mb. |
269 histogram = base::Histogram::FactoryGet( | 268 histogram = base::Histogram::FactoryGet( |
270 AddHistogramSuffix(client_id, "OfflinePages.DeletePage.PageSize"), | 269 AddHistogramSuffix(client_id, "OfflinePages.DeletePage.PageSize"), 1, |
271 1, 10000, 50, base::HistogramBase::kUmaTargetedHistogramFlag); | 270 10000, 50, base::HistogramBase::kUmaTargetedHistogramFlag); |
272 histogram->Add(page.file_size / 1024); | 271 histogram->Add(page.file_size / 1024); |
273 | 272 |
274 histogram = base::Histogram::FactoryGet( | 273 histogram = base::Histogram::FactoryGet( |
275 AddHistogramSuffix(client_id, "OfflinePages.DeletePage.AccessCount"), | 274 AddHistogramSuffix(client_id, "OfflinePages.DeletePage.AccessCount"), 1, |
276 1, 1000000, 50, base::HistogramBase::kUmaTargetedHistogramFlag); | 275 1000000, 50, base::HistogramBase::kUmaTargetedHistogramFlag); |
277 histogram->Add(page.access_count); | 276 histogram->Add(page.access_count); |
278 } | 277 } |
279 | 278 |
280 if (deleted_pages.size() > 1) { | 279 if (deleted_pages.size() > 1) { |
281 UMA_HISTOGRAM_COUNTS("OfflinePages.BatchDelete.Count", | 280 UMA_HISTOGRAM_COUNTS("OfflinePages.BatchDelete.Count", |
282 static_cast<int32_t>(deleted_pages.size())); | 281 static_cast<int32_t>(deleted_pages.size())); |
283 UMA_HISTOGRAM_MEMORY_KB( | 282 UMA_HISTOGRAM_MEMORY_KB("OfflinePages.BatchDelete.TotalPageSize", |
284 "OfflinePages.BatchDelete.TotalPageSize", total_size / 1024); | 283 total_size / 1024); |
285 } | 284 } |
286 } | 285 } |
287 | 286 |
288 void ReportPageHistogramsAfterAccess(const OfflinePageItem& offline_page_item, | 287 void ReportPageHistogramsAfterAccess(const OfflinePageItem& offline_page_item, |
289 const base::Time& access_time) { | 288 const base::Time& access_time) { |
290 // The histogram below is an expansion of the UMA_HISTOGRAM_CUSTOM_COUNTS | 289 // The histogram below is an expansion of the UMA_HISTOGRAM_CUSTOM_COUNTS |
291 // macro adapted to allow for a dynamically suffixed histogram name. | 290 // macro adapted to allow for a dynamically suffixed histogram name. |
292 // Note: The factory creates and owns the histogram. | 291 // Note: The factory creates and owns the histogram. |
293 base::HistogramBase* histogram = base::Histogram::FactoryGet( | 292 base::HistogramBase* histogram = base::Histogram::FactoryGet( |
294 AddHistogramSuffix( | 293 AddHistogramSuffix(offline_page_item.client_id, |
295 offline_page_item.client_id, | 294 offline_page_item.access_count == 0 |
296 offline_page_item.access_count == 0 ? | 295 ? "OfflinePages.FirstOpenSinceCreated" |
297 "OfflinePages.FirstOpenSinceCreated" : | 296 : "OfflinePages.OpenSinceLastOpen"), |
298 "OfflinePages.OpenSinceLastOpen"), | 297 1, kMaxOpenedPageHistogramBucket.InMinutes(), 50, |
299 1, kMaxOpenedPageHistogramBucket.InMinutes(), 50, | 298 base::HistogramBase::kUmaTargetedHistogramFlag); |
300 base::HistogramBase::kUmaTargetedHistogramFlag); | |
301 histogram->Add( | 299 histogram->Add( |
302 (access_time - offline_page_item.last_access_time).InMinutes()); | 300 (access_time - offline_page_item.last_access_time).InMinutes()); |
303 } | 301 } |
304 | 302 |
305 } // namespace | 303 } // namespace |
306 | 304 |
307 // protected | 305 // protected |
308 OfflinePageModelImpl::OfflinePageModelImpl() | 306 OfflinePageModelImpl::OfflinePageModelImpl() |
309 : OfflinePageModel(), is_loaded_(false), weak_ptr_factory_(this) {} | 307 : OfflinePageModel(), is_loaded_(false), weak_ptr_factory_(this) {} |
310 | 308 |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
382 | 380 |
383 // Make a copy of the cached item and update it. The cached item should only | 381 // Make a copy of the cached item and update it. The cached item should only |
384 // be updated upon the successful store operation. | 382 // be updated upon the successful store operation. |
385 OfflinePageItem offline_page_item = iter->second; | 383 OfflinePageItem offline_page_item = iter->second; |
386 | 384 |
387 ReportPageHistogramsAfterAccess(offline_page_item, GetCurrentTime()); | 385 ReportPageHistogramsAfterAccess(offline_page_item, GetCurrentTime()); |
388 | 386 |
389 offline_page_item.last_access_time = GetCurrentTime(); | 387 offline_page_item.last_access_time = GetCurrentTime(); |
390 offline_page_item.access_count++; | 388 offline_page_item.access_count++; |
391 | 389 |
392 std::vector<OfflinePageItem> items = { offline_page_item }; | 390 std::vector<OfflinePageItem> items = {offline_page_item}; |
393 store_->UpdateOfflinePages( | 391 store_->UpdateOfflinePages( |
394 items, base::Bind(&OfflinePageModelImpl::OnMarkPageAccesseDone, | 392 items, base::Bind(&OfflinePageModelImpl::OnMarkPageAccesseDone, |
395 weak_ptr_factory_.GetWeakPtr(), offline_page_item)); | 393 weak_ptr_factory_.GetWeakPtr(), offline_page_item)); |
396 } | 394 } |
397 | 395 |
398 void OfflinePageModelImpl::DeletePagesByOfflineId( | 396 void OfflinePageModelImpl::DeletePagesByOfflineId( |
399 const std::vector<int64_t>& offline_ids, | 397 const std::vector<int64_t>& offline_ids, |
400 const DeletePageCallback& callback) { | 398 const DeletePageCallback& callback) { |
401 RunWhenLoaded(base::Bind(&OfflinePageModelImpl::DoDeletePagesByOfflineId, | 399 RunWhenLoaded(base::Bind(&OfflinePageModelImpl::DoDeletePagesByOfflineId, |
402 weak_ptr_factory_.GetWeakPtr(), offline_ids, | 400 weak_ptr_factory_.GetWeakPtr(), offline_ids, |
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
618 | 616 |
619 void OfflinePageModelImpl::GetPagesByOnlineURLWhenLoadDone( | 617 void OfflinePageModelImpl::GetPagesByOnlineURLWhenLoadDone( |
620 const GURL& online_url, | 618 const GURL& online_url, |
621 const MultipleOfflinePageItemCallback& callback) const { | 619 const MultipleOfflinePageItemCallback& callback) const { |
622 std::vector<OfflinePageItem> result; | 620 std::vector<OfflinePageItem> result; |
623 | 621 |
624 GURL::Replacements remove_params; | 622 GURL::Replacements remove_params; |
625 remove_params.ClearRef(); | 623 remove_params.ClearRef(); |
626 | 624 |
627 GURL online_url_without_fragment = | 625 GURL online_url_without_fragment = |
628 online_url.ReplaceComponents(remove_params); | 626 online_url.ReplaceComponents(remove_params); |
629 | 627 |
630 for (const auto& id_page_pair : offline_pages_) { | 628 for (const auto& id_page_pair : offline_pages_) { |
631 if (id_page_pair.second.IsExpired()) | 629 if (id_page_pair.second.IsExpired()) |
632 continue; | 630 continue; |
633 if (online_url == id_page_pair.second.url) { | 631 if (online_url == id_page_pair.second.url) { |
634 result.push_back(id_page_pair.second); | 632 result.push_back(id_page_pair.second); |
635 continue; | 633 continue; |
636 } | 634 } |
637 // If the full URL does not match, try with the fragment identifier | 635 // If the full URL does not match, try with the fragment identifier |
638 // stripped. | 636 // stripped. |
(...skipping 450 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1089 } | 1087 } |
1090 | 1088 |
1091 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, task); | 1089 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, task); |
1092 } | 1090 } |
1093 | 1091 |
1094 base::Time OfflinePageModelImpl::GetCurrentTime() const { | 1092 base::Time OfflinePageModelImpl::GetCurrentTime() const { |
1095 return testing_clock_ ? testing_clock_->Now() : base::Time::Now(); | 1093 return testing_clock_ ? testing_clock_->Now() : base::Time::Now(); |
1096 } | 1094 } |
1097 | 1095 |
1098 } // namespace offline_pages | 1096 } // namespace offline_pages |
OLD | NEW |