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

Unified Diff: chrome/browser/chromeos/hats/hats_notification_controller.cc

Issue 2103293003: Checks the age of device before initializing HaTS Notification (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Checks the age of device before initializing HaTS Notification Created 4 years, 5 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
« no previous file with comments | « chrome/browser/chromeos/hats/hats_notification_controller.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/chromeos/hats/hats_notification_controller.cc
diff --git a/chrome/browser/chromeos/hats/hats_notification_controller.cc b/chrome/browser/chromeos/hats/hats_notification_controller.cc
index 8ec8e18e9febb01fdf1d9bc88c26a7a417cecda8..461f2acbea0ff8c24d05e5a67535962c4ce9c7de 100644
--- a/chrome/browser/chromeos/hats/hats_notification_controller.cc
+++ b/chrome/browser/chromeos/hats/hats_notification_controller.cc
@@ -8,6 +8,7 @@
#include "base/feature_list.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/chromeos/hats/hats_dialog.h"
+#include "chrome/browser/chromeos/login/startup_utils.h"
#include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h"
#include "chrome/browser/chromeos/profiles/profile_helper.h"
#include "chrome/browser/notifications/notification_ui_manager.h"
@@ -29,15 +30,23 @@ namespace {
// Returns true if the given |profile| interacted with HaTS by either
// dismissing the notification or taking the survey within a given threshold
-// time delta |threshold|.
-bool DidShowSurveyToProfileRecently(Profile* profile,
- base::TimeDelta threshold) {
+// days |threshold_days|.
+bool DidShowSurveyToProfileRecently(Profile* profile, int threshold_days) {
int64_t serialized_timestamp =
profile->GetPrefs()->GetInt64(prefs::kHatsLastInteractionTimestamp);
base::Time previous_interaction_timestamp =
base::Time::FromInternalValue(serialized_timestamp);
- return (previous_interaction_timestamp + threshold) > base::Time::Now();
+ return (previous_interaction_timestamp +
+ base::TimeDelta::FromDays(threshold_days)) > base::Time::Now();
+}
+
+// Returns true if at least |threshold_days| days have passed since OOBE. This
+// is an indirect measure of whether the owner has used the device for at least
+// |threshold_days| days.
+bool IsNewDevice(int threshold_days) {
+ return chromeos::StartupUtils::GetTimeSinceOobeFlagFileCreation() <=
+ base::TimeDelta::FromDays(threshold_days);
}
} // namespace
@@ -51,24 +60,43 @@ const char HatsNotificationController::kDelegateId[] = "hats_delegate";
const char HatsNotificationController::kNotificationId[] = "hats_notification";
// static
-const base::TimeDelta HatsNotificationController::kHatsThresholdTime =
- base::TimeDelta::FromDays(90);
+const int HatsNotificationController::kHatsThresholdDays = 90;
+
+// static
+const int HatsNotificationController::kHatsNewDeviceThresholdDays = 7;
HatsNotificationController::HatsNotificationController(Profile* profile)
- : profile_(profile) {
- // Add self as an observer to be notified when an internet connection is
- // available.
- network_portal_detector::GetInstance()->AddAndFireObserver(this);
+ : profile_(profile), weak_pointer_factory_(this) {
+ base::PostTaskAndReplyWithResult(
+ content::BrowserThread::GetBlockingPool(), FROM_HERE,
+ base::Bind(&IsNewDevice, kHatsNewDeviceThresholdDays),
+ base::Bind(&HatsNotificationController::Initialize,
+ weak_pointer_factory_.GetWeakPtr()));
}
HatsNotificationController::~HatsNotificationController() {
network_portal_detector::GetInstance()->RemoveObserver(this);
}
+void HatsNotificationController::Initialize(bool is_new_device) {
+ if (is_new_device) {
+ // This device has been chosen for a survey, but it is too new. Instead
+ // of showing the user the survey, just mark it as completed.
+ UpdateLastInteractionTime();
+ return;
+ }
+
+ // Add self as an observer to be notified when an internet connection is
+ // available.
+ network_portal_detector::GetInstance()->AddAndFireObserver(this);
+}
+
// static
// TODO(malaykeshav): Add check for @google accounts.
bool HatsNotificationController::ShouldShowSurveyToProfile(Profile* profile) {
- // Do not show the survey if the HaTS feature is disabled for the device.
+ // Do not show the survey if the HaTS feature is disabled for the device. This
+ // flag is controlled by finch and is enabled only when the device has been
+ // selected for the survey.
if (!base::FeatureList::IsEnabled(features::kHappininessTrackingSystem))
return false;
@@ -91,7 +119,7 @@ bool HatsNotificationController::ShouldShowSurveyToProfile(Profile* profile) {
// Do not show survey to user if user has interacted with HaTS within the past
// |kHatsThresholdTime| time delta.
- if (DidShowSurveyToProfileRecently(profile, kHatsThresholdTime))
+ if (DidShowSurveyToProfileRecently(profile, kHatsThresholdDays))
return false;
return true;
« no previous file with comments | « chrome/browser/chromeos/hats/hats_notification_controller.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698