Chromium Code Reviews| 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..243ab8bfc4e3e436940bcf870ef5f67d2c254056 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 |
|
stevenjb
2016/06/29 23:35:55
at least
malaykeshav
2016/06/30 01:30:16
Done
|
| +// is an indirect measure of whether the owner has used the device for atleast |
|
stevenjb
2016/06/29 23:35:55
at least
malaykeshav
2016/06/30 01:30:16
Done
|
| +// |threshold| amount of time. |
| +bool IsNewDevice(base::TimeDelta threshold) { |
| + const base::TimeDelta time_since_oobe = |
| + chromeos::StartupUtils::GetTimeSinceOobeFlagFileCreation(); |
|
stevenjb
2016/06/29 23:35:55
no need for intermediate variable
malaykeshav
2016/06/30 01:30:16
Done
|
| + return time_since_oobe <= threshold; |
| +} |
| + |
| } // namespace |
| namespace chromeos { |
| @@ -54,21 +64,42 @@ 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); |
|
stevenjb
2016/06/29 23:35:55
Avoid initializing values like this, it slows down
malaykeshav
2016/06/30 01:30:16
Done
|
| + |
| 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) { |
| + // 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; |