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

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

Issue 145053004: Let chrome_prefs handle Preferences initialization from master_preferences. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix clang compile Created 6 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/browser/first_run/first_run.h ('k') | chrome/browser/first_run/first_run_browsertest.cc » ('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) 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 <algorithm> 7 #include <algorithm>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/compiler_specific.h" 10 #include "base/compiler_specific.h"
11 #include "base/file_util.h" 11 #include "base/file_util.h"
12 #include "base/files/file_path.h" 12 #include "base/files/file_path.h"
13 #include "base/json/json_file_value_serializer.h"
14 #include "base/lazy_instance.h" 13 #include "base/lazy_instance.h"
15 #include "base/memory/ref_counted.h" 14 #include "base/memory/ref_counted.h"
16 #include "base/message_loop/message_loop.h" 15 #include "base/message_loop/message_loop.h"
17 #include "base/metrics/histogram.h" 16 #include "base/metrics/histogram.h"
18 #include "base/path_service.h" 17 #include "base/path_service.h"
19 #include "base/prefs/pref_service.h" 18 #include "base/prefs/pref_service.h"
20 #include "base/strings/stringprintf.h" 19 #include "base/strings/stringprintf.h"
21 #include "base/strings/utf_string_conversions.h" 20 #include "base/strings/utf_string_conversions.h"
22 #include "build/build_config.h" 21 #include "build/build_config.h"
23 #include "chrome/browser/browser_process.h" 22 #include "chrome/browser/browser_process.h"
24 #include "chrome/browser/chrome_notification_types.h" 23 #include "chrome/browser/chrome_notification_types.h"
25 #include "chrome/browser/extensions/extension_service.h" 24 #include "chrome/browser/extensions/extension_service.h"
26 #include "chrome/browser/extensions/updater/extension_updater.h" 25 #include "chrome/browser/extensions/updater/extension_updater.h"
27 #include "chrome/browser/first_run/first_run_internal.h" 26 #include "chrome/browser/first_run/first_run_internal.h"
28 #include "chrome/browser/google/google_util.h" 27 #include "chrome/browser/google/google_util.h"
29 #include "chrome/browser/importer/external_process_importer_host.h" 28 #include "chrome/browser/importer/external_process_importer_host.h"
30 #include "chrome/browser/importer/importer_list.h" 29 #include "chrome/browser/importer/importer_list.h"
31 #include "chrome/browser/importer/importer_progress_observer.h" 30 #include "chrome/browser/importer/importer_progress_observer.h"
32 #include "chrome/browser/importer/importer_uma.h" 31 #include "chrome/browser/importer/importer_uma.h"
33 #include "chrome/browser/importer/profile_writer.h" 32 #include "chrome/browser/importer/profile_writer.h"
33 #include "chrome/browser/prefs/chrome_pref_service_factory.h"
34 #include "chrome/browser/profiles/profiles_state.h" 34 #include "chrome/browser/profiles/profiles_state.h"
35 #include "chrome/browser/search_engines/template_url_service.h" 35 #include "chrome/browser/search_engines/template_url_service.h"
36 #include "chrome/browser/search_engines/template_url_service_factory.h" 36 #include "chrome/browser/search_engines/template_url_service_factory.h"
37 #include "chrome/browser/shell_integration.h" 37 #include "chrome/browser/shell_integration.h"
38 #include "chrome/browser/signin/signin_manager.h" 38 #include "chrome/browser/signin/signin_manager.h"
39 #include "chrome/browser/signin/signin_manager_factory.h" 39 #include "chrome/browser/signin/signin_manager_factory.h"
40 #include "chrome/browser/signin/signin_promo.h" 40 #include "chrome/browser/signin/signin_promo.h"
41 #include "chrome/browser/signin/signin_tracker.h" 41 #include "chrome/browser/signin/signin_tracker.h"
42 #include "chrome/browser/ui/browser.h" 42 #include "chrome/browser/ui/browser.h"
43 #include "chrome/browser/ui/browser_finder.h" 43 #include "chrome/browser/ui/browser_finder.h"
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 162
163 void DoDelayedInstallExtensionsIfNeeded( 163 void DoDelayedInstallExtensionsIfNeeded(
164 installer::MasterPreferences* install_prefs) { 164 installer::MasterPreferences* install_prefs) {
165 base::DictionaryValue* extensions = 0; 165 base::DictionaryValue* extensions = 0;
166 if (install_prefs->GetExtensionsBlock(&extensions)) { 166 if (install_prefs->GetExtensionsBlock(&extensions)) {
167 VLOG(1) << "Extensions block found in master preferences"; 167 VLOG(1) << "Extensions block found in master preferences";
168 DoDelayedInstallExtensions(); 168 DoDelayedInstallExtensions();
169 } 169 }
170 } 170 }
171 171
172 base::FilePath GetDefaultPrefFilePath(bool create_profile_dir,
173 const base::FilePath& user_data_dir) {
174 base::FilePath default_pref_dir =
175 profiles::GetDefaultProfileDir(user_data_dir);
176 if (create_profile_dir) {
177 if (!base::PathExists(default_pref_dir)) {
178 if (!base::CreateDirectory(default_pref_dir))
179 return base::FilePath();
180 }
181 }
182 return profiles::GetProfilePrefsPath(default_pref_dir);
183 }
184
185 // Sets the |items| bitfield according to whether the import data specified by 172 // Sets the |items| bitfield according to whether the import data specified by
186 // |import_type| should be be auto imported or not. 173 // |import_type| should be be auto imported or not.
187 void SetImportItem(PrefService* user_prefs, 174 void SetImportItem(PrefService* user_prefs,
188 const char* pref_path, 175 const char* pref_path,
189 int import_items, 176 int import_items,
190 int dont_import_items, 177 int dont_import_items,
191 importer::ImportItem import_type, 178 importer::ImportItem import_type,
192 int* items) { 179 int* items) {
193 // Work out whether an item is to be imported according to what is specified 180 // Work out whether an item is to be imported according to what is specified
194 // in master preferences. 181 // in master preferences.
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after
459 } 446 }
460 } 447 }
461 448
462 } // namespace 449 } // namespace
463 450
464 namespace first_run { 451 namespace first_run {
465 namespace internal { 452 namespace internal {
466 453
467 FirstRunState first_run_ = FIRST_RUN_UNKNOWN; 454 FirstRunState first_run_ = FIRST_RUN_UNKNOWN;
468 455
469 bool GeneratePrefFile(const base::FilePath& user_data_dir,
470 const installer::MasterPreferences& master_prefs) {
471 base::FilePath user_prefs = GetDefaultPrefFilePath(true, user_data_dir);
472 if (user_prefs.empty())
473 return false;
474
475 const base::DictionaryValue& master_prefs_dict =
476 master_prefs.master_dictionary();
477
478 JSONFileValueSerializer serializer(user_prefs);
479
480 // Call Serialize (which does IO) on the main thread, which would _normally_
481 // be verboten. In this case however, we require this IO to synchronously
482 // complete before Chrome can start (as master preferences seed the Local
483 // State and Preferences files). This won't trip ThreadIORestrictions as they
484 // won't have kicked in yet on the main thread.
485 return serializer.Serialize(master_prefs_dict);
486 }
487
488 void SetupMasterPrefsFromInstallPrefs( 456 void SetupMasterPrefsFromInstallPrefs(
489 const installer::MasterPreferences& install_prefs, 457 const installer::MasterPreferences& install_prefs,
490 MasterPrefs* out_prefs) { 458 MasterPrefs* out_prefs) {
491 ConvertStringVectorToGURLVector( 459 ConvertStringVectorToGURLVector(
492 install_prefs.GetFirstRunTabs(), &out_prefs->new_tabs); 460 install_prefs.GetFirstRunTabs(), &out_prefs->new_tabs);
493 461
494 install_prefs.GetInt(installer::master_preferences::kDistroPingDelay, 462 install_prefs.GetInt(installer::master_preferences::kDistroPingDelay,
495 &out_prefs->ping_delay); 463 &out_prefs->ping_delay);
496 464
497 bool value = false; 465 bool value = false;
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
705 673
706 scoped_ptr<installer::MasterPreferences> install_prefs(LoadMasterPrefs()); 674 scoped_ptr<installer::MasterPreferences> install_prefs(LoadMasterPrefs());
707 675
708 // Default value in case master preferences is missing or corrupt, or 676 // Default value in case master preferences is missing or corrupt, or
709 // ping_delay is missing. 677 // ping_delay is missing.
710 out_prefs->ping_delay = 90; 678 out_prefs->ping_delay = 90;
711 if (install_prefs.get()) { 679 if (install_prefs.get()) {
712 if (!internal::ShowPostInstallEULAIfNeeded(install_prefs.get())) 680 if (!internal::ShowPostInstallEULAIfNeeded(install_prefs.get()))
713 return EULA_EXIT_NOW; 681 return EULA_EXIT_NOW;
714 682
715 if (!internal::GeneratePrefFile(user_data_dir, *install_prefs.get())) 683 if (!chrome_prefs::InitializePrefsFromMasterPrefs(
716 DLOG(ERROR) << "Failed to generate master_preferences in user data dir."; 684 profiles::GetDefaultProfileDir(user_data_dir),
685 install_prefs->master_dictionary())) {
686 DLOG(ERROR) << "Failed to initialize from master_preferences.";
687 }
717 688
718 DoDelayedInstallExtensionsIfNeeded(install_prefs.get()); 689 DoDelayedInstallExtensionsIfNeeded(install_prefs.get());
719 690
720 internal::SetupMasterPrefsFromInstallPrefs(*install_prefs, out_prefs); 691 internal::SetupMasterPrefsFromInstallPrefs(*install_prefs, out_prefs);
721 } 692 }
722 693
723 return FIRST_RUN_PROCEED; 694 return FIRST_RUN_PROCEED;
724 } 695 }
725 696
726 void AutoImport( 697 void AutoImport(
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
825 SetShouldDoPersonalDataManagerFirstRun(); 796 SetShouldDoPersonalDataManagerFirstRun();
826 797
827 internal::DoPostImportPlatformSpecificTasks(profile); 798 internal::DoPostImportPlatformSpecificTasks(profile);
828 } 799 }
829 800
830 uint16 auto_import_state() { 801 uint16 auto_import_state() {
831 return g_auto_import_state; 802 return g_auto_import_state;
832 } 803 }
833 804
834 } // namespace first_run 805 } // namespace first_run
OLDNEW
« no previous file with comments | « chrome/browser/first_run/first_run.h ('k') | chrome/browser/first_run/first_run_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698