OLD | NEW |
---|---|
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 Loading... | |
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 | |
stevenjb
2016/06/29 23:35:55
at least
malaykeshav
2016/06/30 01:30:16
Done
| |
45 // 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
| |
46 // |threshold| amount of time. | |
47 bool IsNewDevice(base::TimeDelta threshold) { | |
48 const base::TimeDelta time_since_oobe = | |
49 chromeos::StartupUtils::GetTimeSinceOobeFlagFileCreation(); | |
stevenjb
2016/06/29 23:35:55
no need for intermediate variable
malaykeshav
2016/06/30 01:30:16
Done
| |
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); | |
stevenjb
2016/06/29 23:35:55
Avoid initializing values like this, it slows down
malaykeshav
2016/06/30 01:30:16
Done
| |
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) { | |
86 // This device has been chosen for a survey, but it is too new. Instead | |
87 // of showing the user the survey, just mark it as completed. | |
88 UpdateLastInteractionTime(); | |
89 return; | |
90 } | |
91 | |
92 // Add self as an observer to be notified when an internet connection is | |
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. This |
101 // flag is controlled by finch and is enabled only when the device has been | |
102 // selected for the survey. | |
72 if (!base::FeatureList::IsEnabled(features::kHappininessTrackingSystem)) | 103 if (!base::FeatureList::IsEnabled(features::kHappininessTrackingSystem)) |
73 return false; | 104 return false; |
74 | 105 |
75 // Do not show survey if this is a guest session. | 106 // Do not show survey if this is a guest session. |
76 if (profile->IsGuestSession()) | 107 if (profile->IsGuestSession()) |
77 return false; | 108 return false; |
78 | 109 |
79 // Do not show the survey if the current user is not an owner. | 110 // Do not show the survey if the current user is not an owner. |
80 if (!ProfileHelper::IsOwnerProfile(profile)) | 111 if (!ProfileHelper::IsOwnerProfile(profile)) |
81 return false; | 112 return false; |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
158 GURL() /* Send an empty invalid url */, kNotificationId, optional, this); | 189 GURL() /* Send an empty invalid url */, kNotificationId, optional, this); |
159 } | 190 } |
160 | 191 |
161 void HatsNotificationController::UpdateLastInteractionTime() { | 192 void HatsNotificationController::UpdateLastInteractionTime() { |
162 PrefService* pref_service = profile_->GetPrefs(); | 193 PrefService* pref_service = profile_->GetPrefs(); |
163 pref_service->SetInt64(prefs::kHatsLastInteractionTimestamp, | 194 pref_service->SetInt64(prefs::kHatsLastInteractionTimestamp, |
164 base::Time::Now().ToInternalValue()); | 195 base::Time::Now().ToInternalValue()); |
165 } | 196 } |
166 | 197 |
167 } // namespace chromeos | 198 } // namespace chromeos |
OLD | NEW |