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 "base/file_util.h" | |
| 8 #include "base/memory/scoped_ptr.h" | |
| 9 #include "chrome/common/chrome_constants.h" | |
| 10 #include "chrome/installer/util/browser_distribution.h" | |
| 11 #include "chrome/installer/util/install_util.h" | |
| 12 #include "chrome/installer/util/installation_state.h" | |
| 13 #include "chrome/installer/util/master_preferences.h" | |
| 14 #include "chrome/installer/util/master_preferences_constants.h" | |
| 15 #include "chrome/installer/util/util_constants.h" | |
| 16 | |
| 17 namespace installer { | |
| 18 | |
| 19 namespace { | |
| 20 | |
| 21 bool IsChromeFirstRunPending(BrowserDistribution* dist) { | |
| 22 // Chrome creates the first run sentinel after the user has gone through the | |
| 23 // first-run flow. Assume Chrome has been run if the path to the sentinel | |
| 24 // cannot be determined. | |
| 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 IsEULAAcceptanceFlagged(BrowserDistribution* dist) { | |
| 33 // Chrome creates the EULA sentinel after the EULA has been accepted when | |
| 34 // doing so is required by master_preferences. Assume the EULA has not been | |
| 35 // accepted if the path to the sentinel cannot be determined. | |
| 36 FilePath eula_sentinel; | |
| 37 return InstallUtil::GetSentinelFilePath(kEULASentinelFile, | |
| 38 dist, | |
| 39 &eula_sentinel) | |
| 40 && file_util::PathExists(eula_sentinel); | |
| 41 } | |
| 42 | |
| 43 scoped_ptr<MasterPreferences> GetMasterPrefs(const ProductState& prod_state) { | |
| 44 // The standard location of the master prefs is next to the chrome binary. | |
| 45 FilePath master_prefs_path( | |
| 46 prod_state.GetSetupPath().DirName().DirName().DirName()); | |
| 47 scoped_ptr<MasterPreferences> install_prefs(new MasterPreferences( | |
| 48 master_prefs_path.AppendASCII(kDefaultMasterPrefs))); | |
| 49 if (install_prefs && install_prefs->read_from_file()) | |
| 50 return install_prefs.Pass(); | |
| 51 | |
| 52 return scoped_ptr<MasterPreferences>(); | |
| 53 } | |
| 54 | |
| 55 // Attempts to initialize |state| with any Chrome-related product. | |
| 56 // Returns true if any of these product are installed, otherwise false. | |
| 57 bool GetAnyChromeProductState(bool system_level, ProductState* state) { | |
| 58 return state->Initialize(system_level, BrowserDistribution::CHROME_BROWSER) | |
| 59 || state->Initialize(system_level, BrowserDistribution::CHROME_FRAME) | |
| 60 || state->Initialize(system_level, BrowserDistribution::CHROME_APP_HOST); | |
| 61 } | |
| 62 | |
| 63 } // namespace | |
| 64 | |
| 65 EULAAcceptanceResponse IsEULAAccepted(bool system_level) { | |
| 66 ProductState prod_state; | |
| 67 | |
| 68 if (!system_level) { // User-level case has seprate flow. | |
| 69 // Do not simply check Chrome binaries. Instead, check whether or not | |
| 70 // any Chrome-related products is installed, because the presence of any of | |
| 71 // these products at user-level implies that the EULA has been accepted. | |
| 72 return GetAnyChromeProductState(false, &prod_state) | |
| 73 ? QUERY_EULA_ACCEPTED : QUERY_EULA_NOT_ACCEPTED; | |
| 74 } | |
| 75 | |
| 76 // System-level. Try to use Chrome binaries product state. | |
| 77 if (!prod_state.Initialize(true, BrowserDistribution::CHROME_BINARIES)) { | |
| 78 // Fall back to Chrome Browser product state only. | |
| 79 if (!prod_state.Initialize(system_level, | |
|
grt (UTC plus 2)
2013/01/31 21:09:48
you can get rid of the braces if you switch back t
huangs
2013/01/31 23:11:31
Doh! Done.
| |
| 80 BrowserDistribution::CHROME_BROWSER)) { | |
| 81 return QUERY_EULA_FAIL; | |
| 82 } | |
| 83 | |
| 84 LOG_IF(DFATAL, prod_state.is_multi_install()) | |
| 85 << "Binaries are not installed, but found multi-install product."; | |
|
grt (UTC plus 2)
2013/01/31 21:09:48
"found multi-install product" -> "Chrome is multi-
huangs
2013/01/31 23:11:31
Done.
| |
| 86 } | |
| 87 BrowserDistribution* dist = BrowserDistribution::GetSpecificDistribution( | |
| 88 BrowserDistribution::CHROME_BROWSER); | |
| 89 | |
| 90 // Is Google Update waiting for Chrome's EULA to be accepted? | |
| 91 DWORD eula_accepted = 0; | |
| 92 if (prod_state.GetEulaAccepted(&eula_accepted) && !eula_accepted) | |
| 93 return QUERY_EULA_NOT_ACCEPTED; | |
| 94 | |
| 95 if (!IsChromeFirstRunPending(dist) || IsEULAAcceptanceFlagged(dist)) | |
| 96 return QUERY_EULA_ACCEPTED; | |
| 97 | |
| 98 // EULA acceptance not flagged. Now see if it is required. | |
| 99 scoped_ptr<MasterPreferences> install_prefs(GetMasterPrefs(prod_state)); | |
| 100 // If we fail to get master preferences, assume that EULA is not required. | |
| 101 if (!install_prefs) | |
| 102 return QUERY_EULA_ACCEPTED; | |
| 103 | |
| 104 bool eula_required = false; | |
| 105 // If kRequireEula value is absent, assume EULA is not required. | |
| 106 if (!install_prefs->GetBool(master_preferences::kRequireEula, &eula_required)) | |
| 107 return QUERY_EULA_ACCEPTED; | |
| 108 | |
| 109 return eula_required ? QUERY_EULA_NOT_ACCEPTED : QUERY_EULA_ACCEPTED; | |
| 110 } | |
| 111 | |
| 112 } // namespace installer | |
| OLD | NEW |