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

Side by Side Diff: chrome/browser/first_run/first_run_win.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: Code complete: added app command install and app_host.exe wait/forward. 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
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/first_run/first_run.h" 5 #include "chrome/browser/first_run/first_run.h"
6 6
7 #include <shellapi.h> 7 #include <shellapi.h>
8 #include <shlobj.h> 8 #include <shlobj.h>
9 #include <windows.h> 9 #include <windows.h>
10 10
11 #include "base/callback.h" 11 #include "base/callback.h"
12 #include "base/environment.h" 12 #include "base/environment.h"
13 #include "base/file_path.h" 13 #include "base/file_path.h"
14 #include "base/file_util.h" 14 #include "base/file_util.h"
15 #include "base/path_service.h" 15 #include "base/path_service.h"
16 #include "base/process_util.h" 16 #include "base/process_util.h"
17 #include "base/string_number_conversions.h" 17 #include "base/string_number_conversions.h"
18 #include "base/string_split.h" 18 #include "base/string_split.h"
19 #include "base/stringprintf.h" 19 #include "base/stringprintf.h"
20 #include "base/threading/sequenced_worker_pool.h" 20 #include "base/threading/sequenced_worker_pool.h"
21 #include "base/time.h" 21 #include "base/time.h"
22 #include "base/utf_string_conversions.h" 22 #include "base/utf_string_conversions.h"
23 #include "base/win/metro.h" 23 #include "base/win/metro.h"
24 #include "base/win/object_watcher.h" 24 #include "base/win/object_watcher.h"
25 #include "base/win/registry.h"
grt (UTC plus 2) 2013/01/23 19:02:29 remove this
huangs 2013/01/24 00:08:08 Moot; all Browser-specific changes are now gone.
25 #include "base/win/windows_version.h" 26 #include "base/win/windows_version.h"
26 #include "chrome/browser/browser_process.h" 27 #include "chrome/browser/browser_process.h"
27 #include "chrome/browser/first_run/first_run_import_observer.h" 28 #include "chrome/browser/first_run/first_run_import_observer.h"
28 #include "chrome/browser/first_run/first_run_internal.h" 29 #include "chrome/browser/first_run/first_run_internal.h"
29 #include "chrome/browser/importer/importer_host.h" 30 #include "chrome/browser/importer/importer_host.h"
30 #include "chrome/browser/importer/importer_list.h" 31 #include "chrome/browser/importer/importer_list.h"
31 #include "chrome/browser/importer/importer_progress_dialog.h" 32 #include "chrome/browser/importer/importer_progress_dialog.h"
32 #include "chrome/browser/prefs/pref_service.h" 33 #include "chrome/browser/prefs/pref_service.h"
33 #include "chrome/browser/process_singleton.h" 34 #include "chrome/browser/process_singleton.h"
34 #include "chrome/browser/profiles/profile.h" 35 #include "chrome/browser/profiles/profile.h"
35 #include "chrome/browser/shell_integration.h" 36 #include "chrome/browser/shell_integration.h"
36 #include "chrome/common/chrome_constants.h" 37 #include "chrome/common/chrome_constants.h"
37 #include "chrome/common/chrome_paths.h" 38 #include "chrome/common/chrome_paths.h"
38 #include "chrome/common/chrome_result_codes.h" 39 #include "chrome/common/chrome_result_codes.h"
39 #include "chrome/common/chrome_switches.h" 40 #include "chrome/common/chrome_switches.h"
40 #include "chrome/common/pref_names.h" 41 #include "chrome/common/pref_names.h"
41 #include "chrome/common/worker_thread_ticker.h" 42 #include "chrome/common/worker_thread_ticker.h"
42 #include "chrome/installer/util/browser_distribution.h" 43 #include "chrome/installer/util/browser_distribution.h"
43 #include "chrome/installer/util/google_update_settings.h" 44 #include "chrome/installer/util/google_update_settings.h"
44 #include "chrome/installer/util/install_util.h" 45 #include "chrome/installer/util/install_util.h"
grt (UTC plus 2) 2013/01/23 19:02:29 #include "chrome/installer/util/installation_state
huangs 2013/01/24 00:08:08 Done for eula_util.cc
45 #include "chrome/installer/util/master_preferences.h" 46 #include "chrome/installer/util/master_preferences.h"
46 #include "chrome/installer/util/master_preferences_constants.h" 47 #include "chrome/installer/util/master_preferences_constants.h"
47 #include "chrome/installer/util/shell_util.h" 48 #include "chrome/installer/util/shell_util.h"
48 #include "chrome/installer/util/util_constants.h" 49 #include "chrome/installer/util/util_constants.h"
49 #include "content/public/browser/browser_thread.h" 50 #include "content/public/browser/browser_thread.h"
50 #include "content/public/browser/notification_service.h" 51 #include "content/public/browser/notification_service.h"
51 #include "content/public/browser/user_metrics.h" 52 #include "content/public/browser/user_metrics.h"
52 #include "google_update/google_update_idl.h" 53 #include "google_update/google_update_idl.h"
53 #include "grit/chromium_strings.h" 54 #include "grit/chromium_strings.h"
54 #include "grit/generated_resources.h" 55 #include "grit/generated_resources.h"
55 #include "grit/locale_settings.h" 56 #include "grit/locale_settings.h"
56 #include "grit/theme_resources.h" 57 #include "grit/theme_resources.h"
57 #include "ui/base/l10n/l10n_util.h" 58 #include "ui/base/l10n/l10n_util.h"
58 #include "ui/base/layout.h" 59 #include "ui/base/layout.h"
59 #include "ui/base/ui_base_switches.h" 60 #include "ui/base/ui_base_switches.h"
60 #include "ui/base/win/shell.h" 61 #include "ui/base/win/shell.h"
61 62
62 namespace { 63 namespace {
63 64
65 // Taken from google_update_constants.cc.
grt (UTC plus 2) 2013/01/23 19:02:29 remove these
huangs 2013/01/24 00:08:08 Done.
66 const wchar_t kRegPathGoogleUpdate[] = L"Software\\Google\\Update";
67 const wchar_t kRegEULAAceptedField[] = L"eulaaccepted";
68
64 // Launches the setup exe with the given parameter/value on the command-line. 69 // Launches the setup exe with the given parameter/value on the command-line.
65 // For non-metro Windows, it waits for its termination, returns its exit code 70 // For non-metro Windows, it waits for its termination, returns its exit code
66 // in |*ret_code|, and returns true if the exit code is valid. 71 // in |*ret_code|, and returns true if the exit code is valid.
67 // For metro Windows, it launches setup via ShellExecuteEx and returns in order 72 // For metro Windows, it launches setup via ShellExecuteEx and returns in order
68 // to bounce the user back to the desktop, then returns immediately. 73 // to bounce the user back to the desktop, then returns immediately.
69 bool LaunchSetupForEula(const FilePath::StringType& value, int* ret_code) { 74 bool LaunchSetupForEula(const FilePath::StringType& value, int* ret_code) {
70 FilePath exe_dir; 75 FilePath exe_dir;
71 if (!PathService::Get(base::DIR_MODULE, &exe_dir)) 76 if (!PathService::Get(base::DIR_MODULE, &exe_dir))
72 return false; 77 return false;
73 exe_dir = exe_dir.Append(installer::kInstallerDir); 78 exe_dir = exe_dir.Append(installer::kInstallerDir);
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 else if (!PathService::Get(chrome::DIR_USER_DATA, path)) 128 else if (!PathService::Get(chrome::DIR_USER_DATA, path))
124 return false; 129 return false;
125 *path = path->Append(file); 130 *path = path->Append(file);
126 return true; 131 return true;
127 } 132 }
128 133
129 bool GetEULASentinelFilePath(FilePath* path) { 134 bool GetEULASentinelFilePath(FilePath* path) {
130 return GetSentinelFilePath(installer::kEULASentinelFile, path); 135 return GetSentinelFilePath(installer::kEULASentinelFile, path);
131 } 136 }
132 137
133 // Returns true if the EULA is required but has not been accepted by this user. 138 // Reads HKLM/.../Google/Update/eulaaccepted into |value|.
139 // Returns true and updates |value| if successful; else |value| is unchanged.
140 bool GetGoogleUpdateEULAAccepted(DWORD* value) {
grt (UTC plus 2) 2013/01/23 19:02:29 remove this
huangs 2013/01/24 00:08:08 Done.
141 base::win::RegKey key(HKEY_LOCAL_MACHINE, kRegPathGoogleUpdate,
142 KEY_QUERY_VALUE);
143 return key.ReadValueDW(kRegEULAAceptedField, value) == ERROR_SUCCESS;
144 }
145
146 // Returns true if the EULA is not required, or has been accepted by this user.
134 // The EULA is considered having been accepted if the user has gotten past 147 // The EULA is considered having been accepted if the user has gotten past
135 // first run in the "other" environment (desktop or metro). 148 // first run in the "other" environment (desktop or metro).
136 bool IsEULANotAccepted(installer::MasterPreferences* install_prefs) { 149 bool IsEULAUnrequiredOrAccepted(installer::MasterPreferences* install_prefs) {
grt (UTC plus 2) 2013/01/23 19:02:29 please either justify this change or revert it and
huangs 2013/01/24 00:08:08 Reverted in this file. In eula_util.cc, decided t
137 bool value = false; 150 bool val = false;
138 if (install_prefs->GetBool(installer::master_preferences::kRequireEula, 151 // EULA not required if kRequireEula value is absent or false.
139 &value) && value) { 152 if (!install_prefs->GetBool(installer::master_preferences::kRequireEula, &val)
140 FilePath eula_sentinel; 153 || !val) {
141 // Be conservative and show the EULA if the path to the sentinel can't be 154 return true;
142 // determined.
143 if (!GetEULASentinelFilePath(&eula_sentinel) ||
144 !file_util::PathExists(eula_sentinel)) {
145 return true;
146 }
147 } 155 }
148 return false; 156
157 // Be conservative: problem getting sentinel path means EULA is not accepted.
158 FilePath eula_sentinel;
159 return GetEULASentinelFilePath(&eula_sentinel)
160 && file_util::PathExists(eula_sentinel);
149 } 161 }
150 162
151 // Writes the EULA to a temporary file, returned in |*eula_path|, and returns 163 // Writes the EULA to a temporary file, returned in |*eula_path|, and returns
152 // true if successful. 164 // true if successful.
153 bool WriteEULAtoTempFile(FilePath* eula_path) { 165 bool WriteEULAtoTempFile(FilePath* eula_path) {
154 std::string terms = l10n_util::GetStringUTF8(IDS_TERMS_HTML); 166 std::string terms = l10n_util::GetStringUTF8(IDS_TERMS_HTML);
155 if (terms.empty()) 167 if (terms.empty())
156 return false; 168 return false;
157 FILE *file = file_util::CreateAndOpenTemporaryFile(eula_path); 169 FILE *file = file_util::CreateAndOpenTemporaryFile(eula_path);
158 if (!file) 170 if (!file)
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after
448 if (!ImportSettingsWin(NULL, 460 if (!ImportSettingsWin(NULL,
449 importer_list->GetSourceProfileAt(0).importer_type, 461 importer_list->GetSourceProfileAt(0).importer_type,
450 out_prefs->do_import_items, 462 out_prefs->do_import_items,
451 FilePath::FromWStringHack(UTF8ToWide(import_bookmarks_path)), true)) { 463 FilePath::FromWStringHack(UTF8ToWide(import_bookmarks_path)), true)) {
452 LOG(WARNING) << "silent import failed"; 464 LOG(WARNING) << "silent import failed";
453 } 465 }
454 } 466 }
455 } 467 }
456 468
457 bool ShowPostInstallEULAIfNeeded(installer::MasterPreferences* install_prefs) { 469 bool ShowPostInstallEULAIfNeeded(installer::MasterPreferences* install_prefs) {
458 if (IsEULANotAccepted(install_prefs)) { 470 if (!IsEULAUnrequiredOrAccepted(install_prefs)) {
459 // Show the post-installation EULA. This is done by setup.exe and the 471 // Show the post-installation EULA. This is done by setup.exe and the
460 // result determines if we continue or not. We wait here until the user 472 // result determines if we continue or not. We wait here until the user
461 // dismisses the dialog. 473 // dismisses the dialog.
462 474
463 // The actual eula text is in a resource in chrome. We extract it to 475 // The actual eula text is in a resource in chrome. We extract it to
464 // a text file so setup.exe can use it as an inner frame. 476 // a text file so setup.exe can use it as an inner frame.
465 FilePath inner_html; 477 FilePath inner_html;
466 if (WriteEULAtoTempFile(&inner_html)) { 478 if (WriteEULAtoTempFile(&inner_html)) {
467 int retcode = 0; 479 int retcode = 0;
468 if (!LaunchSetupForEula(inner_html.value(), &retcode) || 480 if (!LaunchSetupForEula(inner_html.value(), &retcode) ||
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
501 } 513 }
502 514
503 FilePath MasterPrefsPath() { 515 FilePath MasterPrefsPath() {
504 // The standard location of the master prefs is next to the chrome binary. 516 // The standard location of the master prefs is next to the chrome binary.
505 FilePath master_prefs; 517 FilePath master_prefs;
506 if (!PathService::Get(base::DIR_EXE, &master_prefs)) 518 if (!PathService::Get(base::DIR_EXE, &master_prefs))
507 return FilePath(); 519 return FilePath();
508 return master_prefs.AppendASCII(installer::kDefaultMasterPrefs); 520 return master_prefs.AppendASCII(installer::kDefaultMasterPrefs);
509 } 521 }
510 522
523 bool IsEULAAccepted() {
524 DWORD google_udpate_eula_accepted = 0;
525 if (GetGoogleUpdateEULAAccepted(&google_udpate_eula_accepted)
grt (UTC plus 2) 2013/01/23 19:02:29 why are you checking if google update's EULA has b
huangs 2013/01/24 00:08:08 Made the change. Also: - Return value is HRESULT,
526 && !google_udpate_eula_accepted) {
527 return false;
528 }
529
530 if (!IsChromeFirstRun())
531 return true;
532
533 FilePath master_prefs_path;
534 scoped_ptr<installer::MasterPreferences>
535 install_prefs(internal::LoadMasterPrefs(&master_prefs_path));
536 if (!install_prefs.get())
537 return false;
538
539 return IsEULAUnrequiredOrAccepted(install_prefs.get());
540 }
541
511 } // namespace first_run 542 } // namespace first_run
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698