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

Side by Side Diff: chrome/browser/profiles/profile_impl.cc

Issue 11570009: Split PrefService into PrefService, PrefServiceSimple and PrefServiceSyncable. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Ready for review. Created 8 years 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/profiles/profile_impl.h" 5 #include "chrome/browser/profiles/profile_impl.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/callback.h" 8 #include "base/callback.h"
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/compiler_specific.h" 10 #include "base/compiler_specific.h"
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 #include "chrome/browser/history/top_sites.h" 46 #include "chrome/browser/history/top_sites.h"
47 #include "chrome/browser/metrics/metrics_service.h" 47 #include "chrome/browser/metrics/metrics_service.h"
48 #include "chrome/browser/net/chrome_url_request_context.h" 48 #include "chrome/browser/net/chrome_url_request_context.h"
49 #include "chrome/browser/net/net_pref_observer.h" 49 #include "chrome/browser/net/net_pref_observer.h"
50 #include "chrome/browser/net/predictor.h" 50 #include "chrome/browser/net/predictor.h"
51 #include "chrome/browser/net/proxy_service_factory.h" 51 #include "chrome/browser/net/proxy_service_factory.h"
52 #include "chrome/browser/net/ssl_config_service_manager.h" 52 #include "chrome/browser/net/ssl_config_service_manager.h"
53 #include "chrome/browser/net/url_fixer_upper.h" 53 #include "chrome/browser/net/url_fixer_upper.h"
54 #include "chrome/browser/plugins/plugin_prefs.h" 54 #include "chrome/browser/plugins/plugin_prefs.h"
55 #include "chrome/browser/prefs/browser_prefs.h" 55 #include "chrome/browser/prefs/browser_prefs.h"
56 #include "chrome/browser/prefs/chrome_pref_service_builder.h" 56 #include "chrome/browser/prefs/chrome_pref_service_factory.h"
57 #include "chrome/browser/prefs/scoped_user_pref_update.h" 57 #include "chrome/browser/prefs/scoped_user_pref_update.h"
58 #include "chrome/browser/prerender/prerender_manager_factory.h" 58 #include "chrome/browser/prerender/prerender_manager_factory.h"
59 #include "chrome/browser/profiles/chrome_version_service.h" 59 #include "chrome/browser/profiles/chrome_version_service.h"
60 #include "chrome/browser/profiles/gaia_info_update_service.h" 60 #include "chrome/browser/profiles/gaia_info_update_service.h"
61 #include "chrome/browser/profiles/profile_dependency_manager.h" 61 #include "chrome/browser/profiles/profile_dependency_manager.h"
62 #include "chrome/browser/profiles/profile_destroyer.h" 62 #include "chrome/browser/profiles/profile_destroyer.h"
63 #include "chrome/browser/profiles/profile_info_cache.h" 63 #include "chrome/browser/profiles/profile_info_cache.h"
64 #include "chrome/browser/profiles/profile_manager.h" 64 #include "chrome/browser/profiles/profile_manager.h"
65 #include "chrome/browser/search_engines/template_url_fetcher.h" 65 #include "chrome/browser/search_engines/template_url_fetcher.h"
66 #include "chrome/browser/sessions/session_service_factory.h" 66 #include "chrome/browser/sessions/session_service_factory.h"
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
262 return new ProfileImpl(path, delegate, create_mode, sequenced_task_runner); 262 return new ProfileImpl(path, delegate, create_mode, sequenced_task_runner);
263 } 263 }
264 264
265 // static 265 // static
266 int ProfileImpl::create_readme_delay_ms = 60000; 266 int ProfileImpl::create_readme_delay_ms = 60000;
267 267
268 // static 268 // static
269 const char* const ProfileImpl::kPrefExitTypeNormal = "Normal"; 269 const char* const ProfileImpl::kPrefExitTypeNormal = "Normal";
270 270
271 // static 271 // static
272 void ProfileImpl::RegisterUserPrefs(PrefService* prefs) { 272 void ProfileImpl::RegisterUserPrefs(PrefServiceSyncable* prefs) {
273 prefs->RegisterBooleanPref(prefs::kSavingBrowserHistoryDisabled, 273 prefs->RegisterBooleanPref(prefs::kSavingBrowserHistoryDisabled,
274 false, 274 false,
275 PrefService::UNSYNCABLE_PREF); 275 PrefServiceSyncable::UNSYNCABLE_PREF);
276 prefs->RegisterBooleanPref(prefs::kForceSafeSearch, 276 prefs->RegisterBooleanPref(prefs::kForceSafeSearch,
277 false, 277 false,
278 PrefService::UNSYNCABLE_PREF); 278 PrefServiceSyncable::UNSYNCABLE_PREF);
279 prefs->RegisterIntegerPref(prefs::kProfileAvatarIndex, 279 prefs->RegisterIntegerPref(prefs::kProfileAvatarIndex,
280 -1, 280 -1,
281 PrefService::SYNCABLE_PREF); 281 PrefServiceSyncable::SYNCABLE_PREF);
282 prefs->RegisterStringPref(prefs::kProfileName, 282 prefs->RegisterStringPref(prefs::kProfileName,
283 "", 283 "",
284 PrefService::SYNCABLE_PREF); 284 PrefServiceSyncable::SYNCABLE_PREF);
285 prefs->RegisterStringPref(prefs::kHomePage, 285 prefs->RegisterStringPref(prefs::kHomePage,
286 std::string(), 286 std::string(),
287 PrefService::SYNCABLE_PREF); 287 PrefServiceSyncable::SYNCABLE_PREF);
288 #if defined(ENABLE_PRINTING) 288 #if defined(ENABLE_PRINTING)
289 prefs->RegisterBooleanPref(prefs::kPrintingEnabled, 289 prefs->RegisterBooleanPref(prefs::kPrintingEnabled,
290 true, 290 true,
291 PrefService::UNSYNCABLE_PREF); 291 PrefServiceSyncable::UNSYNCABLE_PREF);
292 #endif 292 #endif
293 prefs->RegisterBooleanPref(prefs::kPrintPreviewDisabled, 293 prefs->RegisterBooleanPref(prefs::kPrintPreviewDisabled,
294 #if defined(GOOGLE_CHROME_BUILD) 294 #if defined(GOOGLE_CHROME_BUILD)
295 false, 295 false,
296 #else 296 #else
297 true, 297 true,
298 #endif 298 #endif
299 PrefService::UNSYNCABLE_PREF); 299 PrefServiceSyncable::UNSYNCABLE_PREF);
300 300
301 // Initialize the cache prefs. 301 // Initialize the cache prefs.
302 prefs->RegisterFilePathPref(prefs::kDiskCacheDir, 302 prefs->RegisterFilePathPref(prefs::kDiskCacheDir,
303 FilePath(), 303 FilePath(),
304 PrefService::UNSYNCABLE_PREF); 304 PrefServiceSyncable::UNSYNCABLE_PREF);
305 prefs->RegisterIntegerPref(prefs::kDiskCacheSize, 305 prefs->RegisterIntegerPref(prefs::kDiskCacheSize,
306 0, 306 0,
307 PrefService::UNSYNCABLE_PREF); 307 PrefServiceSyncable::UNSYNCABLE_PREF);
308 prefs->RegisterIntegerPref(prefs::kMediaCacheSize, 308 prefs->RegisterIntegerPref(prefs::kMediaCacheSize,
309 0, 309 0,
310 PrefService::UNSYNCABLE_PREF); 310 PrefServiceSyncable::UNSYNCABLE_PREF);
311 311
312 // Deprecated. Kept around for migration. 312 // Deprecated. Kept around for migration.
313 prefs->RegisterBooleanPref(prefs::kClearSiteDataOnExit, 313 prefs->RegisterBooleanPref(prefs::kClearSiteDataOnExit,
314 false, 314 false,
315 PrefService::SYNCABLE_PREF); 315 PrefServiceSyncable::SYNCABLE_PREF);
316 } 316 }
317 317
318 ProfileImpl::ProfileImpl( 318 ProfileImpl::ProfileImpl(
319 const FilePath& path, 319 const FilePath& path,
320 Delegate* delegate, 320 Delegate* delegate,
321 CreateMode create_mode, 321 CreateMode create_mode,
322 base::SequencedTaskRunner* sequenced_task_runner) 322 base::SequencedTaskRunner* sequenced_task_runner)
323 : path_(path), 323 : path_(path),
324 ALLOW_THIS_IN_INITIALIZER_LIST(io_data_(this)), 324 ALLOW_THIS_IN_INITIALIZER_LIST(io_data_(this)),
325 host_content_settings_map_(NULL), 325 host_content_settings_map_(NULL),
(...skipping 17 matching lines...) Expand all
343 !command_line->HasSwitch(switches::kDisablePreconnect), 343 !command_line->HasSwitch(switches::kDisablePreconnect),
344 g_browser_process->profile_manager() == NULL); 344 g_browser_process->profile_manager() == NULL);
345 345
346 #if defined(ENABLE_CONFIGURATION_POLICY) 346 #if defined(ENABLE_CONFIGURATION_POLICY)
347 // If we are creating the profile synchronously, then we should load the 347 // If we are creating the profile synchronously, then we should load the
348 // policy data immediately. 348 // policy data immediately.
349 bool force_immediate_policy_load = (create_mode == CREATE_MODE_SYNCHRONOUS); 349 bool force_immediate_policy_load = (create_mode == CREATE_MODE_SYNCHRONOUS);
350 350
351 // TODO(atwilson): Change |cloud_policy_manager_| and 351 // TODO(atwilson): Change |cloud_policy_manager_| and
352 // |managed_mode_policy_provider_| to proper ProfileKeyedServices once 352 // |managed_mode_policy_provider_| to proper ProfileKeyedServices once
353 // PrefService is a ProfileKeyedService (policy must be initialized before 353 // PrefServiceSyncable is a ProfileKeyedService (policy must be initialized
354 // PrefService because PrefService depends on policy loading to get overridden 354 // before PrefServiceSyncable because PrefServiceSyncable depends on policy
355 // pref values). 355 // loading to get overridden pref values).
356 #if !defined(OS_CHROMEOS) 356 #if !defined(OS_CHROMEOS)
357 if (command_line->HasSwitch(switches::kLoadCloudPolicyOnSignin)) { 357 if (command_line->HasSwitch(switches::kLoadCloudPolicyOnSignin)) {
358 cloud_policy_manager_ = 358 cloud_policy_manager_ =
359 policy::UserCloudPolicyManagerFactory::CreateForProfile( 359 policy::UserCloudPolicyManagerFactory::CreateForProfile(
360 this, force_immediate_policy_load); 360 this, force_immediate_policy_load);
361 cloud_policy_manager_->Init(); 361 cloud_policy_manager_->Init();
362 } 362 }
363 #endif 363 #endif
364 managed_mode_policy_provider_ = 364 managed_mode_policy_provider_ =
365 policy::ManagedModePolicyProvider::Create(this, 365 policy::ManagedModePolicyProvider::Create(this,
366 sequenced_task_runner, 366 sequenced_task_runner,
367 force_immediate_policy_load); 367 force_immediate_policy_load);
368 managed_mode_policy_provider_->Init(); 368 managed_mode_policy_provider_->Init();
369 policy_service_ = 369 policy_service_ =
370 g_browser_process->browser_policy_connector()->CreatePolicyService(this); 370 g_browser_process->browser_policy_connector()->CreatePolicyService(this);
371 #else 371 #else
372 policy_service_.reset(new policy::PolicyServiceStub()); 372 policy_service_.reset(new policy::PolicyServiceStub());
373 #endif 373 #endif
374 374
375 if (create_mode == CREATE_MODE_ASYNCHRONOUS) { 375 if (create_mode == CREATE_MODE_ASYNCHRONOUS) {
376 prefs_.reset(ChromePrefServiceBuilder().CreateChromePrefs( 376 prefs_.reset(ChromePrefServiceFactory().CreateProfilePrefs(
377 GetPrefFilePath(), 377 GetPrefFilePath(),
378 sequenced_task_runner, 378 sequenced_task_runner,
379 policy_service_.get(), 379 policy_service_.get(),
380 new ExtensionPrefStore( 380 new ExtensionPrefStore(
381 ExtensionPrefValueMapFactory::GetForProfile(this), false), 381 ExtensionPrefValueMapFactory::GetForProfile(this), false),
382 true)); 382 true));
383 // Wait for the notification that prefs has been loaded 383 // Wait for the notification that prefs has been loaded
384 // (successfully or not). Note that we can use base::Unretained 384 // (successfully or not). Note that we can use base::Unretained
385 // because the PrefService is owned by this class and lives on 385 // because the PrefService is owned by this class and lives on
386 // the same thread. 386 // the same thread.
387 prefs_->AddPrefInitObserver(base::Bind(&ProfileImpl::OnPrefsLoaded, 387 prefs_->AddPrefInitObserver(base::Bind(&ProfileImpl::OnPrefsLoaded,
388 base::Unretained(this))); 388 base::Unretained(this)));
389 } else if (create_mode == CREATE_MODE_SYNCHRONOUS) { 389 } else if (create_mode == CREATE_MODE_SYNCHRONOUS) {
390 // Load prefs synchronously. 390 // Load prefs synchronously.
391 prefs_.reset(ChromePrefServiceBuilder().CreateChromePrefs( 391 prefs_.reset(ChromePrefServiceFactory().CreateProfilePrefs(
392 GetPrefFilePath(), 392 GetPrefFilePath(),
393 sequenced_task_runner, 393 sequenced_task_runner,
394 policy_service_.get(), 394 policy_service_.get(),
395 new ExtensionPrefStore( 395 new ExtensionPrefStore(
396 ExtensionPrefValueMapFactory::GetForProfile(this), false), 396 ExtensionPrefValueMapFactory::GetForProfile(this), false),
397 false)); 397 false));
398 OnPrefsLoaded(true); 398 OnPrefsLoaded(true);
399 } else { 399 } else {
400 NOTREACHED(); 400 NOTREACHED();
401 } 401 }
(...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after
767 #else 767 #else
768 return NULL; 768 return NULL;
769 #endif 769 #endif
770 } 770 }
771 771
772 policy::PolicyService* ProfileImpl::GetPolicyService() { 772 policy::PolicyService* ProfileImpl::GetPolicyService() {
773 DCHECK(policy_service_.get()); // Should explicitly be initialized. 773 DCHECK(policy_service_.get()); // Should explicitly be initialized.
774 return policy_service_.get(); 774 return policy_service_.get();
775 } 775 }
776 776
777 PrefService* ProfileImpl::GetPrefs() { 777 PrefServiceSyncable* ProfileImpl::GetPrefs() {
778 DCHECK(prefs_.get()); // Should explicitly be initialized. 778 DCHECK(prefs_.get()); // Should explicitly be initialized.
779 return prefs_.get(); 779 return prefs_.get();
780 } 780 }
781 781
782 PrefService* ProfileImpl::GetOffTheRecordPrefs() { 782 PrefServiceSyncable* ProfileImpl::GetOffTheRecordPrefs() {
783 if (!otr_prefs_.get()) { 783 if (!otr_prefs_.get()) {
784 // The new ExtensionPrefStore is ref_counted and the new PrefService 784 // The new ExtensionPrefStore is ref_counted and the new PrefService
785 // stores a reference so that we do not leak memory here. 785 // stores a reference so that we do not leak memory here.
786 otr_prefs_.reset(GetPrefs()->CreateIncognitoPrefService( 786 otr_prefs_.reset(GetPrefs()->CreateIncognitoPrefService(
787 new ExtensionPrefStore( 787 new ExtensionPrefStore(
788 ExtensionPrefValueMapFactory::GetForProfile(this), true))); 788 ExtensionPrefValueMapFactory::GetForProfile(this), true)));
789 } 789 }
790 return otr_prefs_.get(); 790 return otr_prefs_.get();
791 } 791 }
792 792
(...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after
1154 if (!path.empty()) 1154 if (!path.empty())
1155 *cache_path = path; 1155 *cache_path = path;
1156 *max_size = is_media_context ? prefs_->GetInteger(prefs::kMediaCacheSize) : 1156 *max_size = is_media_context ? prefs_->GetInteger(prefs::kMediaCacheSize) :
1157 prefs_->GetInteger(prefs::kDiskCacheSize); 1157 prefs_->GetInteger(prefs::kDiskCacheSize);
1158 } 1158 }
1159 1159
1160 base::Callback<ChromeURLDataManagerBackend*(void)> 1160 base::Callback<ChromeURLDataManagerBackend*(void)>
1161 ProfileImpl::GetChromeURLDataManagerBackendGetter() const { 1161 ProfileImpl::GetChromeURLDataManagerBackendGetter() const {
1162 return io_data_.GetChromeURLDataManagerBackendGetter(); 1162 return io_data_.GetChromeURLDataManagerBackendGetter();
1163 } 1163 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698