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 // Goes through the list of offline pages, compiling the following two metrics: |
| 154 // - a count of the pages with the same URL |
| 155 // - The difference between the |created_before| time and the creation time of |
| 156 // the page with the closest creation time before |created_before|. |
| 157 // Returns true if there was a page that was saved before |created_before| with |
| 158 // a matching URL. |
| 159 bool GetMatchingURLCountAndMostRecentCreationTime( |
| 160 const std::map<int64_t, OfflinePageItem>& offline_pages, |
| 161 std::string name_space, |
| 162 const GURL& url, |
| 163 base::Time created_before, |
| 164 int* matching_url_count, |
| 165 base::TimeDelta* most_recent_creation_time) { |
| 166 int count = 0; |
| 167 |
| 168 // Create a time that is very old, so that any valid time will be newer than |
| 169 // it. |
| 170 base::Time latest_time; |
| 171 bool matching_page = false; |
| 172 |
| 173 for (auto& id_page_pair : offline_pages) { |
| 174 if (id_page_pair.second.client_id.name_space == name_space && |
| 175 url == id_page_pair.second.url) { |
| 176 count++; |
| 177 base::Time page_creation_time = id_page_pair.second.creation_time; |
| 178 if (page_creation_time < created_before && |
| 179 page_creation_time > latest_time) { |
| 180 latest_time = page_creation_time; |
| 181 matching_page = true; |
| 182 } |
| 183 } |
| 184 } |
| 185 |
| 186 if (matching_url_count != nullptr) |
| 187 *matching_url_count = count; |
| 188 if (most_recent_creation_time != nullptr && latest_time != base::Time()) |
| 189 *most_recent_creation_time = created_before - latest_time; |
| 190 |
| 191 return matching_page; |
| 192 } |
| 193 |
| 194 void ReportPageHistogramAfterSave( |
| 195 const std::map<int64_t, OfflinePageItem>& offline_pages, |
| 196 const OfflinePageItem& offline_page) { |
154 // The histogram below is an expansion of the UMA_HISTOGRAM_TIMES | 197 // The histogram below is an expansion of the UMA_HISTOGRAM_TIMES |
155 // macro adapted to allow for a dynamically suffixed histogram name. | 198 // macro adapted to allow for a dynamically suffixed histogram name. |
156 // Note: The factory creates and owns the histogram. | 199 // Note: The factory creates and owns the histogram. |
157 base::HistogramBase* histogram = base::Histogram::FactoryTimeGet( | 200 base::HistogramBase* histogram = base::Histogram::FactoryTimeGet( |
158 AddHistogramSuffix(offline_page.client_id, "OfflinePages.SavePageTime"), | 201 AddHistogramSuffix(offline_page.client_id, "OfflinePages.SavePageTime"), |
159 base::TimeDelta::FromMilliseconds(1), base::TimeDelta::FromSeconds(10), | 202 base::TimeDelta::FromMilliseconds(1), base::TimeDelta::FromSeconds(10), |
160 50, base::HistogramBase::kUmaTargetedHistogramFlag); | 203 50, base::HistogramBase::kUmaTargetedHistogramFlag); |
161 histogram->AddTime(base::Time::Now() - offline_page.creation_time); | 204 histogram->AddTime(base::Time::Now() - offline_page.creation_time); |
162 | 205 |
163 // The histogram below is an expansion of the UMA_HISTOGRAM_CUSTOM_COUNTS | 206 // The histogram below is an expansion of the UMA_HISTOGRAM_CUSTOM_COUNTS |
164 // macro adapted to allow for a dynamically suffixed histogram name. | 207 // macro adapted to allow for a dynamically suffixed histogram name. |
165 // Note: The factory creates and owns the histogram. | 208 // Note: The factory creates and owns the histogram. |
166 // Reported as Kb between 1Kb and 10Mb. | 209 // Reported as Kb between 1Kb and 10Mb. |
167 histogram = base::Histogram::FactoryGet( | 210 histogram = base::Histogram::FactoryGet( |
168 AddHistogramSuffix(offline_page.client_id, "OfflinePages.PageSize"), | 211 AddHistogramSuffix(offline_page.client_id, "OfflinePages.PageSize"), |
169 1, 10000, 50, base::HistogramBase::kUmaTargetedHistogramFlag); | 212 1, 10000, 50, base::HistogramBase::kUmaTargetedHistogramFlag); |
170 histogram->Add(offline_page.file_size / 1024); | 213 histogram->Add(offline_page.file_size / 1024); |
| 214 |
| 215 if (offline_page.client_id.name_space == kDownloadNamespace) { |
| 216 int matching_url_count; |
| 217 base::TimeDelta time_since_most_recent_duplicate; |
| 218 if (GetMatchingURLCountAndMostRecentCreationTime( |
| 219 offline_pages, offline_page.client_id.name_space, offline_page.url, |
| 220 offline_page.creation_time, &matching_url_count, |
| 221 &time_since_most_recent_duplicate)) { |
| 222 UMA_HISTOGRAM_CUSTOM_TIMES( |
| 223 "OfflinePages.DownloadSavedPageTimeSinceDuplicateSaved", |
| 224 time_since_most_recent_duplicate, base::TimeDelta::FromSeconds(1), |
| 225 base::TimeDelta::FromDays(7), 50); |
| 226 } |
| 227 UMA_HISTOGRAM_CUSTOM_COUNTS("OfflinePages.DownloadSavedPageDuplicateCount", |
| 228 matching_url_count, 1, 20, 10); |
| 229 } |
171 } | 230 } |
172 | 231 |
173 void ReportPageHistogramsAfterDelete( | 232 void ReportPageHistogramsAfterDelete( |
174 const std::map<int64_t, OfflinePageItem>& offline_pages, | 233 const std::map<int64_t, OfflinePageItem>& offline_pages, |
175 const std::vector<int64_t>& deleted_offline_ids) { | 234 const std::vector<int64_t>& deleted_offline_ids) { |
176 const int max_minutes = base::TimeDelta::FromDays(365).InMinutes(); | 235 const int max_minutes = base::TimeDelta::FromDays(365).InMinutes(); |
177 base::Time now = base::Time::Now(); | 236 base::Time now = base::Time::Now(); |
178 int64_t total_size = 0; | 237 int64_t total_size = 0; |
179 for (int64_t offline_id : deleted_offline_ids) { | 238 for (int64_t offline_id : deleted_offline_ids) { |
180 auto iter = offline_pages.find(offline_id); | 239 auto iter = offline_pages.find(offline_id); |
181 if (iter == offline_pages.end()) | 240 if (iter == offline_pages.end()) |
182 continue; | 241 continue; |
| 242 |
183 total_size += iter->second.file_size; | 243 total_size += iter->second.file_size; |
184 ClientId client_id = iter->second.client_id; | 244 ClientId client_id = iter->second.client_id; |
185 | 245 |
| 246 if (client_id.name_space == kDownloadNamespace) { |
| 247 int remaining_pages_with_url; |
| 248 GetMatchingURLCountAndMostRecentCreationTime( |
| 249 offline_pages, iter->second.client_id.name_space, iter->second.url, |
| 250 base::Time::Max(), &remaining_pages_with_url, nullptr); |
| 251 UMA_HISTOGRAM_CUSTOM_COUNTS( |
| 252 "OfflinePages.DownloadDeletedPageDuplicateCount", |
| 253 remaining_pages_with_url, 1, 20, 10); |
| 254 } |
| 255 |
186 // The histograms below are an expansion of the UMA_HISTOGRAM_CUSTOM_COUNTS | 256 // The histograms below are an expansion of the UMA_HISTOGRAM_CUSTOM_COUNTS |
187 // macro adapted to allow for a dynamically suffixed histogram name. | 257 // macro adapted to allow for a dynamically suffixed histogram name. |
188 // Note: The factory creates and owns the histogram. | 258 // Note: The factory creates and owns the histogram. |
189 base::HistogramBase* histogram = base::Histogram::FactoryGet( | 259 base::HistogramBase* histogram = base::Histogram::FactoryGet( |
190 AddHistogramSuffix(client_id, "OfflinePages.PageLifetime"), | 260 AddHistogramSuffix(client_id, "OfflinePages.PageLifetime"), |
191 1, max_minutes, 100, base::HistogramBase::kUmaTargetedHistogramFlag); | 261 1, max_minutes, 100, base::HistogramBase::kUmaTargetedHistogramFlag); |
192 histogram->Add((now - iter->second.creation_time).InMinutes()); | 262 histogram->Add((now - iter->second.creation_time).InMinutes()); |
193 | 263 |
194 histogram = base::Histogram::FactoryGet( | 264 histogram = base::Histogram::FactoryGet( |
195 AddHistogramSuffix( | 265 AddHistogramSuffix( |
(...skipping 533 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
729 | 799 |
730 void OfflinePageModelImpl::OnAddOfflinePageDone( | 800 void OfflinePageModelImpl::OnAddOfflinePageDone( |
731 OfflinePageArchiver* archiver, | 801 OfflinePageArchiver* archiver, |
732 const SavePageCallback& callback, | 802 const SavePageCallback& callback, |
733 const OfflinePageItem& offline_page, | 803 const OfflinePageItem& offline_page, |
734 bool success) { | 804 bool success) { |
735 SavePageResult result; | 805 SavePageResult result; |
736 if (success) { | 806 if (success) { |
737 offline_pages_[offline_page.offline_id] = offline_page; | 807 offline_pages_[offline_page.offline_id] = offline_page; |
738 result = SavePageResult::SUCCESS; | 808 result = SavePageResult::SUCCESS; |
739 ReportPageHistogramAfterSave(offline_page); | 809 ReportPageHistogramAfterSave(offline_pages_, offline_page); |
740 offline_event_logger_.RecordPageSaved( | 810 offline_event_logger_.RecordPageSaved( |
741 offline_page.client_id.name_space, offline_page.url.spec(), | 811 offline_page.client_id.name_space, offline_page.url.spec(), |
742 std::to_string(offline_page.offline_id)); | 812 std::to_string(offline_page.offline_id)); |
743 } else { | 813 } else { |
744 result = SavePageResult::STORE_FAILURE; | 814 result = SavePageResult::STORE_FAILURE; |
745 } | 815 } |
746 InformSavePageDone(callback, result, offline_page.client_id, | 816 InformSavePageDone(callback, result, offline_page.client_id, |
747 offline_page.offline_id); | 817 offline_page.offline_id); |
748 if (result == SavePageResult::SUCCESS) { | 818 if (result == SavePageResult::SUCCESS) { |
749 DeleteExistingPagesWithSameURL(offline_page); | 819 DeleteExistingPagesWithSameURL(offline_page); |
(...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1070 void OfflinePageModelImpl::RunWhenLoaded(const base::Closure& task) { | 1140 void OfflinePageModelImpl::RunWhenLoaded(const base::Closure& task) { |
1071 if (!is_loaded_) { | 1141 if (!is_loaded_) { |
1072 delayed_tasks_.push_back(task); | 1142 delayed_tasks_.push_back(task); |
1073 return; | 1143 return; |
1074 } | 1144 } |
1075 | 1145 |
1076 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, task); | 1146 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, task); |
1077 } | 1147 } |
1078 | 1148 |
1079 } // namespace offline_pages | 1149 } // namespace offline_pages |
OLD | NEW |