Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| 11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
| 12 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
| 13 #include "base/environment.h" | 13 #include "base/environment.h" |
| 14 #include "base/files/file_path.h" | 14 #include "base/files/file_path.h" |
| 15 #include "base/files/file_util.h" | 15 #include "base/files/file_util.h" |
| 16 #include "base/memory/scoped_ptr.h" | 16 #include "base/memory/scoped_ptr.h" |
| 17 #include "base/memory/weak_ptr.h" | 17 #include "base/memory/weak_ptr.h" |
| 18 #include "base/metrics/histogram_macros.h" | |
| 18 #include "base/path_service.h" | 19 #include "base/path_service.h" |
| 19 #include "base/prefs/json_pref_store.h" | 20 #include "base/prefs/json_pref_store.h" |
| 20 #include "base/prefs/scoped_user_pref_update.h" | 21 #include "base/prefs/scoped_user_pref_update.h" |
| 21 #include "base/strings/string_number_conversions.h" | 22 #include "base/strings/string_number_conversions.h" |
| 22 #include "base/strings/string_util.h" | 23 #include "base/strings/string_util.h" |
| 23 #include "base/strings/stringprintf.h" | 24 #include "base/strings/stringprintf.h" |
| 24 #include "base/strings/utf_string_conversions.h" | 25 #include "base/strings/utf_string_conversions.h" |
| 25 #include "base/synchronization/waitable_event.h" | 26 #include "base/synchronization/waitable_event.h" |
| 26 #include "base/threading/sequenced_worker_pool.h" | 27 #include "base/threading/sequenced_worker_pool.h" |
| 27 #include "base/trace_event/trace_event.h" | 28 #include "base/trace_event/trace_event.h" |
| (...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 259 return NULL; | 260 return NULL; |
| 260 #endif | 261 #endif |
| 261 } | 262 } |
| 262 | 263 |
| 263 } // namespace | 264 } // namespace |
| 264 | 265 |
| 265 // static | 266 // static |
| 266 Profile* Profile::CreateProfile(const base::FilePath& path, | 267 Profile* Profile::CreateProfile(const base::FilePath& path, |
| 267 Delegate* delegate, | 268 Delegate* delegate, |
| 268 CreateMode create_mode) { | 269 CreateMode create_mode) { |
| 269 TRACE_EVENT_BEGIN1("browser", | 270 TRACE_EVENT1("browser,startup", |
| 270 "Profile::CreateProfile", | 271 "Profile::CreateProfile", |
| 271 "profile_path", | 272 "profile_path", |
| 272 path.value().c_str()); | 273 path.MaybeAsASCII()); |
| 273 | 274 |
| 274 // Get sequenced task runner for making sure that file operations of | 275 // Get sequenced task runner for making sure that file operations of |
| 275 // this profile (defined by |path|) are executed in expected order | 276 // this profile (defined by |path|) are executed in expected order |
| 276 // (what was previously assured by the FILE thread). | 277 // (what was previously assured by the FILE thread). |
| 277 scoped_refptr<base::SequencedTaskRunner> sequenced_task_runner = | 278 scoped_refptr<base::SequencedTaskRunner> sequenced_task_runner = |
| 278 JsonPrefStore::GetTaskRunnerForFile(path, | 279 JsonPrefStore::GetTaskRunnerForFile(path, |
| 279 BrowserThread::GetBlockingPool()); | 280 BrowserThread::GetBlockingPool()); |
| 280 if (create_mode == CREATE_MODE_ASYNCHRONOUS) { | 281 if (create_mode == CREATE_MODE_ASYNCHRONOUS) { |
| 281 DCHECK(delegate); | 282 DCHECK(delegate); |
| 282 CreateProfileDirectory(sequenced_task_runner.get(), path); | 283 CreateProfileDirectory(sequenced_task_runner.get(), path); |
| 283 } else if (create_mode == CREATE_MODE_SYNCHRONOUS) { | 284 } else if (create_mode == CREATE_MODE_SYNCHRONOUS) { |
| 284 if (!base::PathExists(path)) { | 285 if (!base::PathExists(path)) { |
| 285 // TODO(tc): http://b/1094718 Bad things happen if we can't write to the | 286 // TODO(rogerta): http://crbug/160553 - Bad things happen if we can't writ e to |
|
Alexei Svitkine (slow)
2015/02/19 14:44:59
Nit: Wrapping.
rkaplow
2015/02/19 15:42:51
Done.
| |
| 286 // profile directory. We should eventually be able to run in this | 287 // the profile directory. We should eventually be able to run in this |
| 287 // situation. | 288 // situation. |
| 288 if (!base::CreateDirectory(path)) | 289 if (!base::CreateDirectory(path)) |
| 289 return NULL; | 290 return NULL; |
| 290 } | 291 } |
| 291 } else { | 292 } else { |
| 292 NOTREACHED(); | 293 NOTREACHED(); |
| 293 } | 294 } |
| 294 | 295 |
| 295 return new ProfileImpl( | 296 return new ProfileImpl( |
| 296 path, delegate, create_mode, sequenced_task_runner.get()); | 297 path, delegate, create_mode, sequenced_task_runner.get()); |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 404 CreateMode create_mode, | 405 CreateMode create_mode, |
| 405 base::SequencedTaskRunner* sequenced_task_runner) | 406 base::SequencedTaskRunner* sequenced_task_runner) |
| 406 : path_(path), | 407 : path_(path), |
| 407 pref_registry_(new user_prefs::PrefRegistrySyncable), | 408 pref_registry_(new user_prefs::PrefRegistrySyncable), |
| 408 io_data_(this), | 409 io_data_(this), |
| 409 host_content_settings_map_(NULL), | 410 host_content_settings_map_(NULL), |
| 410 last_session_exit_type_(EXIT_NORMAL), | 411 last_session_exit_type_(EXIT_NORMAL), |
| 411 start_time_(Time::Now()), | 412 start_time_(Time::Now()), |
| 412 delegate_(delegate), | 413 delegate_(delegate), |
| 413 predictor_(NULL) { | 414 predictor_(NULL) { |
| 414 TRACE_EVENT0("browser", "ProfileImpl::ctor") | 415 TRACE_EVENT0("browser,startup", "ProfileImpl::ctor") |
| 415 DCHECK(!path.empty()) << "Using an empty path will attempt to write " << | 416 DCHECK(!path.empty()) << "Using an empty path will attempt to write " << |
| 416 "profile files to the root directory!"; | 417 "profile files to the root directory!"; |
| 417 | 418 |
| 418 #if defined(ENABLE_SESSION_SERVICE) | 419 #if defined(ENABLE_SESSION_SERVICE) |
| 419 create_session_service_timer_.Start(FROM_HERE, | 420 create_session_service_timer_.Start(FROM_HERE, |
| 420 TimeDelta::FromMilliseconds(kCreateSessionServiceDelayMS), this, | 421 TimeDelta::FromMilliseconds(kCreateSessionServiceDelayMS), this, |
| 421 &ProfileImpl::EnsureSessionServiceCreated); | 422 &ProfileImpl::EnsureSessionServiceCreated); |
| 422 #endif | 423 #endif |
| 423 | 424 |
| 424 set_is_guest_profile(path == ProfileManager::GetGuestProfilePath()); | 425 set_is_guest_profile(path == ProfileManager::GetGuestProfilePath()); |
| (...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 659 content::BrowserContext::GetDefaultStoragePartition(this)-> | 660 content::BrowserContext::GetDefaultStoragePartition(this)-> |
| 660 GetDOMStorageContext()->SetSaveSessionStorageOnDisk(); | 661 GetDOMStorageContext()->SetSaveSessionStorageOnDisk(); |
| 661 | 662 |
| 662 // TODO(wjmaclean): Remove this. crbug.com/420643 | 663 // TODO(wjmaclean): Remove this. crbug.com/420643 |
| 663 chrome::MigrateProfileZoomLevelPrefs(this); | 664 chrome::MigrateProfileZoomLevelPrefs(this); |
| 664 | 665 |
| 665 // The DomDistillerViewerSource is not a normal WebUI so it must be registered | 666 // The DomDistillerViewerSource is not a normal WebUI so it must be registered |
| 666 // as a URLDataSource early. | 667 // as a URLDataSource early. |
| 667 RegisterDomDistillerViewerSource(this); | 668 RegisterDomDistillerViewerSource(this); |
| 668 | 669 |
| 669 // Creation has been finished. | |
| 670 TRACE_EVENT_END1("browser", | |
| 671 "Profile::CreateProfile", | |
| 672 "profile_path", | |
| 673 path_.value().c_str()); | |
| 674 | |
| 675 #if defined(OS_CHROMEOS) | 670 #if defined(OS_CHROMEOS) |
| 676 if (chromeos::UserSessionManager::GetInstance() | 671 if (chromeos::UserSessionManager::GetInstance() |
| 677 ->RestartToApplyPerSessionFlagsIfNeed(this, true)) { | 672 ->RestartToApplyPerSessionFlagsIfNeed(this, true)) { |
| 678 return; | 673 return; |
| 679 } | 674 } |
| 680 #endif | 675 #endif |
| 681 | 676 |
| 682 if (delegate_) { | 677 if (delegate_) { |
| 683 TRACE_EVENT0("browser", "ProfileImpl::DoFileInit:DelegateOnProfileCreated") | 678 TRACE_EVENT0("browser", "ProfileImpl::DoFileInit:DelegateOnProfileCreated") |
| 684 delegate_->OnProfileCreated(this, true, IsNewProfile()); | 679 delegate_->OnProfileCreated(this, true, IsNewProfile()); |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 841 extension_special_storage_policy_ = new ExtensionSpecialStoragePolicy( | 836 extension_special_storage_policy_ = new ExtensionSpecialStoragePolicy( |
| 842 CookieSettings::Factory::GetForProfile(this).get()); | 837 CookieSettings::Factory::GetForProfile(this).get()); |
| 843 } | 838 } |
| 844 return extension_special_storage_policy_.get(); | 839 return extension_special_storage_policy_.get(); |
| 845 #else | 840 #else |
| 846 return NULL; | 841 return NULL; |
| 847 #endif | 842 #endif |
| 848 } | 843 } |
| 849 | 844 |
| 850 void ProfileImpl::OnPrefsLoaded(bool success) { | 845 void ProfileImpl::OnPrefsLoaded(bool success) { |
| 851 TRACE_EVENT0("browser", "ProfileImpl::OnPrefsLoaded") | 846 TRACE_EVENT0("browser", "ProfileImpl::OnPrefsLoaded"); |
| 847 SCOPED_UMA_HISTOGRAM_TIMER("Profile.OnPrefsLoadedTime"); | |
| 852 if (!success) { | 848 if (!success) { |
| 853 if (delegate_) | 849 if (delegate_) |
| 854 delegate_->OnProfileCreated(this, false, false); | 850 delegate_->OnProfileCreated(this, false, false); |
| 855 return; | 851 return; |
| 856 } | 852 } |
| 857 | 853 |
| 858 // TODO(mirandac): remove migration code after 6 months (crbug.com/69995). | 854 // TODO(mirandac): remove migration code after 6 months (crbug.com/69995). |
| 859 if (g_browser_process->local_state()) | 855 if (g_browser_process->local_state()) |
| 860 chrome::MigrateBrowserPrefs(this, g_browser_process->local_state()); | 856 chrome::MigrateBrowserPrefs(this, g_browser_process->local_state()); |
| 861 // TODO(ivankr): remove cleanup code eventually (crbug.com/165672). | 857 // TODO(ivankr): remove cleanup code eventually (crbug.com/165672). |
| (...skipping 461 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1323 ProfileImpl::CreateDomainReliabilityMonitor(PrefService* local_state) { | 1319 ProfileImpl::CreateDomainReliabilityMonitor(PrefService* local_state) { |
| 1324 domain_reliability::DomainReliabilityService* service = | 1320 domain_reliability::DomainReliabilityService* service = |
| 1325 domain_reliability::DomainReliabilityServiceFactory::GetInstance()-> | 1321 domain_reliability::DomainReliabilityServiceFactory::GetInstance()-> |
| 1326 GetForBrowserContext(this); | 1322 GetForBrowserContext(this); |
| 1327 if (!service) | 1323 if (!service) |
| 1328 return scoped_ptr<domain_reliability::DomainReliabilityMonitor>(); | 1324 return scoped_ptr<domain_reliability::DomainReliabilityMonitor>(); |
| 1329 | 1325 |
| 1330 return service->CreateMonitor( | 1326 return service->CreateMonitor( |
| 1331 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO)); | 1327 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO)); |
| 1332 } | 1328 } |
| OLD | NEW |