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

Unified 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: Move code into goodies_displayer 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/chromeos/first_run/goodies_displayer.cc
diff --git a/chrome/browser/chromeos/first_run/goodies_displayer.cc b/chrome/browser/chromeos/first_run/goodies_displayer.cc
new file mode 100644
index 0000000000000000000000000000000000000000..6e0d7d917a71481c11b140f015527b7092352d48
--- /dev/null
+++ b/chrome/browser/chromeos/first_run/goodies_displayer.cc
@@ -0,0 +1,109 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/chromeos/first_run/goodies_displayer.h"
+
+#include "chrome/browser/browser_process.h"
+#include "chrome/browser/chromeos/login/startup_utils.h"
+#include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h"
+#include "chrome/browser/prefs/pref_service_syncable.h"
+#include "chrome/browser/profiles/profile.h"
+#include "chrome/browser/ui/browser.h"
+#include "chrome/browser/ui/browser_tabstrip.h"
+#include "chrome/common/pref_names.h"
+#include "content/public/browser/browser_thread.h"
+
+namespace chromeos {
+namespace first_run {
+
+#if defined(OS_CHROMEOS)
+
+namespace {
+
+// ChromeOS Goodies page for device's first New Window.
+const char kGoodiesURL[] = "https://www.google.com/chrome/devices/goodies.html";
+
+// Max days after initial login that we're willing to show Goodies.
+static const int kMaxDaysAfterOobeForGoodies = 14;
+
+// Checks timestamp on OOBE Complete flag file. kCanShowOobeGoodiesPage
+// defaults to |true|; we set it to |false| (return |false|) for any device over
+// kMaxDaysAfterOobeForGoodies days old, to avoid showing it after update on
+// older devices.
+static bool CheckGoodiesPrefAgainstOobeTimestamp() {
+ DCHECK_CURRENTLY_ON(content::BrowserThread::FILE);
+ const base::FilePath oobe_timestamp_file =
+ StartupUtils::GetOobeCompleteFlagPath();
+ base::File::Info fileInfo;
+ if (base::GetFileInfo(oobe_timestamp_file, &fileInfo)) {
+ base::TimeDelta time_since_oobe =
+ base::Time::Now() - fileInfo.creation_time;
+ if (time_since_oobe >
+ base::TimeDelta::FromDays(kMaxDaysAfterOobeForGoodies))
+ return false;
+ }
+ return true;
+}
+
+// Callback into main thread to set pref to |false| if too long since oobe, or
+// to create GoodiesDisplayer otherwise.
+static void UpdateGoodiesPrefCantShow(bool can_show_goodies) {
+ if (can_show_goodies) {
+ 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).
+ } else {
+ PrefService* prefs = g_browser_process->local_state();
+ prefs->SetBoolean(prefs::kCanShowOobeGoodiesPage, false);
+ }
+}
+
+} // namespace
+
+GoodiesDisplayer::GoodiesDisplayer() {
+ BrowserList::AddObserver(this);
+}
+
+// If conditions enumerated below are met, this loads the Oobe Goodies page for
+// new Chromebooks; when appropriate, it uses pref to mark page as shown,
+// removes itself from BrowserListObservers, and deletes itself.
+void GoodiesDisplayer::OnBrowserSetLastActive(Browser* browser) {
+ // 1. Not guest or incognito session (keep observing).
+ if (browser->profile()->IsOffTheRecord())
+ return;
+
+ PrefService* local_state = g_browser_process->local_state();
+ DCHECK(local_state);
+ // 2. Not previously shown, or otherwise marked as unavailable.
+ if (local_state->GetBoolean(prefs::kCanShowOobeGoodiesPage)) {
+ // 3. Device not enterprise enrolled.
+ if (!g_browser_process->platform_part()
+ ->browser_policy_connector_chromeos()
+ ->IsEnterpriseManaged())
+ chrome::AddTabAt(browser, GURL(kGoodiesURL), -1, false);
+
+ // Set to |false| whether enterprise enrolled or Goodies shown.
+ local_state->SetBoolean(prefs::kCanShowOobeGoodiesPage, false);
+ }
+
+ // Regardless of how we got here, we don't henceforth need to show Goodies,
+ // so clean up.
+ BrowserList::RemoveObserver(this);
+ delete this;
+}
+
+#endif // defined(OS_CHROMEOS)
+
+// Check time since Oobe completion on FILE thread.
+void InitializeGoodiesDisplayer() {
+#if defined(OS_CHROMEOS)
+ PrefService* prefs = g_browser_process->local_state();
+ if (prefs->GetBoolean(prefs::kCanShowOobeGoodiesPage))
+ content::BrowserThread::PostTaskAndReplyWithResult(
+ content::BrowserThread::FILE, FROM_HERE,
+ base::Bind(&CheckGoodiesPrefAgainstOobeTimestamp),
+ base::Bind(&UpdateGoodiesPrefCantShow));
+#endif // defined(OS_CHROMEOS)
+}
+
+} // namespace first_run
+} // namespace chromeos

Powered by Google App Engine
This is Rietveld 408576698