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

Unified Diff: chrome/installer/util/eula_util.cc

Issue 12035043: Implementing app command to query EULA acceptance state for Chrome. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Comments, naming, and cleanup. Created 7 years, 11 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/installer/util/eula_util.cc
diff --git a/chrome/installer/util/eula_util.cc b/chrome/installer/util/eula_util.cc
new file mode 100644
index 0000000000000000000000000000000000000000..00eacc4aaf7585299bb9cc744f09f6d8719739a6
--- /dev/null
+++ b/chrome/installer/util/eula_util.cc
@@ -0,0 +1,99 @@
+// Copyright (c) 2013 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/installer/util/eula_util.h"
+
+#include "base/file_util.h"
+#include "base/memory/scoped_ptr.h"
+#include "chrome/common/chrome_constants.h"
+#include "chrome/installer/util/browser_distribution.h"
+#include "chrome/installer/util/install_util.h"
+#include "chrome/installer/util/installation_state.h"
+#include "chrome/installer/util/master_preferences.h"
+#include "chrome/installer/util/master_preferences_constants.h"
+#include "chrome/installer/util/util_constants.h"
+
+namespace installer {
+
+namespace {
+
+bool IsChromeFirstRunPending(BrowserDistribution* dist) {
+ // Chrome creates a sentinel file after first run, and we look for it.
grt (UTC plus 2) 2013/01/24 21:04:55 // Chrome creates the first run sentinel after the
huangs 2013/01/25 01:13:23 Done.
+ // However, if we fail to get the sentinel path, assume Chrome has been run.
+ FilePath first_run_sentinel;
+ return InstallUtil::GetSentinelFilePath(chrome::kFirstRunSentinel,
+ dist,
+ &first_run_sentinel)
+ && !file_util::PathExists(first_run_sentinel);
+}
+
+bool IsEULAAcceptanceFlagged(BrowserDistribution* dist) {
+ // Chrome creates a sentinel after the Eula is accepted.
grt (UTC plus 2) 2013/01/24 21:04:55 // Chrome creates the EULA sentinel after the EULA
huangs 2013/01/25 01:13:23 Done.
+ // But if we fail to get sentinel path, assume EULA not accepted.
+ FilePath eula_sentinel;
+ return InstallUtil::GetSentinelFilePath(kEULASentinelFile,
+ dist,
+ &eula_sentinel)
+ && file_util::PathExists(eula_sentinel);
+}
+
+scoped_ptr<MasterPreferences> GetMasterPrefs(const ProductState& prod_state) {
+ // The standard location of the master prefs is next to the chrome binary.
+ FilePath master_prefs_path(
+ prod_state.GetSetupPath().DirName().DirName().DirName());
+ scoped_ptr<MasterPreferences> install_prefs(new MasterPreferences(
+ master_prefs_path.AppendASCII(kDefaultMasterPrefs)));
+ if (install_prefs && install_prefs->read_from_file())
+ return install_prefs.Pass();
+
+ return scoped_ptr<MasterPreferences>();
+}
+
+} // namespace
+
+EULAAcceptanceResponse IsEULAAccepted() {
+ ProductState prod_state;
+
+ // If user-level products exist, then EULA has been accepted.
grt (UTC plus 2) 2013/01/24 21:04:55 Are you sure it's is safe to consider the eula to
huangs 2013/01/25 01:13:23 Changing interface to get "bool system_level" para
+ if (prod_state.Initialize(false, BrowserDistribution::CHROME_BINARIES)
+ || prod_state.Initialize(false, BrowserDistribution::CHROME_BROWSER)) {
+ return EULA_YES;
+ }
+
+ // Try to use system-level Chrome binaries product state first.
erikwright (departed) 2013/01/24 20:27:40 nit 'first' now seems out of place. Probably OK to
huangs 2013/01/25 01:13:23 Removed.
+ if (!prod_state.Initialize(true, BrowserDistribution::CHROME_BINARIES)) {
+ // Fall back to using system-level Chrome product state.
+ if (!prod_state.Initialize(true, BrowserDistribution::CHROME_BROWSER))
+ return EULA_FAIL;
+
+ LOG_IF(DFATAL, prod_state.is_multi_install())
+ << "Binaries are not installed, but Chrome is multi-install.";
+ }
+
+ BrowserDistribution* dist = BrowserDistribution::GetSpecificDistribution(
+ BrowserDistribution::CHROME_BROWSER);
+
+ // Is Google Update waiting for Chrome's EULA to be accepted?
+ DWORD eula_accepted = 0;
+ if (prod_state.GetEulaAccepted(&eula_accepted) && !eula_accepted)
+ return EULA_NO;
+
+ if (!IsChromeFirstRunPending(dist) || IsEULAAcceptanceFlagged(dist))
+ return EULA_YES;
+
+ // EULA acceptance not flagged. Now see if it is required.
+ scoped_ptr<MasterPreferences> install_prefs(GetMasterPrefs(prod_state));
+ // If we fail to get master preferences, assume EULA is not accepted.
+ if (!install_prefs)
+ return EULA_NO;
+
+ bool eula_required = false;
+ // If kRequireEula value is absent, assume EULA is not required.
+ if (!install_prefs->GetBool(master_preferences::kRequireEula, &eula_required))
+ return EULA_YES;
+
+ return eula_required ? EULA_NO : EULA_YES;
+}
+
+} // namespace installer

Powered by Google App Engine
This is Rietveld 408576698