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..058de2a424947e43a91d5c17cf74e758589d11da |
--- /dev/null |
+++ b/chrome/installer/util/eula_util.cc |
@@ -0,0 +1,102 @@ |
+// 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 the first run sentinel after the user has gone through the |
+ // first-run flow. Assume Chrome has been run if the path to the sentinel |
+ // cannot be determined. |
+ 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 the EULA sentinel after the EULA has been accepted when |
+ // doing so is required by master_preferences. Assume the EULA has not been |
+ // accepted if the path to the sentinel cannot be determined. |
+ 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(bool system_level) { |
+ ProductState prod_state; |
+ |
+ if (!system_level) { // User-level case has seprate flow. |
+ // Do not simply check Chrome binaries; go through list of products whose |
+ // presence at user-level implies that EULA has been accepted. |
+ return prod_state.Initialize(false, BrowserDistribution::CHROME_BROWSER) |
+ || prod_state.Initialize(false, BrowserDistribution::CHROME_APP_HOST) |
grt (UTC plus 2)
2013/01/29 20:23:32
CHROME_FRAME?
huangs
2013/01/29 21:48:10
Added and refactored.
|
+ ? QUERY_EULA_ACCEPTED : QUERY_EULA_NOT_ACCEPTED; |
+ } |
+ |
+ // System-level. Try to use Chrome binaries product state. |
+ if (!prod_state.Initialize(true, BrowserDistribution::CHROME_BINARIES)) { |
+ // Fall back to using Chrome product state. |
+ if (!prod_state.Initialize(true, BrowserDistribution::CHROME_BROWSER)) |
+ return QUERY_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 QUERY_EULA_NOT_ACCEPTED; |
+ |
+ if (!IsChromeFirstRunPending(dist) || IsEULAAcceptanceFlagged(dist)) |
+ return QUERY_EULA_ACCEPTED; |
+ |
+ // 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 that EULA is not required. |
+ if (!install_prefs) |
+ return QUERY_EULA_ACCEPTED; |
+ |
+ bool eula_required = false; |
+ // If kRequireEula value is absent, assume EULA is not required. |
+ if (!install_prefs->GetBool(master_preferences::kRequireEula, &eula_required)) |
+ return QUERY_EULA_ACCEPTED; |
+ |
+ return eula_required ? QUERY_EULA_NOT_ACCEPTED : QUERY_EULA_ACCEPTED; |
+} |
+ |
+} // namespace installer |