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

Unified Diff: components/browsing_data/browsing_data_utils.cc

Issue 2084903002: Moved BrowsingDataCounter and part of BrowsingDataCounterUtils to components. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed deps Created 4 years, 6 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 side-by-side diff with in-line comments
Download patch
Index: components/browsing_data/browsing_data_utils.cc
diff --git a/components/browsing_data/browsing_data_utils.cc b/components/browsing_data/browsing_data_utils.cc
new file mode 100644
index 0000000000000000000000000000000000000000..bcf237b95ecac73ffd4647d118976645bd4b0e40
--- /dev/null
+++ b/components/browsing_data/browsing_data_utils.cc
@@ -0,0 +1,56 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "components/browsing_data/browsing_data_utils.h"
+#include "content/public/browser/user_metrics.h"
+
+using base::UserMetricsAction;
msramek 2016/06/21 14:43:56 This is typically discouraged. Please inline base:
ioanap 2016/06/23 14:56:27 Noted. I removed it completely, since the method t
+
+TimeRange Unbounded() {
+ return TimeRange(base::Time(), base::Time::Max());
+}
+
+TimeRange Period(TimePeriod period) {
+ switch (period) {
+ case LAST_HOUR:
+ content::RecordAction(UserMetricsAction("ClearBrowsingData_LastHour"));
+ break;
+ case LAST_DAY:
+ content::RecordAction(UserMetricsAction("ClearBrowsingData_LastDay"));
+ break;
+ case LAST_WEEK:
+ content::RecordAction(UserMetricsAction("ClearBrowsingData_LastWeek"));
+ break;
+ case FOUR_WEEKS:
+ content::RecordAction(UserMetricsAction("ClearBrowsingData_LastMonth"));
+ break;
+ case EVERYTHING:
+ content::RecordAction(UserMetricsAction("ClearBrowsingData_Everything"));
+ break;
+ }
+ return TimeRange(CalculateBeginDeleteTime(period), base::Time::Max());
+}
+
+base::Time CalculateBeginDeleteTime(TimePeriod time_period) {
+ base::TimeDelta diff;
+ base::Time delete_begin_time = base::Time::Now();
+ switch (time_period) {
+ case LAST_HOUR:
+ diff = base::TimeDelta::FromHours(1);
+ break;
+ case LAST_DAY:
+ diff = base::TimeDelta::FromHours(24);
+ break;
+ case LAST_WEEK:
+ diff = base::TimeDelta::FromHours(7 * 24);
+ break;
+ case FOUR_WEEKS:
+ diff = base::TimeDelta::FromHours(4 * 7 * 24);
+ break;
+ case EVERYTHING:
+ delete_begin_time = base::Time();
+ break;
+ }
+ return delete_begin_time - diff;
+}

Powered by Google App Engine
This is Rietveld 408576698