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

Side by Side Diff: chrome/browser/first_run_win.cc

Issue 3042010: Fixes for first run path.... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 10 years, 5 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 | « no previous file | chrome/browser/views/location_bar/location_bar_view.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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.h" 5 #include "chrome/browser/first_run.h"
6 6
7 #include <windows.h> 7 #include <windows.h>
8 #include <shellapi.h> 8 #include <shellapi.h>
9 #include <shlobj.h> 9 #include <shlobj.h>
10 10
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 if (terms.empty()) 156 if (terms.empty())
157 return false; 157 return false;
158 FilePath temp_dir; 158 FilePath temp_dir;
159 if (!file_util::GetTempDir(&temp_dir)) 159 if (!file_util::GetTempDir(&temp_dir))
160 return false; 160 return false;
161 *eula_path = temp_dir.Append(L"chrome_eula_iframe.html"); 161 *eula_path = temp_dir.Append(L"chrome_eula_iframe.html");
162 return (file_util::WriteFile(*eula_path, terms.data(), terms.size()) > 0); 162 return (file_util::WriteFile(*eula_path, terms.data(), terms.size()) > 0);
163 } 163 }
164 164
165 // Helper class that performs delayed first-run tasks that need more of the 165 // Helper class that performs delayed first-run tasks that need more of the
166 // chrome infrastructure to be up an running before they can be attempted. 166 // chrome infrastructure to be up and running before they can be attempted.
167 class FirsRunDelayedTasks : public NotificationObserver { 167 class FirstRunDelayedTasks : public NotificationObserver {
168 public: 168 public:
169 enum Tasks { 169 enum Tasks {
170 NO_TASK, 170 NO_TASK,
171 INSTALL_EXTENSIONS 171 INSTALL_EXTENSIONS
172 }; 172 };
173 173
174 explicit FirsRunDelayedTasks(Tasks task) { 174 explicit FirstRunDelayedTasks(Tasks task) {
175 if (task == INSTALL_EXTENSIONS) { 175 if (task == INSTALL_EXTENSIONS) {
176 registrar_.Add(this, NotificationType::EXTENSIONS_READY, 176 registrar_.Add(this, NotificationType::EXTENSIONS_READY,
177 NotificationService::AllSources()); 177 NotificationService::AllSources());
178 } 178 }
179 registrar_.Add(this, NotificationType::BROWSER_CLOSED, 179 registrar_.Add(this, NotificationType::BROWSER_CLOSED,
180 NotificationService::AllSources()); 180 NotificationService::AllSources());
181 } 181 }
182 182
183 virtual void Observe(NotificationType type, 183 virtual void Observe(NotificationType type,
184 const NotificationSource& source, 184 const NotificationSource& source,
185 const NotificationDetails& details) { 185 const NotificationDetails& details) {
186 // After processing the notification we always delete ourselves. 186 // After processing the notification we always delete ourselves.
187 if (type.value == NotificationType::EXTENSIONS_READY) 187 if (type.value == NotificationType::EXTENSIONS_READY)
188 DoExtensionWork(Source<Profile>(source).ptr()->GetExtensionsService()); 188 DoExtensionWork(Source<Profile>(source).ptr()->GetExtensionsService());
189 delete this; 189 delete this;
190 return; 190 return;
191 } 191 }
192 192
193 private: 193 private:
194 // Private ctor forces it to be created only in the heap. 194 // Private ctor forces it to be created only in the heap.
195 ~FirsRunDelayedTasks() {} 195 ~FirstRunDelayedTasks() {}
196 196
197 // The extension work is to basically trigger an extension update check. 197 // The extension work is to basically trigger an extension update check.
198 // If the extension specified in the master pref is older than the live 198 // If the extension specified in the master pref is older than the live
199 // extension it will get updated which is the same as get it installed. 199 // extension it will get updated which is the same as get it installed.
200 void DoExtensionWork(ExtensionsService* service) { 200 void DoExtensionWork(ExtensionsService* service) {
201 if (!service) 201 if (!service)
202 return; 202 return;
203 service->updater()->CheckNow(); 203 service->updater()->CheckNow();
204 return; 204 return;
205 } 205 }
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
297 return true; 297 return true;
298 298
299 // The master prefs are regular prefs so we can just copy the file 299 // The master prefs are regular prefs so we can just copy the file
300 // to the default place and they just work. 300 // to the default place and they just work.
301 if (!file_util::CopyFile(master_prefs, user_prefs)) 301 if (!file_util::CopyFile(master_prefs, user_prefs))
302 return true; 302 return true;
303 303
304 DictionaryValue* extensions = 0; 304 DictionaryValue* extensions = 0;
305 if (installer_util::HasExtensionsBlock(prefs.get(), &extensions)) { 305 if (installer_util::HasExtensionsBlock(prefs.get(), &extensions)) {
306 LOG(INFO) << "Extensions block found in master preferences"; 306 LOG(INFO) << "Extensions block found in master preferences";
307 new FirsRunDelayedTasks(FirsRunDelayedTasks::INSTALL_EXTENSIONS); 307 new FirstRunDelayedTasks(FirstRunDelayedTasks::INSTALL_EXTENSIONS);
308 } 308 }
309 309
310 // Add a special exception for import_search_engine preference. 310 // If the search engine dialog is not shown, the search engine is set to
311 // Even though we skip all other import_* preferences below, if 311 // Google unless master_preferences specifically turns on search engine
312 // skip-first-run-ui is not specified, we make exception for this one 312 // import.
313 // preference.
314 int import_items = 0; 313 int import_items = 0;
315 if (installer_util::GetDistroBooleanPreference(prefs.get(), 314 if (installer_util::GetDistroBooleanPreference(prefs.get(),
316 installer_util::master_preferences::kDistroImportSearchPref, &value)) { 315 installer_util::master_preferences::kDistroImportSearchPref, &value)
317 if (value) { 316 && value) {
318 import_items += importer::SEARCH_ENGINES; 317 import_items |= importer::SEARCH_ENGINES;
319 out_prefs->do_import_items += importer::SEARCH_ENGINES; 318 out_prefs->do_import_items |= importer::SEARCH_ENGINES;
320 } else {
321 out_prefs->dont_import_items += importer::SEARCH_ENGINES;
322 }
323 } 319 }
324 320
321 // Check to see if search engine logos should be randomized.
322 if (installer_util::GetDistroBooleanPreference(prefs.get(),
323 installer_util::master_preferences::kSearchEngineExperimentRandomizePref,
324 &value) && value)
325 out_prefs->randomize_search_engine_experiment = true;
326
325 // If we're suppressing the first-run bubble, set that preference now. 327 // If we're suppressing the first-run bubble, set that preference now.
326 // Otherwise, wait until the user has completed first run to set it, so the 328 // Otherwise, wait until the user has completed first run to set it, so the
327 // user is guaranteed to see the bubble iff he or she has completed the first 329 // user is guaranteed to see the bubble iff he or she has completed the first
328 // run process. 330 // run process.
329 if (installer_util::GetDistroBooleanPreference(prefs.get(), 331 if (installer_util::GetDistroBooleanPreference(prefs.get(),
330 installer_util::master_preferences::kDistroSuppressFirstRunBubble, 332 installer_util::master_preferences::kDistroSuppressFirstRunBubble,
331 &value) && value) 333 &value) && value)
332 FirstRun::SetShowFirstRunBubblePref(false); 334 FirstRun::SetShowFirstRunBubblePref(false);
333 335
334 if (InSearchExperimentLocale() && 336
335 installer_util::GetDistroBooleanPreference(prefs.get(), 337 if (installer_util::GetDistroBooleanPreference(prefs.get(),
336 installer_util::master_preferences::kSearchEngineExperimentPref, 338 installer_util::master_preferences::kDistroImportHistoryPref, &value)) {
337 &value) && value) { 339 if (value) {
338 // Set the first run dialog to include the search choice window. 340 import_items |= importer::HISTORY;
339 out_prefs->run_search_engine_experiment = true; 341 } else {
340 // Check to see if search engine logos should be randomized. 342 // Automatic history import can be turned off in master_prefs.
341 if (installer_util::GetDistroBooleanPreference(prefs.get(), 343 out_prefs->dont_import_items |= importer::HISTORY;
342 installer_util::master_preferences::
343 kSearchEngineExperimentRandomizePref,
344 &value) && value) {
345 out_prefs->randomize_search_engine_experiment = true;
346 } 344 }
347 // Set the first run bubble to minimal.
348 FirstRun::SetMinimalFirstRunBubblePref();
349 } 345 }
350 346
351 // History is imported automatically, unless turned off in master_prefs.
352 if (installer_util::GetDistroBooleanPreference(prefs.get(), 347 if (installer_util::GetDistroBooleanPreference(prefs.get(),
353 installer_util::master_preferences::kDistroImportHistoryPref, &value) 348 installer_util::master_preferences::kDistroImportHomePagePref, &value)) {
354 && !value) { 349 if (value) {
355 out_prefs->dont_import_items |= importer::HISTORY; 350 import_items |= importer::HOME_PAGE;
356 } 351 } else {
357 352 // Automatic home page import can be turned off in master_prefs.
358 // Home page is imported automatically only in organic builds, and can be 353 out_prefs->dont_import_items |= importer::HOME_PAGE;
359 // turned off in master_prefs. 354 }
360 if (installer_util::GetDistroBooleanPreference(prefs.get(),
361 installer_util::master_preferences::kDistroImportHomePagePref, &value)
362 && !value) {
363 out_prefs->dont_import_items |= importer::HOME_PAGE;
364 } 355 }
365 356
366 // Bookmarks are never imported unless specifically turned on. 357 // Bookmarks are never imported unless specifically turned on.
367 if (installer_util::GetDistroBooleanPreference(prefs.get(), 358 if (installer_util::GetDistroBooleanPreference(prefs.get(),
368 installer_util::master_preferences::kDistroImportBookmarksPref, &value) 359 installer_util::master_preferences::kDistroImportBookmarksPref, &value)
369 && value) { 360 && value) {
361 import_items |= importer::FAVORITES;
370 out_prefs->do_import_items |= importer::FAVORITES; 362 out_prefs->do_import_items |= importer::FAVORITES;
371 } 363 }
372 364
365 if (installer_util::GetDistroBooleanPreference(prefs.get(),
366 installer_util::master_preferences::kMakeChromeDefaultForUser, &value) &&
367 value)
368 ShellIntegration::SetAsDefaultBrowser();
369
370 // TODO(mirandac): Refactor skip-first-run-ui process into regular first run
371 // import process. http://crbug.com/49647
373 // Note we are skipping all other master preferences if skip-first-run-ui 372 // Note we are skipping all other master preferences if skip-first-run-ui
374 // is *not* specified. (That is, we continue only if skipping first run ui.) 373 // is *not* specified. (That is, we continue only if skipping first run ui.)
375 if (!installer_util::GetDistroBooleanPreference(prefs.get(), 374 if (!installer_util::GetDistroBooleanPreference(prefs.get(),
376 installer_util::master_preferences::kDistroSkipFirstRunPref, &value) || 375 installer_util::master_preferences::kDistroSkipFirstRunPref, &value) ||
377 !value) 376 !value)
378 return true; 377 return true;
379 378
380 // From here on we won't show first run so we need to do the work to show the
381 // bubble anyway, unless it's already been explicitly suppressed.
382 FirstRun::SetShowFirstRunBubblePref(true);
383
384 // We need to be able to create the first run sentinel or else we cannot 379 // We need to be able to create the first run sentinel or else we cannot
385 // proceed because ImportSettings will launch the importer process which 380 // proceed because ImportSettings will launch the importer process which
386 // would end up here if the sentinel is not present. 381 // would end up here if the sentinel is not present.
387 if (!FirstRun::CreateSentinel()) 382 if (!FirstRun::CreateSentinel())
388 return false; 383 return false;
389 384
390 if (installer_util::GetDistroBooleanPreference(prefs.get(), 385 if (installer_util::GetDistroBooleanPreference(prefs.get(),
391 installer_util::master_preferences::kDistroShowWelcomePage, &value) && 386 installer_util::master_preferences::kDistroShowWelcomePage, &value) &&
392 value) 387 value)
393 FirstRun::SetShowWelcomePagePref(); 388 FirstRun::SetShowWelcomePagePref();
394 389
395 std::wstring import_bookmarks_path; 390 std::wstring import_bookmarks_path;
396 installer_util::GetDistroStringPreference(prefs.get(), 391 installer_util::GetDistroStringPreference(prefs.get(),
397 installer_util::master_preferences::kDistroImportBookmarksFromFilePref, 392 installer_util::master_preferences::kDistroImportBookmarksFromFilePref,
398 &import_bookmarks_path); 393 &import_bookmarks_path);
399 394
400 if (import_items || !import_bookmarks_path.empty()) { 395 if (import_items || !import_bookmarks_path.empty()) {
401 // There is something to import from the default browser. This launches 396 // There is something to import from the default browser. This launches
402 // the importer process and blocks until done or until it fails. 397 // the importer process and blocks until done or until it fails.
403 scoped_refptr<ImporterHost> importer_host = new ImporterHost(); 398 scoped_refptr<ImporterHost> importer_host = new ImporterHost();
404 if (!FirstRun::ImportSettings(NULL, 399 if (!FirstRun::ImportSettings(NULL,
405 importer_host->GetSourceProfileInfoAt(0).browser_type, 400 importer_host->GetSourceProfileInfoAt(0).browser_type,
406 import_items, import_bookmarks_path, NULL)) { 401 import_items, import_bookmarks_path, NULL)) {
407 LOG(WARNING) << "silent import failed"; 402 LOG(WARNING) << "silent import failed";
408 } 403 }
409 } 404 }
410 405
411 if (installer_util::GetDistroBooleanPreference(prefs.get(),
412 installer_util::master_preferences::kMakeChromeDefaultForUser, &value) &&
413 value)
414 ShellIntegration::SetAsDefaultBrowser();
415
416 return false; 406 return false;
417 } 407 }
418 408
419 bool Upgrade::IsBrowserAlreadyRunning() { 409 bool Upgrade::IsBrowserAlreadyRunning() {
420 static HANDLE handle = NULL; 410 static HANDLE handle = NULL;
421 std::wstring exe; 411 std::wstring exe;
422 PathService::Get(base::FILE_EXE, &exe); 412 PathService::Get(base::FILE_EXE, &exe);
423 std::replace(exe.begin(), exe.end(), '\\', '!'); 413 std::replace(exe.begin(), exe.end(), '\\', '!');
424 std::transform(exe.begin(), exe.end(), exe.begin(), tolower); 414 std::transform(exe.begin(), exe.end(), exe.begin(), tolower);
425 exe = L"Global\\" + exe; 415 exe = L"Global\\" + exe;
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after
671 randomize_search_engine_experiment)); 661 randomize_search_engine_experiment));
672 DCHECK(search_engine_dialog); 662 DCHECK(search_engine_dialog);
673 663
674 search_engine_dialog->Show(); 664 search_engine_dialog->Show();
675 views::AcceleratorHandler accelerator_handler; 665 views::AcceleratorHandler accelerator_handler;
676 MessageLoopForUI::current()->Run(&accelerator_handler); 666 MessageLoopForUI::current()->Run(&accelerator_handler);
677 search_engine_dialog->Close(); 667 search_engine_dialog->Close();
678 } 668 }
679 } 669 }
680 670
671 FirstRun::SetShowFirstRunBubblePref(true);
672 // Set the first run bubble to minimal.
673 FirstRun::SetMinimalFirstRunBubblePref();
674
681 process_singleton->Unlock(); 675 process_singleton->Unlock();
682 FirstRun::CreateSentinel(); 676 FirstRun::CreateSentinel();
683 } 677 }
684 678
685 bool FirstRun::ImportSettings(Profile* profile, int browser_type, 679 bool FirstRun::ImportSettings(Profile* profile, int browser_type,
686 int items_to_import, 680 int items_to_import,
687 const std::wstring& import_bookmarks_path, 681 const std::wstring& import_bookmarks_path,
688 HWND parent_window) { 682 HWND parent_window) {
689 const CommandLine& cmdline = *CommandLine::ForCurrentProcess(); 683 const CommandLine& cmdline = *CommandLine::ForCurrentProcess();
690 CommandLine import_cmd(cmdline.GetProgram()); 684 CommandLine import_cmd(cmdline.GetProgram());
(...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after
1068 1062
1069 Upgrade::TryResult Upgrade::ShowTryChromeDialog(size_t version) { 1063 Upgrade::TryResult Upgrade::ShowTryChromeDialog(size_t version) {
1070 if (version > 10000) { 1064 if (version > 10000) {
1071 // This is a test value. We want to make sure we exercise 1065 // This is a test value. We want to make sure we exercise
1072 // returning this early. See EarlyReturnTest test harness. 1066 // returning this early. See EarlyReturnTest test harness.
1073 return Upgrade::TD_NOT_NOW; 1067 return Upgrade::TD_NOT_NOW;
1074 } 1068 }
1075 TryChromeDialog td; 1069 TryChromeDialog td;
1076 return td.ShowModal(); 1070 return td.ShowModal();
1077 } 1071 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/views/location_bar/location_bar_view.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698