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..1f34959ba54dcd6237a40f7532687f95b66a9835 |
--- /dev/null |
+++ b/chrome/installer/util/eula_util.cc |
@@ -0,0 +1,98 @@ |
+// 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 <windows.h> |
+ |
+#include "base/file_util.h" |
+#include "chrome/common/chrome_constants.h" |
+#include "chrome/installer/launcher_support/chrome_launcher_support.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 IsChromeFirstRun(BrowserDistribution* dist) { |
grt (UTC plus 2)
2013/01/24 02:51:40
IsChromeFirstRun -> IsChromeFirstRunPending or som
huangs
2013/01/24 18:56:03
Done.
|
+ // If there is problem getting sentinel path, assume not first run. |
grt (UTC plus 2)
2013/01/24 02:51:40
If there is a problem getting the sentinel path, a
huangs
2013/01/24 18:56:03
Done (rephrased to fit line).
|
+ FilePath first_run_sentinel; |
+ return InstallUtil::GetSentinelFilePath(chrome::kFirstRunSentinel, |
+ dist, |
+ &first_run_sentinel) |
+ && !file_util::PathExists(first_run_sentinel); |
+} |
+ |
+bool IsEULASentinelPresent(BrowserDistribution* dist ) { |
grt (UTC plus 2)
2013/01/24 02:51:40
"dist " -> "dist"
huangs
2013/01/24 18:56:03
Done.
|
+ // If there is problem getting sentinel path, assume EULA not accepted. |
+ FilePath eula_sentinel; |
+ return InstallUtil::GetSentinelFilePath(kEULASentinelFile, |
+ dist, |
+ &eula_sentinel) |
+ && file_util::PathExists(eula_sentinel); |
+} |
+ |
+MasterPreferences* GetNewMasterPrefs() { |
grt (UTC plus 2)
2013/01/24 02:51:40
scoped_ptr<MasterPreferences> GetNewMasterPrefs()
huangs
2013/01/24 18:56:03
Done.
|
+ // The standard location of the master prefs is next to the chrome binary. |
+ FilePath chrome_exe(chrome_launcher_support::GetAnyChromePath()); |
grt (UTC plus 2)
2013/01/24 02:51:40
i haven't read what GetAnyChromePath does, but wha
huangs
2013/01/24 18:56:03
Done (need to pass const ProductState& product_sta
|
+ if (!chrome_exe.empty()) { |
+ FilePath master_prefs_path(chrome_exe.DirName()); |
+ MasterPreferences* install_prefs = new MasterPreferences( |
grt (UTC plus 2)
2013/01/24 02:51:40
scoped_ptr<MasterPreferences> install_prefs(...);
huangs
2013/01/24 18:56:03
Done.
|
+ master_prefs_path.AppendASCII(kDefaultMasterPrefs)); |
+ if (install_prefs != NULL) { |
grt (UTC plus 2)
2013/01/24 02:51:40
if (install_prefs && install_prefs->read_from_file
huangs
2013/01/24 18:56:03
Done.
|
+ if (install_prefs->read_from_file()) |
+ return install_prefs; |
+ |
+ delete install_prefs; |
+ } |
+ } |
+ return NULL; |
grt (UTC plus 2)
2013/01/24 02:51:40
you may need to make this:
return scoped_ptr<Mas
huangs
2013/01/24 18:56:03
Done. Thanks!
|
+} |
+ |
+bool IsEULARequiredInMasterPrefs(MasterPreferences* install_prefs) { |
grt (UTC plus 2)
2013/01/24 02:51:40
this function takes a MasterPreferences, so it doe
huangs
2013/01/24 18:56:03
The function is added because I was envisioning re
|
+ bool val = false; |
+ // If kRequireEula value is absent, assume EULA is not required. |
+ if (!install_prefs->GetBool(master_preferences::kRequireEula, &val)) |
+ return false; |
+ |
+ return val; |
+} |
+ |
+} // namespace |
+ |
+HRESULT IsEULAAccepted() { |
+ BrowserDistribution* dist = BrowserDistribution::GetSpecificDistribution( |
+ BrowserDistribution::CHROME_BINARIES); |
+ if (!dist) |
+ return E_FAIL; // Error: system-level binaries aren't installed. |
grt (UTC plus 2)
2013/01/24 02:51:40
!dist means that the impossible happened rather th
huangs
2013/01/24 18:56:03
Done.
|
+ |
+ ProductState binaries; |
+ if (!binaries.Initialize(true, dist) && !binaries.Initialize(false, dist)) |
grt (UTC plus 2)
2013/01/24 02:51:40
eula only applies to system-level installs. you sh
huangs
2013/01/24 18:56:03
Done. Also added logic to return EULA_YES when qu
|
+ return E_FAIL; |
+ |
+ // Is Omaha waiting for Chrome's EULA to be accepted? |
+ DWORD eula_accepted = 0; |
+ if (binaries.GetEulaAccepted(&eula_accepted) && !eula_accepted) |
+ return 0; |
+ |
+ // Has the current user been through first-run? |
+ if (!IsChromeFirstRun(dist)) |
grt (UTC plus 2)
2013/01/24 02:51:40
use the BrowserDistribution::CHROME_BROWSER instan
huangs
2013/01/24 18:56:03
Done.
|
+ return 1; |
+ |
grt (UTC plus 2)
2013/01/24 02:51:40
is the result the same if the EULA sentinel check
huangs
2013/01/24 18:56:03
It's a bit bizarre since we check for "yes" before
grt (UTC plus 2)
2013/01/24 21:04:55
it's an optimization. the cost of parsing master_p
|
+ scoped_ptr<MasterPreferences> install_prefs(GetNewMasterPrefs()); |
+ if (!install_prefs.get()) |
grt (UTC plus 2)
2013/01/24 02:51:40
if (!install_prefs)
huangs
2013/01/24 18:56:03
Done.
|
+ return 0; |
+ |
+ if (!IsEULARequiredInMasterPrefs(install_prefs.get())) |
+ return 1; |
+ |
+ return IsEULASentinelPresent(dist) ? 1 : 0; |
+} |
+ |
+} // namespace installer |