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

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: Fixing installation validator unit test. Created 7 years, 10 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
« no previous file with comments | « chrome/installer/util/eula_util.h ('k') | chrome/installer/util/installation_validator.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 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 } // namespace
56
57 EULAAcceptanceResponse IsEULAAccepted(bool system_level) {
58 ProductState prod_state;
59
60 if (!system_level) { // User-level case has seprate flow.
61 // Do not simply check Chrome binaries; go through list of products whose
62 // presence at user-level implies that EULA has been accepted.
63 return prod_state.Initialize(false, BrowserDistribution::CHROME_BROWSER)
64 || prod_state.Initialize(false, BrowserDistribution::CHROME_APP_HOST)
grt (UTC plus 2) 2013/01/29 20:23:32 CHROME_FRAME?
huangs 2013/01/29 21:48:10 Added and refactored.
65 ? QUERY_EULA_ACCEPTED : QUERY_EULA_NOT_ACCEPTED;
66 }
67
68 // System-level. Try to use Chrome binaries product state.
69 if (!prod_state.Initialize(true, BrowserDistribution::CHROME_BINARIES)) {
70 // Fall back to using Chrome product state.
71 if (!prod_state.Initialize(true, BrowserDistribution::CHROME_BROWSER))
72 return QUERY_EULA_FAIL;
73
74 LOG_IF(DFATAL, prod_state.is_multi_install())
75 << "Binaries are not installed, but Chrome is multi-install.";
76 }
77 BrowserDistribution* dist = BrowserDistribution::GetSpecificDistribution(
78 BrowserDistribution::CHROME_BROWSER);
79
80 // Is Google Update waiting for Chrome's EULA to be accepted?
81 DWORD eula_accepted = 0;
82 if (prod_state.GetEulaAccepted(&eula_accepted) && !eula_accepted)
83 return QUERY_EULA_NOT_ACCEPTED;
84
85 if (!IsChromeFirstRunPending(dist) || IsEULAAcceptanceFlagged(dist))
86 return QUERY_EULA_ACCEPTED;
87
88 // EULA acceptance not flagged. Now see if it is required.
89 scoped_ptr<MasterPreferences> install_prefs(GetMasterPrefs(prod_state));
90 // If we fail to get master preferences, assume that EULA is not required.
91 if (!install_prefs)
92 return QUERY_EULA_ACCEPTED;
93
94 bool eula_required = false;
95 // If kRequireEula value is absent, assume EULA is not required.
96 if (!install_prefs->GetBool(master_preferences::kRequireEula, &eula_required))
97 return QUERY_EULA_ACCEPTED;
98
99 return eula_required ? QUERY_EULA_NOT_ACCEPTED : QUERY_EULA_ACCEPTED;
100 }
101
102 } // namespace installer
OLDNEW
« no previous file with comments | « chrome/installer/util/eula_util.h ('k') | chrome/installer/util/installation_validator.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698