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

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: 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 unified diff | Download patch
« no previous file with comments | « chrome/browser/chromeos/hats/hats_notification_controller.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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"
21 #include "grit/theme_resources.h" 22 #include "grit/theme_resources.h"
22 #include "ui/base/l10n/l10n_util.h" 23 #include "ui/base/l10n/l10n_util.h"
23 #include "ui/base/resource/resource_bundle.h" 24 #include "ui/base/resource/resource_bundle.h"
24 #include "ui/message_center/message_center.h" 25 #include "ui/message_center/message_center.h"
25 #include "ui/message_center/notification_types.h" 26 #include "ui/message_center/notification_types.h"
26 #include "ui/strings/grit/ui_strings.h" 27 #include "ui/strings/grit/ui_strings.h"
27 28
28 namespace { 29 namespace {
29 30
30 // Returns true if the given |profile| interacted with HaTS by either 31 // Returns true if the given |profile| interacted with HaTS by either
31 // dismissing the notification or taking the survey within a given threshold 32 // dismissing the notification or taking the survey within a given threshold
32 // time delta |threshold|. 33 // days |threshold|.
33 bool DidShowSurveyToProfileRecently(Profile* profile, 34 bool DidShowSurveyToProfileRecently(Profile* profile, int threshold) {
stevenjb 2016/07/07 23:05:10 nit: threshold_days (or just days)
34 base::TimeDelta threshold) {
35 int64_t serialized_timestamp = 35 int64_t serialized_timestamp =
36 profile->GetPrefs()->GetInt64(prefs::kHatsLastInteractionTimestamp); 36 profile->GetPrefs()->GetInt64(prefs::kHatsLastInteractionTimestamp);
37 37
38 base::Time previous_interaction_timestamp = 38 base::Time previous_interaction_timestamp =
39 base::Time::FromInternalValue(serialized_timestamp); 39 base::Time::FromInternalValue(serialized_timestamp);
40 return (previous_interaction_timestamp + threshold) > base::Time::Now(); 40 return (previous_interaction_timestamp +
41 base::TimeDelta::FromDays(threshold)) > base::Time::Now();
42 }
43
44 // Returns true if at least |threshold| days have passed since OOBE. This is an
45 // indirect measure of whether the owner has used the device for at least
46 // |threshold| days.
47 bool IsNewDevice(int threshold) {
stevenjb 2016/07/07 23:05:10 nit: threshold_days (or just days)
48 return chromeos::StartupUtils::GetTimeSinceOobeFlagFileCreation() <=
49 base::TimeDelta::FromDays(threshold);
41 } 50 }
42 51
43 } // namespace 52 } // namespace
44 53
45 namespace chromeos { 54 namespace chromeos {
46 55
47 // static 56 // static
48 const char HatsNotificationController::kDelegateId[] = "hats_delegate"; 57 const char HatsNotificationController::kDelegateId[] = "hats_delegate";
49 58
50 // static 59 // static
51 const char HatsNotificationController::kNotificationId[] = "hats_notification"; 60 const char HatsNotificationController::kNotificationId[] = "hats_notification";
52 61
53 // static 62 // static
54 const base::TimeDelta HatsNotificationController::kHatsThresholdTime = 63 const int kHatsThresholdDays = 90;
55 base::TimeDelta::FromDays(90); 64
65 // static
66 const int kHatsNewDeviceThresholdDays = 7;
56 67
57 HatsNotificationController::HatsNotificationController(Profile* profile) 68 HatsNotificationController::HatsNotificationController(Profile* profile)
58 : profile_(profile) { 69 : profile_(profile), weak_pointer_factory_(this) {
59 // Add self as an observer to be notified when an internet connection is 70 base::PostTaskAndReplyWithResult(
60 // available. 71 content::BrowserThread::GetBlockingPool(), FROM_HERE,
61 network_portal_detector::GetInstance()->AddAndFireObserver(this); 72 base::Bind(&IsNewDevice, kHatsNewDeviceThresholdDays),
73 base::Bind(&HatsNotificationController::Initialize,
74 weak_pointer_factory_.GetWeakPtr()));
62 } 75 }
63 76
64 HatsNotificationController::~HatsNotificationController() { 77 HatsNotificationController::~HatsNotificationController() {
65 network_portal_detector::GetInstance()->RemoveObserver(this); 78 network_portal_detector::GetInstance()->RemoveObserver(this);
66 } 79 }
67 80
81 void HatsNotificationController::Initialize(bool is_new_device) {
82 if (is_new_device) {
83 // This device has been chosen for a survey, but it is too new. Instead
84 // of showing the user the survey, just mark it as completed.
85 UpdateLastInteractionTime();
86 return;
87 }
88
89 // Add self as an observer to be notified when an internet connection is
90 // available.
91 network_portal_detector::GetInstance()->AddAndFireObserver(this);
92 }
93
68 // static 94 // static
69 // TODO(malaykeshav): Add check for @google accounts. 95 // TODO(malaykeshav): Add check for @google accounts.
70 bool HatsNotificationController::ShouldShowSurveyToProfile(Profile* profile) { 96 bool HatsNotificationController::ShouldShowSurveyToProfile(Profile* profile) {
71 // Do not show the survey if the HaTS feature is disabled for the device. 97 // Do not show the survey if the HaTS feature is disabled for the device. This
98 // flag is controlled by finch and is enabled only when the device has been
99 // selected for the survey.
72 if (!base::FeatureList::IsEnabled(features::kHappininessTrackingSystem)) 100 if (!base::FeatureList::IsEnabled(features::kHappininessTrackingSystem))
73 return false; 101 return false;
74 102
75 // Do not show survey if this is a guest session. 103 // Do not show survey if this is a guest session.
76 if (profile->IsGuestSession()) 104 if (profile->IsGuestSession())
77 return false; 105 return false;
78 106
79 // Do not show the survey if the current user is not an owner. 107 // Do not show the survey if the current user is not an owner.
80 if (!ProfileHelper::IsOwnerProfile(profile)) 108 if (!ProfileHelper::IsOwnerProfile(profile))
81 return false; 109 return false;
82 110
83 // Do not show survey if this is an enterprise managed device. 111 // Do not show survey if this is an enterprise managed device.
84 // TODO(malaykeshav): Show survey to google users but not any other enterprise 112 // TODO(malaykeshav): Show survey to google users but not any other enterprise
85 // users. 113 // users.
86 if (g_browser_process->platform_part() 114 if (g_browser_process->platform_part()
87 ->browser_policy_connector_chromeos() 115 ->browser_policy_connector_chromeos()
88 ->IsEnterpriseManaged()) { 116 ->IsEnterpriseManaged()) {
89 return false; 117 return false;
90 } 118 }
91 119
92 // Do not show survey to user if user has interacted with HaTS within the past 120 // Do not show survey to user if user has interacted with HaTS within the past
93 // |kHatsThresholdTime| time delta. 121 // |kHatsThresholdTime| time delta.
94 if (DidShowSurveyToProfileRecently(profile, kHatsThresholdTime)) 122 if (DidShowSurveyToProfileRecently(profile, kHatsThresholdDays))
95 return false; 123 return false;
96 124
97 return true; 125 return true;
98 } 126 }
99 127
100 // NotificationDelegate override: 128 // NotificationDelegate override:
101 std::string HatsNotificationController::id() const { 129 std::string HatsNotificationController::id() const {
102 return kDelegateId; 130 return kDelegateId;
103 } 131 }
104 132
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 GURL() /* Send an empty invalid url */, kNotificationId, optional, this); 186 GURL() /* Send an empty invalid url */, kNotificationId, optional, this);
159 } 187 }
160 188
161 void HatsNotificationController::UpdateLastInteractionTime() { 189 void HatsNotificationController::UpdateLastInteractionTime() {
162 PrefService* pref_service = profile_->GetPrefs(); 190 PrefService* pref_service = profile_->GetPrefs();
163 pref_service->SetInt64(prefs::kHatsLastInteractionTimestamp, 191 pref_service->SetInt64(prefs::kHatsLastInteractionTimestamp,
164 base::Time::Now().ToInternalValue()); 192 base::Time::Now().ToInternalValue());
165 } 193 }
166 194
167 } // namespace chromeos 195 } // namespace chromeos
OLDNEW
« 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