Chromium Code Reviews| 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 100755 |
| index 0000000000000000000000000000000000000000..65c8984f4bb1ed20a9480bde1dc1e595a0afd828 |
| --- /dev/null |
| +++ b/chrome/installer/util/eula_util.cc |
| @@ -0,0 +1,93 @@ |
| +// 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) { |
|
erikwright (departed)
2013/01/24 19:09:54
Comment something like:
// Chrome creates a senti
huangs
2013/01/24 19:45:22
Done. Please note the subsequent comment is about
|
| + // 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 IsEULASentinelPresent(BrowserDistribution* dist) { |
|
erikwright (departed)
2013/01/24 19:09:54
Something like:
// Chrome creates a sentinel afte
huangs
2013/01/24 19:45:22
Renamed to IsEULAAcceptanceFlagged().
|
| + // 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; |
| + // Try to use system-level Chrome binaries product state first. |
| + if (!prod_state.Initialize(true, BrowserDistribution::CHROME_BINARIES)) { |
| + // Fall back to using Chrome product state. |
| + if (prod_state.Initialize(true, BrowserDistribution::CHROME_BROWSER)) { |
| + LOG_IF(DFATAL, prod_state.is_multi_install()) |
| + << "Binaries are not installed yet Chrome thinks it's multi-install."; |
| + } else { |
| + // Test user-level, and return EULA_YES if successful. |
| + return prod_state.Initialize(false, BrowserDistribution::CHROME_BINARIES) |
|
erikwright (departed)
2013/01/24 19:09:54
If we accept the presence of a user-level Chrome o
huangs
2013/01/24 19:45:22
Done.
|
| + || prod_state.Initialize(false, BrowserDistribution::CHROME_BROWSER) |
| + ? EULA_YES : EULA_FAIL; |
| + } |
| + } |
| + BrowserDistribution* dist = BrowserDistribution::GetSpecificDistribution( |
| + BrowserDistribution::CHROME_BROWSER); |
| + |
| + // Is Omaha 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) || IsEULASentinelPresent(dist)) |
| + return EULA_YES; |
| + |
| + // Sentinel is absent. Now see if it was required in the first place. |
| + scoped_ptr<MasterPreferences> install_prefs(GetMasterPrefs(prod_state)); |
| + // If we fail to get master preferences, assume EULA is not accepted. |
|
erikwright (departed)
2013/01/24 19:09:54
I think master preferences can reasonably be absen
grt (UTC plus 2)
2013/01/24 21:07:03
absolutely. no master preferences file should be t
huangs
2013/01/25 01:13:23
!!! In this case, we should return EULA_YES, since
|
| + 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 |