Chromium Code Reviews| OLD | NEW |
|---|---|
| (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 "base/task_runner_util.h" | |
| 9 #include "chrome/browser/browser_process.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/profiles/profile.h" | |
| 14 #include "chrome/browser/ui/browser.h" | |
| 15 #include "chrome/browser/ui/browser_tabstrip.h" | |
| 16 #include "chrome/common/pref_names.h" | |
| 17 #include "content/public/browser/browser_thread.h" | |
| 18 | |
| 19 namespace chromeos { | |
| 20 namespace first_run { | |
| 21 | |
| 22 namespace { | |
| 23 | |
| 24 // ChromeOS Goodies page for device's first New Window. | |
| 25 const char kGoodiesURL[] = "https://www.google.com/chrome/devices/goodies.html"; | |
| 26 | |
| 27 // Max days after initial login that we're willing to show Goodies. | |
| 28 static const int kMaxDaysAfterOobeForGoodies = 14; | |
| 29 | |
| 30 base::LazyInstance<GoodiesDisplayer> g_goodies_displayer = | |
| 31 LAZY_INSTANCE_INITIALIZER; | |
| 32 | |
| 33 // Checks timestamp on OOBE Complete flag file. kCanShowOobeGoodiesPage | |
| 34 // defaults to |true|; we set it to |false| (return |false|) for any device over | |
| 35 // kMaxDaysAfterOobeForGoodies days old, to avoid showing it after update on | |
| 36 // older devices. | |
| 37 bool CheckGoodiesPrefAgainstOobeTimestamp() { | |
| 38 const base::FilePath oobe_timestamp_file = | |
| 39 StartupUtils::GetOobeCompleteFlagPath(); | |
| 40 base::File::Info fileInfo; | |
| 41 if (base::GetFileInfo(oobe_timestamp_file, &fileInfo)) { | |
| 42 const base::TimeDelta time_since_oobe = | |
| 43 base::Time::Now() - fileInfo.creation_time; | |
| 44 if (time_since_oobe > | |
| 45 base::TimeDelta::FromDays(kMaxDaysAfterOobeForGoodies)) | |
| 46 return false; | |
| 47 } | |
| 48 return true; | |
| 49 } | |
| 50 | |
| 51 // Callback into main thread to set pref to |false| if too long since oobe, or | |
| 52 // to create GoodiesDisplayer otherwise. | |
| 53 void UpdateGoodiesPrefCantShow(bool can_show_goodies) { | |
| 54 if (can_show_goodies) { | |
| 55 g_goodies_displayer.Get(); | |
| 56 } else { | |
| 57 g_browser_process->local_state()->SetBoolean(prefs::kCanShowOobeGoodiesPage, | |
| 58 false); | |
| 59 } | |
| 60 } | |
| 61 | |
| 62 } // namespace | |
| 63 | |
| 64 GoodiesDisplayer::GoodiesDisplayer() { | |
| 65 BrowserList::AddObserver(this); | |
| 66 } | |
| 67 | |
| 68 // If Goodies page hasn't been shown yet, and Chromebook isn't too old, create | |
| 69 // GoodiesDisplayer to observe BrowserList. | |
| 70 void GoodiesDisplayer::Init() { | |
| 71 if (g_browser_process->local_state()->GetBoolean( | |
| 72 prefs::kCanShowOobeGoodiesPage)) | |
| 73 base::PostTaskAndReplyWithResult( | |
| 74 content::BrowserThread::GetBlockingPool(), FROM_HERE, | |
| 75 base::Bind(&CheckGoodiesPrefAgainstOobeTimestamp), | |
| 76 base::Bind(&UpdateGoodiesPrefCantShow)); | |
| 77 } | |
| 78 | |
| 79 // If conditions enumerated below are met, this loads the Oobe Goodies page for | |
| 80 // new Chromebooks; when appropriate, it uses pref to mark page as shown, | |
| 81 // removes itself from BrowserListObservers, and deletes itself. | |
|
achuithb
2015/09/16 03:40:29
Where does it delete itself?
Why not delete at th
Greg Levin
2015/09/16 16:55:13
|> Where does it delete itself?
Currently, it doe
achuithb
2015/09/16 17:17:30
delete on program exit is more commonly called a l
Greg Levin
2015/09/16 20:48:23
Done.
| |
| 82 void GoodiesDisplayer::OnBrowserSetLastActive(Browser* browser) { | |
| 83 // 1. Not guest or incognito session (keep observing). | |
| 84 if (browser->profile()->IsOffTheRecord()) | |
| 85 return; | |
| 86 | |
| 87 PrefService* local_state = g_browser_process->local_state(); | |
| 88 // 2. Not previously shown, or otherwise marked as unavailable. | |
| 89 if (local_state->GetBoolean(prefs::kCanShowOobeGoodiesPage)) { | |
| 90 // 3. Device not enterprise enrolled. | |
| 91 if (!g_browser_process->platform_part() | |
| 92 ->browser_policy_connector_chromeos() | |
| 93 ->IsEnterpriseManaged()) | |
|
achuithb
2015/09/16 03:40:29
I believe you need {} when the if stmt is multi-li
Greg Levin
2015/09/16 16:55:13
All I found was this: http://google-styleguide.goo
achuithb
2015/09/16 17:17:30
I believe there is no consensus on this, so let's
Greg Levin
2015/09/16 20:48:23
Acknowledged.
| |
| 94 chrome::AddTabAt(browser, GURL(kGoodiesURL), -1, false); | |
| 95 | |
| 96 // Set to |false| whether enterprise enrolled or Goodies shown. | |
| 97 local_state->SetBoolean(prefs::kCanShowOobeGoodiesPage, false); | |
| 98 } | |
| 99 | |
| 100 // Regardless of how we got here, we don't henceforth need to show Goodies. | |
| 101 BrowserList::RemoveObserver(this); | |
| 102 } | |
| 103 | |
| 104 } // namespace first_run | |
| 105 } // namespace chromeos | |
| OLD | NEW |