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 "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 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 132 // Make sure that the ProfileImpl doesn't grow. We're currently trying to drive | 132 // Make sure that the ProfileImpl doesn't grow. We're currently trying to drive |
| 133 // the number of services that are included in ProfileImpl (instead of using | 133 // the number of services that are included in ProfileImpl (instead of using |
| 134 // BrowserContextKeyedServiceFactory) to zero. | 134 // BrowserContextKeyedServiceFactory) to zero. |
| 135 // | 135 // |
| 136 // If you don't know about this effort, please read: | 136 // If you don't know about this effort, please read: |
| 137 // https://sites.google.com/a/chromium.org/dev/developers/design-documents/pro file-architecture | 137 // https://sites.google.com/a/chromium.org/dev/developers/design-documents/pro file-architecture |
| 138 // | 138 // |
| 139 // REVIEWERS: Do not let anyone increment this. We need to drive the number of | 139 // REVIEWERS: Do not let anyone increment this. We need to drive the number of |
| 140 // raw accessed services down to zero. DO NOT LET PEOPLE REGRESS THIS UNLESS | 140 // raw accessed services down to zero. DO NOT LET PEOPLE REGRESS THIS UNLESS |
| 141 // THE PATCH ITSELF IS MAKING PROGRESS ON PKSF REFACTORING. | 141 // THE PATCH ITSELF IS MAKING PROGRESS ON PKSF REFACTORING. |
| 142 COMPILE_ASSERT(sizeof(ProfileImpl) <= 744u, profile_impl_size_unexpected); | 142 COMPILE_ASSERT(sizeof(ProfileImpl) <= 744u, profile_impl_size_unexpected); |
|
sail
2013/06/14 17:15:39
weak_ptr_factory_ will trigger this assert
| |
| 143 #endif | 143 #endif |
| 144 | 144 |
| 145 #if defined(ENABLE_SESSION_SERVICE) | 145 #if defined(ENABLE_SESSION_SERVICE) |
| 146 // Delay, in milliseconds, before we explicitly create the SessionService. | 146 // Delay, in milliseconds, before we explicitly create the SessionService. |
| 147 static const int kCreateSessionServiceDelayMS = 500; | 147 static const int kCreateSessionServiceDelayMS = 500; |
| 148 #endif | 148 #endif |
| 149 | 149 |
| 150 // Text content of README file created in each profile directory. Both %s | 150 // Text content of README file created in each profile directory. Both %s |
| 151 // placeholders must contain the product name. This is not localizable and hence | 151 // placeholders must contain the product name. This is not localizable and hence |
| 152 // not in resources. | 152 // not in resources. |
| 153 static const char kReadmeText[] = | 153 static const char kReadmeText[] = |
| 154 "%s settings and storage represent user-selected preferences and " | 154 "%s settings and storage represent user-selected preferences and " |
| 155 "information and MUST not be extracted, overwritten or modified except " | 155 "information and MUST not be extracted, overwritten or modified except " |
| 156 "through %s defined APIs."; | 156 "through %s defined APIs."; |
| 157 | 157 |
| 158 // Value written to prefs for EXIT_CRASHED and EXIT_SESSION_ENDED. | 158 // Value written to prefs for EXIT_CRASHED and EXIT_SESSION_ENDED. |
| 159 const char* const kPrefExitTypeCrashed = "Crashed"; | 159 const char* const kPrefExitTypeCrashed = "Crashed"; |
| 160 const char* const kPrefExitTypeSessionEnded = "SessionEnded"; | 160 const char* const kPrefExitTypeSessionEnded = "SessionEnded"; |
| 161 | 161 |
| 162 #if defined(OS_WIN) | |
| 163 const int kCurrentProfileIconVersion = 1; | |
| 164 #endif | |
| 165 | |
| 162 // Helper method needed because PostTask cannot currently take a Callback | 166 // Helper method needed because PostTask cannot currently take a Callback |
| 163 // function with non-void return type. | 167 // function with non-void return type. |
| 164 void CreateDirectoryAndSignal(const base::FilePath& path, | 168 void CreateDirectoryAndSignal(const base::FilePath& path, |
| 165 base::WaitableEvent* done_creating) { | 169 base::WaitableEvent* done_creating) { |
| 166 DVLOG(1) << "Creating directory " << path.value(); | 170 DVLOG(1) << "Creating directory " << path.value(); |
| 167 file_util::CreateDirectory(path); | 171 file_util::CreateDirectory(path); |
| 168 done_creating->Signal(); | 172 done_creating->Signal(); |
| 169 } | 173 } |
| 170 | 174 |
| 171 // Task that blocks the FILE thread until CreateDirectoryAndSignal() finishes on | 175 // Task that blocks the FILE thread until CreateDirectoryAndSignal() finishes on |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 347 base::SequencedTaskRunner* sequenced_task_runner) | 351 base::SequencedTaskRunner* sequenced_task_runner) |
| 348 : zoom_callback_(base::Bind(&ProfileImpl::OnZoomLevelChanged, | 352 : zoom_callback_(base::Bind(&ProfileImpl::OnZoomLevelChanged, |
| 349 base::Unretained(this))), | 353 base::Unretained(this))), |
| 350 path_(path), | 354 path_(path), |
| 351 pref_registry_(new user_prefs::PrefRegistrySyncable), | 355 pref_registry_(new user_prefs::PrefRegistrySyncable), |
| 352 io_data_(this), | 356 io_data_(this), |
| 353 host_content_settings_map_(NULL), | 357 host_content_settings_map_(NULL), |
| 354 last_session_exit_type_(EXIT_NORMAL), | 358 last_session_exit_type_(EXIT_NORMAL), |
| 355 start_time_(Time::Now()), | 359 start_time_(Time::Now()), |
| 356 delegate_(delegate), | 360 delegate_(delegate), |
| 357 predictor_(NULL) { | 361 predictor_(NULL), |
| 362 weak_ptr_factory_(this) { | |
| 358 DCHECK(!path.empty()) << "Using an empty path will attempt to write " << | 363 DCHECK(!path.empty()) << "Using an empty path will attempt to write " << |
| 359 "profile files to the root directory!"; | 364 "profile files to the root directory!"; |
| 360 | 365 |
| 361 #if defined(ENABLE_SESSION_SERVICE) | 366 #if defined(ENABLE_SESSION_SERVICE) |
| 362 create_session_service_timer_.Start(FROM_HERE, | 367 create_session_service_timer_.Start(FROM_HERE, |
| 363 TimeDelta::FromMilliseconds(kCreateSessionServiceDelayMS), this, | 368 TimeDelta::FromMilliseconds(kCreateSessionServiceDelayMS), this, |
| 364 &ProfileImpl::EnsureSessionServiceCreated); | 369 &ProfileImpl::EnsureSessionServiceCreated); |
| 365 #endif | 370 #endif |
| 366 | 371 |
| 367 // Determine if prefetch is enabled for this profile. | 372 // Determine if prefetch is enabled for this profile. |
| (...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 726 EXIT_NORMAL : EXIT_CRASHED; | 731 EXIT_NORMAL : EXIT_CRASHED; |
| 727 } else { | 732 } else { |
| 728 last_session_exit_type_ = | 733 last_session_exit_type_ = |
| 729 SessionTypePrefValueToExitType(exit_type_pref_value); | 734 SessionTypePrefValueToExitType(exit_type_pref_value); |
| 730 } | 735 } |
| 731 // Mark the session as open. | 736 // Mark the session as open. |
| 732 prefs_->SetString(prefs::kSessionExitType, kPrefExitTypeCrashed); | 737 prefs_->SetString(prefs::kSessionExitType, kPrefExitTypeCrashed); |
| 733 // Force this to true in case we fallback and use it. | 738 // Force this to true in case we fallback and use it. |
| 734 // TODO(sky): remove this in a couple of releases (m28ish). | 739 // TODO(sky): remove this in a couple of releases (m28ish). |
| 735 prefs_->SetBoolean(prefs::kSessionExitedCleanly, true); | 740 prefs_->SetBoolean(prefs::kSessionExitedCleanly, true); |
| 741 #if defined(OS_WIN) | |
|
sail
2013/06/14 17:15:39
The profile icon code doesn't really belong in thi
calamity
2013/06/17 07:29:30
Any suggestions about where to put it then?
I had
sail
2013/06/17 19:51:03
ProfileManager is not correct either.
How about l
calamity
2013/06/18 04:41:30
Listened for notification from profile_shortcut_ma
| |
| 742 UpdateProfileIconIfNecessary(); | |
| 743 #endif | |
| 736 | 744 |
| 737 BrowserContextDependencyManager::GetInstance()->CreateBrowserContextServices( | 745 BrowserContextDependencyManager::GetInstance()->CreateBrowserContextServices( |
| 738 this, false); | 746 this, false); |
| 739 | 747 |
| 740 DCHECK(!net_pref_observer_); | 748 DCHECK(!net_pref_observer_); |
| 741 net_pref_observer_.reset(new NetPrefObserver( | 749 net_pref_observer_.reset(new NetPrefObserver( |
| 742 prefs_.get(), | 750 prefs_.get(), |
| 743 prerender::PrerenderManagerFactory::GetForProfile(this), | 751 prerender::PrerenderManagerFactory::GetForProfile(this), |
| 744 predictor_)); | 752 predictor_)); |
| 745 | 753 |
| 746 ChromeVersionService::OnProfileLoaded(prefs_.get(), IsNewProfile()); | 754 ChromeVersionService::OnProfileLoaded(prefs_.get(), IsNewProfile()); |
| 747 DoFinalInit(); | 755 DoFinalInit(); |
| 748 } | 756 } |
| 749 | 757 |
| 758 void ProfileImpl::UpdateProfileIconIfNecessary() { | |
| 759 if (prefs_->GetInteger(prefs::kProfileIconVersion) < | |
| 760 kCurrentProfileIconVersion) { | |
| 761 // Ensure the profile's icon file has been created. | |
| 762 ProfileShortcutManager* profile_shortcut_manager = | |
| 763 g_browser_process->profile_manager()->profile_shortcut_manager(); | |
| 764 if (profile_shortcut_manager) { | |
| 765 profile_shortcut_manager->CreateOrUpdateProfileIcon( | |
| 766 GetPath(), | |
| 767 base::Bind(&ProfileImpl::OnProfileIconCreateSuccess, | |
| 768 weak_ptr_factory_.GetWeakPtr())); | |
| 769 } | |
| 770 } | |
| 771 } | |
| 772 | |
| 773 void ProfileImpl::OnProfileIconCreateSuccess() { | |
| 774 prefs_->SetInteger(prefs::kProfileIconVersion, kCurrentProfileIconVersion); | |
| 775 } | |
| 776 | |
| 750 bool ProfileImpl::WasCreatedByVersionOrLater(const std::string& version) { | 777 bool ProfileImpl::WasCreatedByVersionOrLater(const std::string& version) { |
| 751 Version profile_version(ChromeVersionService::GetVersion(prefs_.get())); | 778 Version profile_version(ChromeVersionService::GetVersion(prefs_.get())); |
| 752 Version arg_version(version); | 779 Version arg_version(version); |
| 753 return (profile_version.CompareTo(arg_version) >= 0); | 780 return (profile_version.CompareTo(arg_version) >= 0); |
| 754 } | 781 } |
| 755 | 782 |
| 756 void ProfileImpl::SetExitType(ExitType exit_type) { | 783 void ProfileImpl::SetExitType(ExitType exit_type) { |
| 757 if (!prefs_) | 784 if (!prefs_) |
| 758 return; | 785 return; |
| 759 ExitType current_exit_type = SessionTypePrefValueToExitType( | 786 ExitType current_exit_type = SessionTypePrefValueToExitType( |
| (...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1137 base::FilePath* cache_path, | 1164 base::FilePath* cache_path, |
| 1138 int* max_size) { | 1165 int* max_size) { |
| 1139 DCHECK(cache_path); | 1166 DCHECK(cache_path); |
| 1140 DCHECK(max_size); | 1167 DCHECK(max_size); |
| 1141 base::FilePath path(prefs_->GetFilePath(prefs::kDiskCacheDir)); | 1168 base::FilePath path(prefs_->GetFilePath(prefs::kDiskCacheDir)); |
| 1142 if (!path.empty()) | 1169 if (!path.empty()) |
| 1143 *cache_path = path; | 1170 *cache_path = path; |
| 1144 *max_size = is_media_context ? prefs_->GetInteger(prefs::kMediaCacheSize) : | 1171 *max_size = is_media_context ? prefs_->GetInteger(prefs::kMediaCacheSize) : |
| 1145 prefs_->GetInteger(prefs::kDiskCacheSize); | 1172 prefs_->GetInteger(prefs::kDiskCacheSize); |
| 1146 } | 1173 } |
| OLD | NEW |