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

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: Reviewer comments: Round 3 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/files/file_util.h"
8 #include "chrome/browser/browser_process.h"
9 #include "chrome/browser/chromeos/login/session/user_session_manager.h"
10 #include "chrome/browser/chromeos/login/startup_utils.h"
11 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h"
12 #include "chrome/browser/prefs/pref_service_syncable.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 namespace {
22
23 // ChromeOS Goodies page for device's first New Window.
24 const char kGoodiesURL[] = "https://www.google.com/chrome/devices/goodies.html";
25
26 // Max days after initial login that we're willing to show Goodies.
27 static const int kMaxDaysAfterOobeForGoodies = 14;
28
29 // Checks timestamp on OOBE Complete flag file. kCanShowOobeGoodiesPage
30 // defaults to |true|; we set it to |false| (return |false|) for any device over
31 // kMaxDaysAfterOobeForGoodies days old, to avoid showing it after update on
32 // older devices.
33 bool CheckGoodiesPrefAgainstOobeTimestamp() {
34 const base::FilePath oobe_timestamp_file =
35 StartupUtils::GetOobeCompleteFlagPath();
36 base::File::Info fileInfo;
achuithb 2015/09/16 21:51:36 Add a DCHECK for BlockingPool: DCHECK(content::Bro
Greg Levin 2015/09/16 22:50:45 Done.
37 if (base::GetFileInfo(oobe_timestamp_file, &fileInfo)) {
38 const base::TimeDelta time_since_oobe =
39 base::Time::Now() - fileInfo.creation_time;
40 if (time_since_oobe >
41 base::TimeDelta::FromDays(kMaxDaysAfterOobeForGoodies))
42 return false;
43 }
44 return true;
45 }
46
47 // Callback into main thread to set pref to |false| if too long since oobe, or
48 // to create GoodiesDisplayer otherwise.
49 void UpdateGoodiesPrefCantShow(bool can_show_goodies) {
50 if (can_show_goodies) {
achuithb 2015/09/16 21:51:36 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
Greg Levin 2015/09/16 22:50:45 Done.
51 UserSessionManager::GetInstance()->CreateGoodiesDisplayer();
52 } else {
53 g_browser_process->local_state()->SetBoolean(prefs::kCanShowOobeGoodiesPage,
54 false);
55 }
56 }
57
58 } // namespace
59
60 GoodiesDisplayer::GoodiesDisplayer() {
61 BrowserList::AddObserver(this);
62 }
63
64 // If Goodies page hasn't been shown yet, and Chromebook isn't too old, create
65 // GoodiesDisplayer to observe BrowserList.
66 void GoodiesDisplayer::Init() {
67 if (g_browser_process->local_state()->GetBoolean(
68 prefs::kCanShowOobeGoodiesPage))
69 base::PostTaskAndReplyWithResult(
70 content::BrowserThread::GetBlockingPool(), FROM_HERE,
71 base::Bind(&CheckGoodiesPrefAgainstOobeTimestamp),
72 base::Bind(&UpdateGoodiesPrefCantShow));
73 }
74
75 // If conditions enumerated below are met, this loads the Oobe Goodies page for
76 // new Chromebooks; when appropriate, it uses pref to mark page as shown,
77 // removes itself from BrowserListObservers, and deletes itself.
78 void GoodiesDisplayer::OnBrowserSetLastActive(Browser* browser) {
79 // 1. Not guest or incognito session (keep observing).
80 if (browser->profile()->IsOffTheRecord())
81 return;
82
83 PrefService* local_state = g_browser_process->local_state();
84 // 2. Not previously shown, or otherwise marked as unavailable.
85 if (local_state->GetBoolean(prefs::kCanShowOobeGoodiesPage)) {
86 // 3. Device not enterprise enrolled.
87 if (!g_browser_process->platform_part()
88 ->browser_policy_connector_chromeos()
89 ->IsEnterpriseManaged())
90 chrome::AddTabAt(browser, GURL(kGoodiesURL), 2, false);
91
92 // Set to |false| whether enterprise enrolled or Goodies shown.
93 local_state->SetBoolean(prefs::kCanShowOobeGoodiesPage, false);
94 }
95
96 // Regardless of how we got here, we don't henceforth need to show Goodies.
97 BrowserList::RemoveObserver(this);
98 UserSessionManager::GetInstance()->DestroyGoodiesDisplayer();
99 }
100
101 } // namespace first_run
102 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698