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

Side by Side 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, 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 unified diff | Download patch
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/chromeos/hats/hats_notification_controller.h" 5 #include "chrome/browser/chromeos/hats/hats_notification_controller.h"
6 6
7 #include "ash/common/system/system_notifier.h" 7 #include "ash/common/system/system_notifier.h"
8 #include "base/feature_list.h" 8 #include "base/feature_list.h"
9 #include "chrome/browser/browser_process.h" 9 #include "chrome/browser/browser_process.h"
10 #include "chrome/browser/chromeos/hats/hats_dialog.h" 10 #include "chrome/browser/chromeos/hats/hats_dialog.h"
11 #include "chrome/browser/chromeos/login/startup_utils.h"
11 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" 12 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h"
12 #include "chrome/browser/chromeos/profiles/profile_helper.h" 13 #include "chrome/browser/chromeos/profiles/profile_helper.h"
13 #include "chrome/browser/notifications/notification_ui_manager.h" 14 #include "chrome/browser/notifications/notification_ui_manager.h"
14 #include "chrome/browser/profiles/profile.h" 15 #include "chrome/browser/profiles/profile.h"
15 #include "chrome/common/chrome_features.h" 16 #include "chrome/common/chrome_features.h"
16 #include "chrome/common/pref_names.h" 17 #include "chrome/common/pref_names.h"
17 #include "chromeos/network/network_state.h" 18 #include "chromeos/network/network_state.h"
18 #include "components/prefs/pref_service.h" 19 #include "components/prefs/pref_service.h"
19 #include "content/public/browser/browser_thread.h" 20 #include "content/public/browser/browser_thread.h"
20 #include "grit/ash_strings.h" 21 #include "grit/ash_strings.h"
(...skipping 12 matching lines...) Expand all
33 bool DidShowSurveyToProfileRecently(Profile* profile, 34 bool DidShowSurveyToProfileRecently(Profile* profile,
34 base::TimeDelta threshold) { 35 base::TimeDelta threshold) {
35 int64_t serialized_timestamp = 36 int64_t serialized_timestamp =
36 profile->GetPrefs()->GetInt64(prefs::kHatsLastInteractionTimestamp); 37 profile->GetPrefs()->GetInt64(prefs::kHatsLastInteractionTimestamp);
37 38
38 base::Time previous_interaction_timestamp = 39 base::Time previous_interaction_timestamp =
39 base::Time::FromInternalValue(serialized_timestamp); 40 base::Time::FromInternalValue(serialized_timestamp);
40 return (previous_interaction_timestamp + threshold) > base::Time::Now(); 41 return (previous_interaction_timestamp + threshold) > base::Time::Now();
41 } 42 }
42 43
44 // Returns true if atleast |threshold| time units have passed since OOBE. This
45 // is an indirect measure of whether the owner has used the device for atleast
46 // |threshold| amount of time.
47 bool IsNewDevice(base::TimeDelta threshold) {
48 const base::TimeDelta time_since_oobe =
49 chromeos::StartupUtils::GetTimeSinceOobeFlagFileCreation();
50 return time_since_oobe <= threshold;
51 }
52
43 } // namespace 53 } // namespace
44 54
45 namespace chromeos { 55 namespace chromeos {
46 56
47 // static 57 // static
48 const char HatsNotificationController::kDelegateId[] = "hats_delegate"; 58 const char HatsNotificationController::kDelegateId[] = "hats_delegate";
49 59
50 // static 60 // static
51 const char HatsNotificationController::kNotificationId[] = "hats_notification"; 61 const char HatsNotificationController::kNotificationId[] = "hats_notification";
52 62
53 // static 63 // static
54 const base::TimeDelta HatsNotificationController::kHatsThresholdTime = 64 const base::TimeDelta HatsNotificationController::kHatsThresholdTime =
55 base::TimeDelta::FromDays(90); 65 base::TimeDelta::FromDays(90);
56 66
67 // static
68 const base::TimeDelta HatsNotificationController::kHatsNewDeviceThresholdTime =
69 base::TimeDelta::FromDays(7);
70
57 HatsNotificationController::HatsNotificationController(Profile* profile) 71 HatsNotificationController::HatsNotificationController(Profile* profile)
58 : profile_(profile) { 72 : profile_(profile), weak_pointer_factory_(this) {
59 // Add self as an observer to be notified when an internet connection is 73 base::PostTaskAndReplyWithResult(
60 // available. 74 content::BrowserThread::GetBlockingPool(), FROM_HERE,
61 network_portal_detector::GetInstance()->AddAndFireObserver(this); 75 base::Bind(&IsNewDevice, kHatsNewDeviceThresholdTime),
76 base::Bind(&HatsNotificationController::Initialize,
77 weak_pointer_factory_.GetWeakPtr()));
62 } 78 }
63 79
64 HatsNotificationController::~HatsNotificationController() { 80 HatsNotificationController::~HatsNotificationController() {
65 network_portal_detector::GetInstance()->RemoveObserver(this); 81 network_portal_detector::GetInstance()->RemoveObserver(this);
66 } 82 }
67 83
84 void HatsNotificationController::Initialize(bool is_new_device) {
85 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
86 // 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
87 // We also update the preference flag as if the user just attempted the
88 // survey.
89 UpdateLastInteractionTime();
90 return;
91 }
92 // 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
93 // available.
94 network_portal_detector::GetInstance()->AddAndFireObserver(this);
95 }
96
68 // static 97 // static
69 // TODO(malaykeshav): Add check for @google accounts. 98 // TODO(malaykeshav): Add check for @google accounts.
70 bool HatsNotificationController::ShouldShowSurveyToProfile(Profile* profile) { 99 bool HatsNotificationController::ShouldShowSurveyToProfile(Profile* profile) {
71 // Do not show the survey if the HaTS feature is disabled for the device. 100 // Do not show the survey if the HaTS feature is disabled for the device.
jdufault 2016/06/29 22:27:03 Please update this comment to explain that the fea
malaykeshav 2016/06/29 22:32:33 Done.
72 if (!base::FeatureList::IsEnabled(features::kHappininessTrackingSystem)) 101 if (!base::FeatureList::IsEnabled(features::kHappininessTrackingSystem))
73 return false; 102 return false;
74 103
75 // Do not show survey if this is a guest session. 104 // Do not show survey if this is a guest session.
76 if (profile->IsGuestSession()) 105 if (profile->IsGuestSession())
77 return false; 106 return false;
78 107
79 // Do not show the survey if the current user is not an owner. 108 // Do not show the survey if the current user is not an owner.
80 if (!ProfileHelper::IsOwnerProfile(profile)) 109 if (!ProfileHelper::IsOwnerProfile(profile))
81 return false; 110 return false;
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 GURL() /* Send an empty invalid url */, kNotificationId, optional, this); 187 GURL() /* Send an empty invalid url */, kNotificationId, optional, this);
159 } 188 }
160 189
161 void HatsNotificationController::UpdateLastInteractionTime() { 190 void HatsNotificationController::UpdateLastInteractionTime() {
162 PrefService* pref_service = profile_->GetPrefs(); 191 PrefService* pref_service = profile_->GetPrefs();
163 pref_service->SetInt64(prefs::kHatsLastInteractionTimestamp, 192 pref_service->SetInt64(prefs::kHatsLastInteractionTimestamp,
164 base::Time::Now().ToInternalValue()); 193 base::Time::Now().ToInternalValue());
165 } 194 }
166 195
167 } // namespace chromeos 196 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698