Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(60)

Side by Side Diff: components/offline_pages/core/offline_page_model_impl.cc

Issue 2489443002: Move all components/offline_pages/ files into component/offline_pages/core (Closed)
Patch Set: rebase Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 AddHistogramSuffix(offline_page.client_id, "OfflinePages.SavePageTime"), 194 AddHistogramSuffix(offline_page.client_id, "OfflinePages.SavePageTime"),
196 base::TimeDelta::FromMilliseconds(1), base::TimeDelta::FromSeconds(10), 195 base::TimeDelta::FromMilliseconds(1), base::TimeDelta::FromSeconds(10),
197 50, base::HistogramBase::kUmaTargetedHistogramFlag); 196 50, base::HistogramBase::kUmaTargetedHistogramFlag);
198 histogram->AddTime(save_time - offline_page.creation_time); 197 histogram->AddTime(save_time - offline_page.creation_time);
199 198
200 // The histogram below is an expansion of the UMA_HISTOGRAM_CUSTOM_COUNTS 199 // The histogram below is an expansion of the UMA_HISTOGRAM_CUSTOM_COUNTS
201 // macro adapted to allow for a dynamically suffixed histogram name. 200 // macro adapted to allow for a dynamically suffixed histogram name.
202 // Note: The factory creates and owns the histogram. 201 // Note: The factory creates and owns the histogram.
203 // Reported as Kb between 1Kb and 10Mb. 202 // Reported as Kb between 1Kb and 10Mb.
204 histogram = base::Histogram::FactoryGet( 203 histogram = base::Histogram::FactoryGet(
205 AddHistogramSuffix(offline_page.client_id, "OfflinePages.PageSize"), 204 AddHistogramSuffix(offline_page.client_id, "OfflinePages.PageSize"), 1,
206 1, 10000, 50, base::HistogramBase::kUmaTargetedHistogramFlag); 205 10000, 50, base::HistogramBase::kUmaTargetedHistogramFlag);
207 histogram->Add(offline_page.file_size / 1024); 206 histogram->Add(offline_page.file_size / 1024);
208 207
209 if (policy_controller_->IsSupportedByDownload( 208 if (policy_controller_->IsSupportedByDownload(
210 offline_page.client_id.name_space)) { 209 offline_page.client_id.name_space)) {
211 int matching_url_count; 210 int matching_url_count;
212 base::TimeDelta time_since_most_recent_duplicate; 211 base::TimeDelta time_since_most_recent_duplicate;
213 if (GetMatchingURLCountAndMostRecentCreationTime( 212 if (GetMatchingURLCountAndMostRecentCreationTime(
214 offline_pages, offline_page.client_id.name_space, offline_page.url, 213 offline_pages, offline_page.client_id.name_space, offline_page.url,
215 offline_page.creation_time, &matching_url_count, 214 offline_page.creation_time, &matching_url_count,
216 &time_since_most_recent_duplicate)) { 215 &time_since_most_recent_duplicate)) {
(...skipping 28 matching lines...) Expand all
245 &remaining_pages_with_url, nullptr); 244 &remaining_pages_with_url, nullptr);
246 UMA_HISTOGRAM_CUSTOM_COUNTS( 245 UMA_HISTOGRAM_CUSTOM_COUNTS(
247 "OfflinePages.DownloadDeletedPageDuplicateCount", 246 "OfflinePages.DownloadDeletedPageDuplicateCount",
248 remaining_pages_with_url, 1, 20, 10); 247 remaining_pages_with_url, 1, 20, 10);
249 } 248 }
250 249
251 // The histograms below are an expansion of the UMA_HISTOGRAM_CUSTOM_COUNTS 250 // The histograms below are an expansion of the UMA_HISTOGRAM_CUSTOM_COUNTS
252 // macro adapted to allow for a dynamically suffixed histogram name. 251 // macro adapted to allow for a dynamically suffixed histogram name.
253 // Note: The factory creates and owns the histogram. 252 // Note: The factory creates and owns the histogram.
254 base::HistogramBase* histogram = base::Histogram::FactoryGet( 253 base::HistogramBase* histogram = base::Histogram::FactoryGet(
255 AddHistogramSuffix(client_id, "OfflinePages.PageLifetime"), 254 AddHistogramSuffix(client_id, "OfflinePages.PageLifetime"), 1,
256 1, max_minutes, 100, base::HistogramBase::kUmaTargetedHistogramFlag); 255 max_minutes, 100, base::HistogramBase::kUmaTargetedHistogramFlag);
257 histogram->Add((delete_time - page.creation_time).InMinutes()); 256 histogram->Add((delete_time - page.creation_time).InMinutes());
258 257
259 histogram = base::Histogram::FactoryGet( 258 histogram = base::Histogram::FactoryGet(
260 AddHistogramSuffix( 259 AddHistogramSuffix(client_id,
261 client_id, "OfflinePages.DeletePage.TimeSinceLastOpen"), 260 "OfflinePages.DeletePage.TimeSinceLastOpen"),
262 1, max_minutes, 100, base::HistogramBase::kUmaTargetedHistogramFlag); 261 1, max_minutes, 100, base::HistogramBase::kUmaTargetedHistogramFlag);
263 histogram->Add((delete_time - page.last_access_time).InMinutes()); 262 histogram->Add((delete_time - page.last_access_time).InMinutes());
264 263
265 histogram = base::Histogram::FactoryGet( 264 histogram = base::Histogram::FactoryGet(
266 AddHistogramSuffix( 265 AddHistogramSuffix(client_id,
267 client_id, "OfflinePages.DeletePage.LastOpenToCreated"), 266 "OfflinePages.DeletePage.LastOpenToCreated"),
268 1, max_minutes, 100, base::HistogramBase::kUmaTargetedHistogramFlag); 267 1, max_minutes, 100, base::HistogramBase::kUmaTargetedHistogramFlag);
269 histogram->Add((page.last_access_time - page.creation_time).InMinutes()); 268 histogram->Add((page.last_access_time - page.creation_time).InMinutes());
270 269
271 // Reported as Kb between 1Kb and 10Mb. 270 // Reported as Kb between 1Kb and 10Mb.
272 histogram = base::Histogram::FactoryGet( 271 histogram = base::Histogram::FactoryGet(
273 AddHistogramSuffix(client_id, "OfflinePages.DeletePage.PageSize"), 272 AddHistogramSuffix(client_id, "OfflinePages.DeletePage.PageSize"), 1,
274 1, 10000, 50, base::HistogramBase::kUmaTargetedHistogramFlag); 273 10000, 50, base::HistogramBase::kUmaTargetedHistogramFlag);
275 histogram->Add(page.file_size / 1024); 274 histogram->Add(page.file_size / 1024);
276 275
277 histogram = base::Histogram::FactoryGet( 276 histogram = base::Histogram::FactoryGet(
278 AddHistogramSuffix(client_id, "OfflinePages.DeletePage.AccessCount"), 277 AddHistogramSuffix(client_id, "OfflinePages.DeletePage.AccessCount"), 1,
279 1, 1000000, 50, base::HistogramBase::kUmaTargetedHistogramFlag); 278 1000000, 50, base::HistogramBase::kUmaTargetedHistogramFlag);
280 histogram->Add(page.access_count); 279 histogram->Add(page.access_count);
281 } 280 }
282 281
283 if (deleted_pages.size() > 1) { 282 if (deleted_pages.size() > 1) {
284 UMA_HISTOGRAM_COUNTS("OfflinePages.BatchDelete.Count", 283 UMA_HISTOGRAM_COUNTS("OfflinePages.BatchDelete.Count",
285 static_cast<int32_t>(deleted_pages.size())); 284 static_cast<int32_t>(deleted_pages.size()));
286 UMA_HISTOGRAM_MEMORY_KB( 285 UMA_HISTOGRAM_MEMORY_KB("OfflinePages.BatchDelete.TotalPageSize",
287 "OfflinePages.BatchDelete.TotalPageSize", total_size / 1024); 286 total_size / 1024);
288 } 287 }
289 } 288 }
290 289
291 void ReportPageHistogramsAfterAccess(const OfflinePageItem& offline_page_item, 290 void ReportPageHistogramsAfterAccess(const OfflinePageItem& offline_page_item,
292 const base::Time& access_time) { 291 const base::Time& access_time) {
293 // The histogram below is an expansion of the UMA_HISTOGRAM_CUSTOM_COUNTS 292 // The histogram below is an expansion of the UMA_HISTOGRAM_CUSTOM_COUNTS
294 // macro adapted to allow for a dynamically suffixed histogram name. 293 // macro adapted to allow for a dynamically suffixed histogram name.
295 // Note: The factory creates and owns the histogram. 294 // Note: The factory creates and owns the histogram.
296 base::HistogramBase* histogram = base::Histogram::FactoryGet( 295 base::HistogramBase* histogram = base::Histogram::FactoryGet(
297 AddHistogramSuffix( 296 AddHistogramSuffix(offline_page_item.client_id,
298 offline_page_item.client_id, 297 offline_page_item.access_count == 0
299 offline_page_item.access_count == 0 ? 298 ? "OfflinePages.FirstOpenSinceCreated"
300 "OfflinePages.FirstOpenSinceCreated" : 299 : "OfflinePages.OpenSinceLastOpen"),
301 "OfflinePages.OpenSinceLastOpen"), 300 1, kMaxOpenedPageHistogramBucket.InMinutes(), 50,
302 1, kMaxOpenedPageHistogramBucket.InMinutes(), 50, 301 base::HistogramBase::kUmaTargetedHistogramFlag);
303 base::HistogramBase::kUmaTargetedHistogramFlag);
304 histogram->Add( 302 histogram->Add(
305 (access_time - offline_page_item.last_access_time).InMinutes()); 303 (access_time - offline_page_item.last_access_time).InMinutes());
306 } 304 }
307 305
308 } // namespace 306 } // namespace
309 307
310 // protected 308 // protected
311 OfflinePageModelImpl::OfflinePageModelImpl() 309 OfflinePageModelImpl::OfflinePageModelImpl()
312 : OfflinePageModel(), is_loaded_(false), weak_ptr_factory_(this) {} 310 : OfflinePageModel(), is_loaded_(false), weak_ptr_factory_(this) {}
313 311
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
385 383
386 // Make a copy of the cached item and update it. The cached item should only 384 // Make a copy of the cached item and update it. The cached item should only
387 // be updated upon the successful store operation. 385 // be updated upon the successful store operation.
388 OfflinePageItem offline_page_item = iter->second; 386 OfflinePageItem offline_page_item = iter->second;
389 387
390 ReportPageHistogramsAfterAccess(offline_page_item, GetCurrentTime()); 388 ReportPageHistogramsAfterAccess(offline_page_item, GetCurrentTime());
391 389
392 offline_page_item.last_access_time = GetCurrentTime(); 390 offline_page_item.last_access_time = GetCurrentTime();
393 offline_page_item.access_count++; 391 offline_page_item.access_count++;
394 392
395 std::vector<OfflinePageItem> items = { offline_page_item }; 393 std::vector<OfflinePageItem> items = {offline_page_item};
396 store_->UpdateOfflinePages( 394 store_->UpdateOfflinePages(
397 items, base::Bind(&OfflinePageModelImpl::OnMarkPageAccesseDone, 395 items, base::Bind(&OfflinePageModelImpl::OnMarkPageAccesseDone,
398 weak_ptr_factory_.GetWeakPtr(), offline_page_item)); 396 weak_ptr_factory_.GetWeakPtr(), offline_page_item));
399 } 397 }
400 398
401 void OfflinePageModelImpl::DeletePagesByOfflineId( 399 void OfflinePageModelImpl::DeletePagesByOfflineId(
402 const std::vector<int64_t>& offline_ids, 400 const std::vector<int64_t>& offline_ids,
403 const DeletePageCallback& callback) { 401 const DeletePageCallback& callback) {
404 RunWhenLoaded(base::Bind(&OfflinePageModelImpl::DoDeletePagesByOfflineId, 402 RunWhenLoaded(base::Bind(&OfflinePageModelImpl::DoDeletePagesByOfflineId,
405 weak_ptr_factory_.GetWeakPtr(), offline_ids, 403 weak_ptr_factory_.GetWeakPtr(), offline_ids,
(...skipping 675 matching lines...) Expand 10 before | Expand all | Expand 10 after
1081 } 1079 }
1082 1080
1083 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, task); 1081 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, task);
1084 } 1082 }
1085 1083
1086 base::Time OfflinePageModelImpl::GetCurrentTime() const { 1084 base::Time OfflinePageModelImpl::GetCurrentTime() const {
1087 return testing_clock_ ? testing_clock_->Now() : base::Time::Now(); 1085 return testing_clock_ ? testing_clock_->Now() : base::Time::Now();
1088 } 1086 }
1089 1087
1090 } // namespace offline_pages 1088 } // namespace offline_pages
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698