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 "chrome/browser/browser_process.h" | |
| 8 #include "chrome/browser/chromeos/login/startup_utils.h" | |
| 9 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" | |
| 10 #include "chrome/browser/prefs/pref_service_syncable.h" | |
| 11 #include "chrome/browser/profiles/profile.h" | |
| 12 #include "chrome/browser/ui/browser.h" | |
| 13 #include "chrome/browser/ui/browser_tabstrip.h" | |
| 14 #include "chrome/common/pref_names.h" | |
| 15 #include "content/public/browser/browser_thread.h" | |
| 16 | |
| 17 namespace chromeos { | |
| 18 namespace first_run { | |
| 19 | |
| 20 #if defined(OS_CHROMEOS) | |
| 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 // Checks timestamp on OOBE Complete flag file. kCanShowOobeGoodiesPage | |
| 31 // defaults to |true|; we set it to |false| (return |false|) for any device over | |
| 32 // kMaxDaysAfterOobeForGoodies days old, to avoid showing it after update on | |
| 33 // older devices. | |
| 34 static bool CheckGoodiesPrefAgainstOobeTimestamp() { | |
| 35 DCHECK_CURRENTLY_ON(content::BrowserThread::FILE); | |
| 36 const base::FilePath oobe_timestamp_file = | |
| 37 StartupUtils::GetOobeCompleteFlagPath(); | |
| 38 base::File::Info fileInfo; | |
| 39 if (base::GetFileInfo(oobe_timestamp_file, &fileInfo)) { | |
| 40 base::TimeDelta time_since_oobe = | |
| 41 base::Time::Now() - fileInfo.creation_time; | |
| 42 if (time_since_oobe > | |
| 43 base::TimeDelta::FromDays(kMaxDaysAfterOobeForGoodies)) | |
| 44 return false; | |
| 45 } | |
| 46 return true; | |
| 47 } | |
| 48 | |
| 49 // Callback into main thread to set pref to |false| if too long since oobe, or | |
| 50 // to create GoodiesDisplayer otherwise. | |
| 51 static void UpdateGoodiesPrefCantShow(bool can_show_goodies) { | |
| 52 if (can_show_goodies) { | |
| 53 new GoodiesDisplayer(); // TODO: Leaky? | |
|
Greg Levin
2015/09/15 00:12:11
This probably isn't finished, but I wanted to get
Greg Levin
2015/09/15 16:16:24
Done (fixed in Patch Set 3).
| |
| 54 } else { | |
| 55 PrefService* prefs = g_browser_process->local_state(); | |
| 56 prefs->SetBoolean(prefs::kCanShowOobeGoodiesPage, false); | |
| 57 } | |
| 58 } | |
| 59 | |
| 60 } // namespace | |
| 61 | |
| 62 GoodiesDisplayer::GoodiesDisplayer() { | |
| 63 BrowserList::AddObserver(this); | |
| 64 } | |
| 65 | |
| 66 // If conditions enumerated below are met, this loads the Oobe Goodies page for | |
| 67 // new Chromebooks; when appropriate, it uses pref to mark page as shown, | |
| 68 // removes itself from BrowserListObservers, and deletes itself. | |
| 69 void GoodiesDisplayer::OnBrowserSetLastActive(Browser* browser) { | |
| 70 // 1. Not guest or incognito session (keep observing). | |
| 71 if (browser->profile()->IsOffTheRecord()) | |
| 72 return; | |
| 73 | |
| 74 PrefService* local_state = g_browser_process->local_state(); | |
| 75 DCHECK(local_state); | |
| 76 // 2. Not previously shown, or otherwise marked as unavailable. | |
| 77 if (local_state->GetBoolean(prefs::kCanShowOobeGoodiesPage)) { | |
| 78 // 3. Device not enterprise enrolled. | |
| 79 if (!g_browser_process->platform_part() | |
| 80 ->browser_policy_connector_chromeos() | |
| 81 ->IsEnterpriseManaged()) | |
| 82 chrome::AddTabAt(browser, GURL(kGoodiesURL), -1, false); | |
| 83 | |
| 84 // Set to |false| whether enterprise enrolled or Goodies shown. | |
| 85 local_state->SetBoolean(prefs::kCanShowOobeGoodiesPage, false); | |
| 86 } | |
| 87 | |
| 88 // Regardless of how we got here, we don't henceforth need to show Goodies, | |
| 89 // so clean up. | |
| 90 BrowserList::RemoveObserver(this); | |
| 91 delete this; | |
| 92 } | |
| 93 | |
| 94 #endif // defined(OS_CHROMEOS) | |
| 95 | |
| 96 // Check time since Oobe completion on FILE thread. | |
| 97 void InitializeGoodiesDisplayer() { | |
| 98 #if defined(OS_CHROMEOS) | |
| 99 PrefService* prefs = g_browser_process->local_state(); | |
| 100 if (prefs->GetBoolean(prefs::kCanShowOobeGoodiesPage)) | |
| 101 content::BrowserThread::PostTaskAndReplyWithResult( | |
| 102 content::BrowserThread::FILE, FROM_HERE, | |
| 103 base::Bind(&CheckGoodiesPrefAgainstOobeTimestamp), | |
| 104 base::Bind(&UpdateGoodiesPrefCantShow)); | |
| 105 #endif // defined(OS_CHROMEOS) | |
| 106 } | |
| 107 | |
| 108 } // namespace first_run | |
| 109 } // namespace chromeos | |
| OLD | NEW |