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

Side by Side Diff: chrome/browser/android/offline_pages/recent_tab_helper.cc

Issue 1967793002: Add some UMA for recent tabs (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: address changes Created 4 years, 7 months 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
« no previous file with comments | « no previous file | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2016 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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 "chrome/browser/android/offline_pages/recent_tab_helper.h" 5 #include "chrome/browser/android/offline_pages/recent_tab_helper.h"
6 6
7 #include <queue> 7 #include <queue>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/location.h" 11 #include "base/location.h"
12 #include "base/logging.h" 12 #include "base/logging.h"
13 #include "base/macros.h" 13 #include "base/macros.h"
14 #include "base/metrics/histogram_macros.h"
14 #include "base/thread_task_runner_handle.h" 15 #include "base/thread_task_runner_handle.h"
15 #include "base/time/time.h" 16 #include "base/time/time.h"
16 #include "chrome/browser/android/offline_pages/offline_page_mhtml_archiver.h" 17 #include "chrome/browser/android/offline_pages/offline_page_mhtml_archiver.h"
17 #include "chrome/browser/android/offline_pages/offline_page_model_factory.h" 18 #include "chrome/browser/android/offline_pages/offline_page_model_factory.h"
18 #include "components/offline_pages/offline_page_item.h" 19 #include "components/offline_pages/offline_page_item.h"
19 #include "components/offline_pages/offline_page_model.h" 20 #include "components/offline_pages/offline_page_model.h"
20 #include "content/public/browser/browser_context.h" 21 #include "content/public/browser/browser_context.h"
21 #include "content/public/browser/browser_thread.h" 22 #include "content/public/browser/browser_thread.h"
22 #include "content/public/browser/navigation_entry.h" 23 #include "content/public/browser/navigation_entry.h"
23 #include "content/public/browser/navigation_handle.h" 24 #include "content/public/browser/navigation_handle.h"
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 // - delete the pages found in the previous step 86 // - delete the pages found in the previous step
86 // - snapshot the current web contents 87 // - snapshot the current web contents
87 // Along the chain, the original URL is passed and compared, to detect 88 // Along the chain, the original URL is passed and compared, to detect
88 // possible navigation and cancel snapshot in that case. 89 // possible navigation and cancel snapshot in that case.
89 void RecentTabHelper::StartSnapshot() { 90 void RecentTabHelper::StartSnapshot() {
90 if (never_do_snapshots_) 91 if (never_do_snapshots_)
91 return; 92 return;
92 93
93 GURL url = web_contents()->GetLastCommittedURL(); 94 GURL url = web_contents()->GetLastCommittedURL();
94 if (!page_model_->CanSavePage(url)) { 95 if (!page_model_->CanSavePage(url)) {
95 // TODO(dimich): Add UMA. Bug 608112. 96 UMA_HISTOGRAM_COUNTS("OfflinePages.CanNotSaveRecentPage", 1);
dewittj 2016/05/10 23:07:56 I wonder if we should have an enumerated histogram
bburns 2016/05/11 16:21:52 I don't feel strongly. Is this detailed in a PRD
dewittj 2016/05/11 16:31:58 nope, not in the PRD. I don't super care about th
fgorski 2016/05/11 16:54:23 Boolean sounds good for this one, as this is a pro
96 return; 97 return;
97 } 98 }
98 99
99 snapshot_url_ = url; 100 snapshot_url_ = url;
100 101
101 // TODO(dimich): Implement automatic cleanup as per design doc, based on 102 // TODO(dimich): Implement automatic cleanup as per design doc, based on
102 // storage limits and page age. 103 // storage limits and page age.
103 // This algorithm (remove pages before making sure the save was successful) 104 // This algorithm (remove pages before making sure the save was successful)
104 // prefers keeping the storage use low and under control by potentially 105 // prefers keeping the storage use low and under control by potentially
105 // sacrificing the current snapshot. 106 // sacrificing the current snapshot.
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 } 174 }
174 175
175 page_model_->SavePage( 176 page_model_->SavePage(
176 snapshot_url_, client_id(), std::move(archiver), 177 snapshot_url_, client_id(), std::move(archiver),
177 base::Bind(&RecentTabHelper::SavePageCallback, 178 base::Bind(&RecentTabHelper::SavePageCallback,
178 weak_ptr_factory_.GetWeakPtr())); 179 weak_ptr_factory_.GetWeakPtr()));
179 } 180 }
180 181
181 void RecentTabHelper::SavePageCallback(OfflinePageModel::SavePageResult result, 182 void RecentTabHelper::SavePageCallback(OfflinePageModel::SavePageResult result,
182 int64_t offline_id) { 183 int64_t offline_id) {
183 // TODO(dimich): add UMA, including result. Bug 608112. 184 UMA_HISTOGRAM_ENUMERATION(
185 "OfflinePages.SavePageResult.RecentPage", static_cast<int>(result),
fgorski 2016/05/11 16:54:23 I don't think this is needed in this shape and for
186 static_cast<int>(OfflinePageModel::SavePageResult::RESULT_COUNT));
184 ReportSnapshotCompleted(); 187 ReportSnapshotCompleted();
185 } 188 }
186 189
187 void RecentTabHelper::ReportSnapshotCompleted() { 190 void RecentTabHelper::ReportSnapshotCompleted() {
188 snapshot_controller_->PendingSnapshotCompleted(); 191 snapshot_controller_->PendingSnapshotCompleted();
189 } 192 }
190 193
191 bool RecentTabHelper::IsSamePage() const { 194 bool RecentTabHelper::IsSamePage() const {
192 return web_contents() && 195 return web_contents() &&
193 (web_contents()->GetLastCommittedURL() == snapshot_url_); 196 (web_contents()->GetLastCommittedURL() == snapshot_url_);
194 } 197 }
195 198
196 ClientId RecentTabHelper::client_id() const { 199 ClientId RecentTabHelper::client_id() const {
197 return ClientId(kClientNamespace, ""); 200 return ClientId(kClientNamespace, "");
198 } 201 }
199 202
200 void RecentTabHelper::SetArchiveFactoryForTest( 203 void RecentTabHelper::SetArchiveFactoryForTest(
201 std::unique_ptr<TestArchiveFactory> test_archive_factory) { 204 std::unique_ptr<TestArchiveFactory> test_archive_factory) {
202 test_archive_factory_ = std::move(test_archive_factory); 205 test_archive_factory_ = std::move(test_archive_factory);
203 } 206 }
204 207
205 void RecentTabHelper::SetTaskRunnerForTest( 208 void RecentTabHelper::SetTaskRunnerForTest(
206 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner) { 209 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner) {
207 snapshot_controller_.reset(new SnapshotController(task_runner, this)); 210 snapshot_controller_.reset(new SnapshotController(task_runner, this));
208 } 211 }
209 212
210 } // namespace offline_pages 213 } // namespace offline_pages
OLDNEW
« no previous file with comments | « no previous file | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698