Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/installer/util/eula_util.h" | |
| 6 | |
| 7 #include <windows.h> | |
| 8 | |
| 9 #include "base/file_util.h" | |
| 10 #include "chrome/common/chrome_constants.h" | |
| 11 #include "chrome/installer/launcher_support/chrome_launcher_support.h" | |
| 12 #include "chrome/installer/util/browser_distribution.h" | |
| 13 #include "chrome/installer/util/install_util.h" | |
| 14 #include "chrome/installer/util/installation_state.h" | |
| 15 #include "chrome/installer/util/master_preferences.h" | |
| 16 #include "chrome/installer/util/master_preferences_constants.h" | |
| 17 #include "chrome/installer/util/util_constants.h" | |
| 18 | |
| 19 namespace installer { | |
| 20 | |
| 21 namespace { | |
| 22 | |
| 23 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.
| |
| 24 // 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).
| |
| 25 FilePath first_run_sentinel; | |
| 26 return InstallUtil::GetSentinelFilePath(chrome::kFirstRunSentinel, | |
| 27 dist, | |
| 28 &first_run_sentinel) | |
| 29 && !file_util::PathExists(first_run_sentinel); | |
| 30 } | |
| 31 | |
| 32 bool IsEULASentinelPresent(BrowserDistribution* dist ) { | |
|
grt (UTC plus 2)
2013/01/24 02:51:40
"dist " -> "dist"
huangs
2013/01/24 18:56:03
Done.
| |
| 33 // If there is problem getting sentinel path, assume EULA not accepted. | |
| 34 FilePath eula_sentinel; | |
| 35 return InstallUtil::GetSentinelFilePath(kEULASentinelFile, | |
| 36 dist, | |
| 37 &eula_sentinel) | |
| 38 && file_util::PathExists(eula_sentinel); | |
| 39 } | |
| 40 | |
| 41 MasterPreferences* GetNewMasterPrefs() { | |
|
grt (UTC plus 2)
2013/01/24 02:51:40
scoped_ptr<MasterPreferences> GetNewMasterPrefs()
huangs
2013/01/24 18:56:03
Done.
| |
| 42 // The standard location of the master prefs is next to the chrome binary. | |
| 43 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
| |
| 44 if (!chrome_exe.empty()) { | |
| 45 FilePath master_prefs_path(chrome_exe.DirName()); | |
| 46 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.
| |
| 47 master_prefs_path.AppendASCII(kDefaultMasterPrefs)); | |
| 48 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.
| |
| 49 if (install_prefs->read_from_file()) | |
| 50 return install_prefs; | |
| 51 | |
| 52 delete install_prefs; | |
| 53 } | |
| 54 } | |
| 55 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!
| |
| 56 } | |
| 57 | |
| 58 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
| |
| 59 bool val = false; | |
| 60 // If kRequireEula value is absent, assume EULA is not required. | |
| 61 if (!install_prefs->GetBool(master_preferences::kRequireEula, &val)) | |
| 62 return false; | |
| 63 | |
| 64 return val; | |
| 65 } | |
| 66 | |
| 67 } // namespace | |
| 68 | |
| 69 HRESULT IsEULAAccepted() { | |
| 70 BrowserDistribution* dist = BrowserDistribution::GetSpecificDistribution( | |
| 71 BrowserDistribution::CHROME_BINARIES); | |
| 72 if (!dist) | |
| 73 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.
| |
| 74 | |
| 75 ProductState binaries; | |
| 76 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
| |
| 77 return E_FAIL; | |
| 78 | |
| 79 // Is Omaha waiting for Chrome's EULA to be accepted? | |
| 80 DWORD eula_accepted = 0; | |
| 81 if (binaries.GetEulaAccepted(&eula_accepted) && !eula_accepted) | |
| 82 return 0; | |
| 83 | |
| 84 // Has the current user been through first-run? | |
| 85 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.
| |
| 86 return 1; | |
| 87 | |
|
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
| |
| 88 scoped_ptr<MasterPreferences> install_prefs(GetNewMasterPrefs()); | |
| 89 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.
| |
| 90 return 0; | |
| 91 | |
| 92 if (!IsEULARequiredInMasterPrefs(install_prefs.get())) | |
| 93 return 1; | |
| 94 | |
| 95 return IsEULASentinelPresent(dist) ? 1 : 0; | |
| 96 } | |
| 97 | |
| 98 } // namespace installer | |
| OLD | NEW |