Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / installer / util / eula_util.cc
blob25bcba86f2e333c9a8ae1912a3ed3aec6a578d6f
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.
5 #include "chrome/installer/util/eula_util.h"
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"
17 namespace installer {
19 namespace {
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 base::FilePath first_run_sentinel;
26 return InstallUtil::GetSentinelFilePath(chrome::kFirstRunSentinel,
27 dist,
28 &first_run_sentinel)
29 && !base::PathExists(first_run_sentinel);
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 base::FilePath eula_sentinel;
37 return InstallUtil::GetSentinelFilePath(kEULASentinelFile,
38 dist,
39 &eula_sentinel)
40 && base::PathExists(eula_sentinel);
43 scoped_ptr<MasterPreferences> GetMasterPrefs(const ProductState& prod_state) {
44 // The standard location of the master prefs is next to the chrome binary.
45 base::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();
52 return scoped_ptr<MasterPreferences>();
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);
63 } // namespace
65 EULAAcceptanceResponse IsEULAAccepted(bool system_level) {
66 ProductState prod_state;
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;
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(true, BrowserDistribution::CHROME_BROWSER))
80 return QUERY_EULA_FAIL;
82 LOG_IF(DFATAL, prod_state.is_multi_install())
83 << "Binaries are not installed, but Chrome is multi-install.";
85 BrowserDistribution* dist = BrowserDistribution::GetSpecificDistribution(
86 BrowserDistribution::CHROME_BROWSER);
88 // Is Google Update waiting for Chrome's EULA to be accepted?
89 DWORD eula_accepted = 0;
90 if (prod_state.GetEulaAccepted(&eula_accepted) && !eula_accepted)
91 return QUERY_EULA_NOT_ACCEPTED;
93 if (!IsChromeFirstRunPending(dist) || IsEULAAcceptanceFlagged(dist))
94 return QUERY_EULA_ACCEPTED;
96 // EULA acceptance not flagged. Now see if it is required.
97 scoped_ptr<MasterPreferences> install_prefs(GetMasterPrefs(prod_state));
98 // If we fail to get master preferences, assume that EULA is not required.
99 if (!install_prefs)
100 return QUERY_EULA_ACCEPTED;
102 bool eula_required = false;
103 // If kRequireEula value is absent, assume EULA is not required.
104 if (!install_prefs->GetBool(master_preferences::kRequireEula, &eula_required))
105 return QUERY_EULA_ACCEPTED;
107 return eula_required ? QUERY_EULA_NOT_ACCEPTED : QUERY_EULA_ACCEPTED;
110 } // namespace installer