Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(72)

Side by Side Diff: chrome/installer/util/eula_util.cc

Issue 12035043: Implementing app command to query EULA acceptance state for Chrome. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Comments, naming, and cleanup. Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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 a sentinel file after first run, and we look for it.
grt (UTC plus 2) 2013/01/24 21:04:55 // Chrome creates the first run sentinel after the
huangs 2013/01/25 01:13:23 Done.
23 // However, if we fail to get the sentinel path, assume Chrome has been run.
24 FilePath first_run_sentinel;
25 return InstallUtil::GetSentinelFilePath(chrome::kFirstRunSentinel,
26 dist,
27 &first_run_sentinel)
28 && !file_util::PathExists(first_run_sentinel);
29 }
30
31 bool IsEULAAcceptanceFlagged(BrowserDistribution* dist) {
32 // Chrome creates a sentinel after the Eula is accepted.
grt (UTC plus 2) 2013/01/24 21:04:55 // Chrome creates the EULA sentinel after the EULA
huangs 2013/01/25 01:13:23 Done.
33 // But if we fail to get 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 scoped_ptr<MasterPreferences> GetMasterPrefs(const ProductState& prod_state) {
42 // The standard location of the master prefs is next to the chrome binary.
43 FilePath master_prefs_path(
44 prod_state.GetSetupPath().DirName().DirName().DirName());
45 scoped_ptr<MasterPreferences> install_prefs(new MasterPreferences(
46 master_prefs_path.AppendASCII(kDefaultMasterPrefs)));
47 if (install_prefs && install_prefs->read_from_file())
48 return install_prefs.Pass();
49
50 return scoped_ptr<MasterPreferences>();
51 }
52
53 } // namespace
54
55 EULAAcceptanceResponse IsEULAAccepted() {
56 ProductState prod_state;
57
58 // If user-level products exist, then EULA has been accepted.
grt (UTC plus 2) 2013/01/24 21:04:55 Are you sure it's is safe to consider the eula to
huangs 2013/01/25 01:13:23 Changing interface to get "bool system_level" para
59 if (prod_state.Initialize(false, BrowserDistribution::CHROME_BINARIES)
60 || prod_state.Initialize(false, BrowserDistribution::CHROME_BROWSER)) {
61 return EULA_YES;
62 }
63
64 // Try to use system-level Chrome binaries product state first.
erikwright (departed) 2013/01/24 20:27:40 nit 'first' now seems out of place. Probably OK to
huangs 2013/01/25 01:13:23 Removed.
65 if (!prod_state.Initialize(true, BrowserDistribution::CHROME_BINARIES)) {
66 // Fall back to using system-level Chrome product state.
67 if (!prod_state.Initialize(true, BrowserDistribution::CHROME_BROWSER))
68 return EULA_FAIL;
69
70 LOG_IF(DFATAL, prod_state.is_multi_install())
71 << "Binaries are not installed, but Chrome is multi-install.";
72 }
73
74 BrowserDistribution* dist = BrowserDistribution::GetSpecificDistribution(
75 BrowserDistribution::CHROME_BROWSER);
76
77 // Is Google Update waiting for Chrome's EULA to be accepted?
78 DWORD eula_accepted = 0;
79 if (prod_state.GetEulaAccepted(&eula_accepted) && !eula_accepted)
80 return EULA_NO;
81
82 if (!IsChromeFirstRunPending(dist) || IsEULAAcceptanceFlagged(dist))
83 return EULA_YES;
84
85 // EULA acceptance not flagged. Now see if it is required.
86 scoped_ptr<MasterPreferences> install_prefs(GetMasterPrefs(prod_state));
87 // If we fail to get master preferences, assume EULA is not accepted.
88 if (!install_prefs)
89 return EULA_NO;
90
91 bool eula_required = false;
92 // If kRequireEula value is absent, assume EULA is not required.
93 if (!install_prefs->GetBool(master_preferences::kRequireEula, &eula_required))
94 return EULA_YES;
95
96 return eula_required ? EULA_NO : EULA_YES;
97 }
98
99 } // namespace installer
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698