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

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: 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: 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..d406b3d9a0a19bf1cdf95cdc22aa627cd2252c07 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"
@@ -40,6 +41,15 @@ bool DidShowSurveyToProfileRecently(Profile* profile,
return (previous_interaction_timestamp + threshold) > base::Time::Now();
}
+// Returns true if atleast |threshold| time units have passed since OOBE. This
+// is an indirect measure of whether the owner has used the device for atleast
+// |threshold| amount of time.
+bool IsNewDevice(base::TimeDelta threshold) {
+ const base::TimeDelta time_since_oobe =
+ chromeos::StartupUtils::GetTimeSinceOobeFlagFileCreation();
+ return time_since_oobe <= threshold;
+}
+
} // namespace
namespace chromeos {
@@ -54,17 +64,36 @@ const char HatsNotificationController::kNotificationId[] = "hats_notification";
const base::TimeDelta HatsNotificationController::kHatsThresholdTime =
base::TimeDelta::FromDays(90);
+// static
+const base::TimeDelta HatsNotificationController::kHatsNewDeviceThresholdTime =
+ base::TimeDelta::FromDays(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, kHatsNewDeviceThresholdTime),
+ 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) {
jdufault 2016/06/29 19:26:10 It'd be nice if we could move this is_new_device l
malaykeshav 2016/06/29 19:38:29 We want to consider the case of a new device as if
jdufault 2016/06/29 22:27:03 After offline discussion keeping the existing stru
+ // If the device is new, then we do not show any survey or notificaiton.
jdufault 2016/06/29 22:27:03 Can you update the comment to be more specific, ie
malaykeshav 2016/06/29 22:32:34 +1 Done
+ // We also update the preference flag as if the user just attempted the
+ // survey.
+ UpdateLastInteractionTime();
+ return;
+ }
+ // Add self as an observer to be notified when an internet connection is
jdufault 2016/06/29 19:26:10 nit: newline before comment
malaykeshav 2016/06/29 19:38:29 Done
+ // available.
+ network_portal_detector::GetInstance()->AddAndFireObserver(this);
+}
+
// static
// TODO(malaykeshav): Add check for @google accounts.
bool HatsNotificationController::ShouldShowSurveyToProfile(Profile* profile) {

Powered by Google App Engine
This is Rietveld 408576698