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/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" |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
143 // Note: The factory creates and owns the histogram. | 143 // Note: The factory creates and owns the histogram. |
144 base::HistogramBase* histogram = base::LinearHistogram::FactoryGet( | 144 base::HistogramBase* histogram = base::LinearHistogram::FactoryGet( |
145 AddHistogramSuffix(client_id, "OfflinePages.SavePageResult"), | 145 AddHistogramSuffix(client_id, "OfflinePages.SavePageResult"), |
146 1, | 146 1, |
147 static_cast<int>(SavePageResult::RESULT_COUNT), | 147 static_cast<int>(SavePageResult::RESULT_COUNT), |
148 static_cast<int>(SavePageResult::RESULT_COUNT) + 1, | 148 static_cast<int>(SavePageResult::RESULT_COUNT) + 1, |
149 base::HistogramBase::kUmaTargetedHistogramFlag); | 149 base::HistogramBase::kUmaTargetedHistogramFlag); |
150 histogram->Add(static_cast<int>(result)); | 150 histogram->Add(static_cast<int>(result)); |
151 } | 151 } |
152 | 152 |
153 void ReportPageHistogramAfterSave(const OfflinePageItem& offline_page) { | 153 bool GetMatchingURLCountAndMostRecentCreationTime( |
154 const std::map<int64_t, OfflinePageItem>& offline_pages, | |
155 std::string name_space, | |
156 const GURL& url, | |
157 base::Time created_before, | |
158 int* matching_url_count, | |
159 base::TimeDelta* most_recent_creation_time) { | |
160 int count = 0; | |
161 | |
162 // Create a time that is very old, so that any valid time will be newer than | |
163 // it. | |
164 base::Time latest_time; | |
165 bool matching_page; | |
166 | |
167 for (auto& id_page_pair : offline_pages) { | |
168 if (id_page_pair.second.client_id.name_space == name_space && | |
169 url == id_page_pair.second.url) { | |
170 count++; | |
fgorski
2016/09/07 22:08:35
shouldn't this be incremented when you have a matc
dewittj
2016/09/08 22:49:20
In the case of saving then it's equivalent. But i
| |
171 base::Time page_creation_time = id_page_pair.second.creation_time; | |
172 if (page_creation_time < created_before && | |
173 page_creation_time > latest_time) { | |
174 latest_time = page_creation_time; | |
175 matching_page = true; | |
176 } | |
177 } | |
178 } | |
179 | |
180 if (matching_url_count != nullptr) | |
181 *matching_url_count = count; | |
182 if (most_recent_creation_time != nullptr && latest_time != base::Time()) | |
183 *most_recent_creation_time = created_before - latest_time; | |
184 | |
185 return matching_page; | |
186 } | |
187 | |
188 void ReportPageHistogramAfterSave( | |
189 const std::map<int64_t, OfflinePageItem>& offline_pages, | |
190 const OfflinePageItem& offline_page) { | |
154 // The histogram below is an expansion of the UMA_HISTOGRAM_TIMES | 191 // The histogram below is an expansion of the UMA_HISTOGRAM_TIMES |
155 // macro adapted to allow for a dynamically suffixed histogram name. | 192 // macro adapted to allow for a dynamically suffixed histogram name. |
156 // Note: The factory creates and owns the histogram. | 193 // Note: The factory creates and owns the histogram. |
157 base::HistogramBase* histogram = base::Histogram::FactoryTimeGet( | 194 base::HistogramBase* histogram = base::Histogram::FactoryTimeGet( |
158 AddHistogramSuffix(offline_page.client_id, "OfflinePages.SavePageTime"), | 195 AddHistogramSuffix(offline_page.client_id, "OfflinePages.SavePageTime"), |
159 base::TimeDelta::FromMilliseconds(1), base::TimeDelta::FromSeconds(10), | 196 base::TimeDelta::FromMilliseconds(1), base::TimeDelta::FromSeconds(10), |
160 50, base::HistogramBase::kUmaTargetedHistogramFlag); | 197 50, base::HistogramBase::kUmaTargetedHistogramFlag); |
161 histogram->AddTime(base::Time::Now() - offline_page.creation_time); | 198 histogram->AddTime(base::Time::Now() - offline_page.creation_time); |
162 | 199 |
163 // The histogram below is an expansion of the UMA_HISTOGRAM_CUSTOM_COUNTS | 200 // The histogram below is an expansion of the UMA_HISTOGRAM_CUSTOM_COUNTS |
164 // macro adapted to allow for a dynamically suffixed histogram name. | 201 // macro adapted to allow for a dynamically suffixed histogram name. |
165 // Note: The factory creates and owns the histogram. | 202 // Note: The factory creates and owns the histogram. |
166 // Reported as Kb between 1Kb and 10Mb. | 203 // Reported as Kb between 1Kb and 10Mb. |
167 histogram = base::Histogram::FactoryGet( | 204 histogram = base::Histogram::FactoryGet( |
168 AddHistogramSuffix(offline_page.client_id, "OfflinePages.PageSize"), | 205 AddHistogramSuffix(offline_page.client_id, "OfflinePages.PageSize"), |
169 1, 10000, 50, base::HistogramBase::kUmaTargetedHistogramFlag); | 206 1, 10000, 50, base::HistogramBase::kUmaTargetedHistogramFlag); |
170 histogram->Add(offline_page.file_size / 1024); | 207 histogram->Add(offline_page.file_size / 1024); |
208 | |
209 if (offline_page.client_id.name_space == kDownloadNamespace) { | |
210 int matching_url_count; | |
211 base::TimeDelta time_since_most_recent_duplicate; | |
212 if (GetMatchingURLCountAndMostRecentCreationTime( | |
213 offline_pages, offline_page.client_id.name_space, offline_page.url, | |
214 offline_page.creation_time, &matching_url_count, | |
215 &time_since_most_recent_duplicate)) { | |
216 UMA_HISTOGRAM_CUSTOM_TIMES( | |
217 "OfflinePages.DownloadSavedPageTimeSinceDuplicateSaved", | |
218 time_since_most_recent_duplicate, | |
219 base::TimeDelta::FromMilliseconds(1), base::TimeDelta::FromDays(7), | |
220 200); | |
221 } | |
222 UMA_HISTOGRAM_COUNTS_100("OfflinePages.DownloadSavedPageDuplicateCount", | |
223 matching_url_count); | |
224 } | |
171 } | 225 } |
172 | 226 |
173 void ReportPageHistogramsAfterDelete( | 227 void ReportPageHistogramsAfterDelete( |
174 const std::map<int64_t, OfflinePageItem>& offline_pages, | 228 const std::map<int64_t, OfflinePageItem>& offline_pages, |
175 const std::vector<int64_t>& deleted_offline_ids) { | 229 const std::vector<int64_t>& deleted_offline_ids) { |
176 const int max_minutes = base::TimeDelta::FromDays(365).InMinutes(); | 230 const int max_minutes = base::TimeDelta::FromDays(365).InMinutes(); |
177 base::Time now = base::Time::Now(); | 231 base::Time now = base::Time::Now(); |
178 int64_t total_size = 0; | 232 int64_t total_size = 0; |
179 for (int64_t offline_id : deleted_offline_ids) { | 233 for (int64_t offline_id : deleted_offline_ids) { |
180 auto iter = offline_pages.find(offline_id); | 234 auto iter = offline_pages.find(offline_id); |
181 if (iter == offline_pages.end()) | 235 if (iter == offline_pages.end()) { |
fgorski
2016/09/07 22:08:35
nit: {} not needed.
dewittj
2016/09/08 22:49:20
Done.
| |
182 continue; | 236 continue; |
237 } | |
183 total_size += iter->second.file_size; | 238 total_size += iter->second.file_size; |
184 ClientId client_id = iter->second.client_id; | 239 ClientId client_id = iter->second.client_id; |
185 | 240 |
241 if (client_id.name_space == kDownloadNamespace) { | |
242 int remaining_pages_with_url; | |
243 GetMatchingURLCountAndMostRecentCreationTime( | |
244 offline_pages, iter->second.client_id.name_space, iter->second.url, | |
245 base::Time::Max(), &remaining_pages_with_url, nullptr); | |
246 UMA_HISTOGRAM_COUNTS_100("OfflinePages.DownloadDeletedPageDuplicateCount", | |
247 remaining_pages_with_url); | |
248 } | |
249 | |
186 // 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 |
187 // macro adapted to allow for a dynamically suffixed histogram name. | 251 // macro adapted to allow for a dynamically suffixed histogram name. |
188 // Note: The factory creates and owns the histogram. | 252 // Note: The factory creates and owns the histogram. |
189 base::HistogramBase* histogram = base::Histogram::FactoryGet( | 253 base::HistogramBase* histogram = base::Histogram::FactoryGet( |
190 AddHistogramSuffix(client_id, "OfflinePages.PageLifetime"), | 254 AddHistogramSuffix(client_id, "OfflinePages.PageLifetime"), |
191 1, max_minutes, 100, base::HistogramBase::kUmaTargetedHistogramFlag); | 255 1, max_minutes, 100, base::HistogramBase::kUmaTargetedHistogramFlag); |
192 histogram->Add((now - iter->second.creation_time).InMinutes()); | 256 histogram->Add((now - iter->second.creation_time).InMinutes()); |
193 | 257 |
194 histogram = base::Histogram::FactoryGet( | 258 histogram = base::Histogram::FactoryGet( |
195 AddHistogramSuffix( | 259 AddHistogramSuffix( |
(...skipping 533 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
729 | 793 |
730 void OfflinePageModelImpl::OnAddOfflinePageDone( | 794 void OfflinePageModelImpl::OnAddOfflinePageDone( |
731 OfflinePageArchiver* archiver, | 795 OfflinePageArchiver* archiver, |
732 const SavePageCallback& callback, | 796 const SavePageCallback& callback, |
733 const OfflinePageItem& offline_page, | 797 const OfflinePageItem& offline_page, |
734 bool success) { | 798 bool success) { |
735 SavePageResult result; | 799 SavePageResult result; |
736 if (success) { | 800 if (success) { |
737 offline_pages_[offline_page.offline_id] = offline_page; | 801 offline_pages_[offline_page.offline_id] = offline_page; |
738 result = SavePageResult::SUCCESS; | 802 result = SavePageResult::SUCCESS; |
739 ReportPageHistogramAfterSave(offline_page); | 803 ReportPageHistogramAfterSave(offline_pages_, offline_page); |
740 offline_event_logger_.RecordPageSaved( | 804 offline_event_logger_.RecordPageSaved( |
741 offline_page.client_id.name_space, offline_page.url.spec(), | 805 offline_page.client_id.name_space, offline_page.url.spec(), |
742 std::to_string(offline_page.offline_id)); | 806 std::to_string(offline_page.offline_id)); |
743 } else { | 807 } else { |
744 result = SavePageResult::STORE_FAILURE; | 808 result = SavePageResult::STORE_FAILURE; |
745 } | 809 } |
746 InformSavePageDone(callback, result, offline_page.client_id, | 810 InformSavePageDone(callback, result, offline_page.client_id, |
747 offline_page.offline_id); | 811 offline_page.offline_id); |
748 if (result == SavePageResult::SUCCESS) { | 812 if (result == SavePageResult::SUCCESS) { |
749 DeleteExistingPagesWithSameURL(offline_page); | 813 DeleteExistingPagesWithSameURL(offline_page); |
(...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1070 void OfflinePageModelImpl::RunWhenLoaded(const base::Closure& task) { | 1134 void OfflinePageModelImpl::RunWhenLoaded(const base::Closure& task) { |
1071 if (!is_loaded_) { | 1135 if (!is_loaded_) { |
1072 delayed_tasks_.push_back(task); | 1136 delayed_tasks_.push_back(task); |
1073 return; | 1137 return; |
1074 } | 1138 } |
1075 | 1139 |
1076 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, task); | 1140 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, task); |
1077 } | 1141 } |
1078 | 1142 |
1079 } // namespace offline_pages | 1143 } // namespace offline_pages |
OLD | NEW |