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

Side by Side Diff: chrome/browser/chromeos/first_run/goodies_displayer.cc

Issue 1308833004: Show Goodies page to new Chromebook users (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Use LazyInstance<GoodiesDisplayer> Created 5 years, 3 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
(Empty)
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/browser/chromeos/first_run/goodies_displayer.h"
6
7 #include "base/lazy_instance.h"
8 #include "chrome/browser/browser_process.h"
9 #include "chrome/browser/chromeos/login/startup_utils.h"
10 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h"
11 #include "chrome/browser/prefs/pref_service_syncable.h"
12 #include "chrome/browser/profiles/profile.h"
13 #include "chrome/browser/ui/browser.h"
14 #include "chrome/browser/ui/browser_tabstrip.h"
15 #include "chrome/common/pref_names.h"
16 #include "content/public/browser/browser_thread.h"
17
18 namespace chromeos {
19 namespace first_run {
20
21 #if defined(OS_CHROMEOS)
22
23 namespace {
24
25 // ChromeOS Goodies page for device's first New Window.
26 const char kGoodiesURL[] = "https://www.google.com/chrome/devices/goodies.html";
27
28 // Max days after initial login that we're willing to show Goodies.
29 static const int kMaxDaysAfterOobeForGoodies = 14;
30
31 base::LazyInstance<GoodiesDisplayer> g_goodies_displayer =
achuithb 2015/09/15 18:24:32 I don't see any reason why this should be a single
Greg Levin 2015/09/15 21:44:48 My concern was the case when User A logs in and ou
achuithb 2015/09/16 03:40:29 Hmm, are you sure that's possible? What about dele
Greg Levin 2015/09/16 16:55:13 |> Hmm, are you sure that's possible? Yes, I've t
achuithb 2015/09/16 17:17:30 I view singletons as being some kind of service th
Greg Levin 2015/09/16 20:48:23 Done- Moved instance to be member of UserSessionM
32 LAZY_INSTANCE_INITIALIZER;
33
34 // Checks timestamp on OOBE Complete flag file. kCanShowOobeGoodiesPage
35 // defaults to |true|; we set it to |false| (return |false|) for any device over
36 // kMaxDaysAfterOobeForGoodies days old, to avoid showing it after update on
37 // older devices.
38 static bool CheckGoodiesPrefAgainstOobeTimestamp() {
achuithb 2015/09/15 18:20:54 Don't need static. anon namespace functions do not
Greg Levin 2015/09/15 21:44:48 Done.
39 DCHECK_CURRENTLY_ON(content::BrowserThread::FILE);
achuithb 2015/09/15 18:20:54 BrowserThread::FILE is deprecated. You should use
Greg Levin 2015/09/15 21:44:48 Done.
40 const base::FilePath oobe_timestamp_file =
41 StartupUtils::GetOobeCompleteFlagPath();
42 base::File::Info fileInfo;
43 if (base::GetFileInfo(oobe_timestamp_file, &fileInfo)) {
44 base::TimeDelta time_since_oobe =
achuithb 2015/09/15 18:20:54 const
Greg Levin 2015/09/15 21:44:48 Done.
45 base::Time::Now() - fileInfo.creation_time;
46 if (time_since_oobe >
47 base::TimeDelta::FromDays(kMaxDaysAfterOobeForGoodies))
48 return false;
49 }
50 return true;
51 }
52
53 // Callback into main thread to set pref to |false| if too long since oobe, or
54 // to create GoodiesDisplayer otherwise.
55 static void UpdateGoodiesPrefCantShow(bool can_show_goodies) {
achuithb 2015/09/15 18:20:54 No static
Greg Levin 2015/09/15 21:44:48 Done.
56 if (can_show_goodies) {
57 g_goodies_displayer.Get();
58 } else {
59 PrefService* prefs = g_browser_process->local_state();
achuithb 2015/09/15 18:20:54 No reason to have this temporary variable prefs
Greg Levin 2015/09/15 21:44:48 Done.
60 prefs->SetBoolean(prefs::kCanShowOobeGoodiesPage, false);
61 }
62 }
63
64 } // namespace
65
66 GoodiesDisplayer::GoodiesDisplayer() {
67 BrowserList::AddObserver(this);
68 }
69
70 // If conditions enumerated below are met, this loads the Oobe Goodies page for
71 // new Chromebooks; when appropriate, it uses pref to mark page as shown,
72 // removes itself from BrowserListObservers, and deletes itself.
73 void GoodiesDisplayer::OnBrowserSetLastActive(Browser* browser) {
74 // 1. Not guest or incognito session (keep observing).
75 if (browser->profile()->IsOffTheRecord())
76 return;
77
78 PrefService* local_state = g_browser_process->local_state();
79 DCHECK(local_state);
achuithb 2015/09/15 18:20:53 No point in having this DCHECK.
Greg Levin 2015/09/15 21:44:48 Done.
80 // 2. Not previously shown, or otherwise marked as unavailable.
81 if (local_state->GetBoolean(prefs::kCanShowOobeGoodiesPage)) {
82 // 3. Device not enterprise enrolled.
83 if (!g_browser_process->platform_part()
84 ->browser_policy_connector_chromeos()
85 ->IsEnterpriseManaged())
86 chrome::AddTabAt(browser, GURL(kGoodiesURL), -1, false);
87
88 // Set to |false| whether enterprise enrolled or Goodies shown.
89 local_state->SetBoolean(prefs::kCanShowOobeGoodiesPage, false);
90 }
91
92 // Regardless of how we got here, we don't henceforth need to show Goodies.
93 BrowserList::RemoveObserver(this);
94 }
95
96 #endif // defined(OS_CHROMEOS)
97
98 // Check time since Oobe completion on FILE thread.
99 void InitializeGoodiesDisplayer() {
100 #if defined(OS_CHROMEOS)
101 PrefService* prefs = g_browser_process->local_state();
102 if (prefs->GetBoolean(prefs::kCanShowOobeGoodiesPage))
103 content::BrowserThread::PostTaskAndReplyWithResult(
achuithb 2015/09/15 18:20:53 Use BlockingPool
Greg Levin 2015/09/15 21:44:48 Done.
104 content::BrowserThread::FILE, FROM_HERE,
105 base::Bind(&CheckGoodiesPrefAgainstOobeTimestamp),
106 base::Bind(&UpdateGoodiesPrefCantShow));
107 #endif // defined(OS_CHROMEOS)
108 }
109
110 } // namespace first_run
111 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698