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

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

Issue 14137032: Create profile .ico file on profile creation (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rework, set pref through callback Created 7 years, 6 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
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 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
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
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)
742 if (prefs_->GetInteger(prefs::kProfileIconVersion) <
Alexei Svitkine (slow) 2013/06/05 14:06:03 I would prefer if you refactor this into a helper
calamity 2013/06/07 04:26:26 Done.
743 kCurrentProfileIconVersion) {
744 // Ensure the profile's icon file has been created.
745 ProfileShortcutManager* profile_shortcut_manager =
746 g_browser_process->profile_manager()->profile_shortcut_manager();
747 if (profile_shortcut_manager) {
748 profile_shortcut_manager->CreateProfileIcon(
749 GetPath(),
750 base::Bind(&ProfileImpl::OnProfileIconCreateSuccess,
751 weak_ptr_factory_.GetWeakPtr()));
752 }
753 }
754 #endif
736 755
737 BrowserContextDependencyManager::GetInstance()->CreateBrowserContextServices( 756 BrowserContextDependencyManager::GetInstance()->CreateBrowserContextServices(
738 this, false); 757 this, false);
739 758
740 DCHECK(!net_pref_observer_); 759 DCHECK(!net_pref_observer_);
741 net_pref_observer_.reset(new NetPrefObserver( 760 net_pref_observer_.reset(new NetPrefObserver(
742 prefs_.get(), 761 prefs_.get(),
743 prerender::PrerenderManagerFactory::GetForProfile(this), 762 prerender::PrerenderManagerFactory::GetForProfile(this),
744 predictor_)); 763 predictor_));
745 764
746 ChromeVersionService::OnProfileLoaded(prefs_.get(), IsNewProfile()); 765 ChromeVersionService::OnProfileLoaded(prefs_.get(), IsNewProfile());
747 DoFinalInit(); 766 DoFinalInit();
748 } 767 }
749 768
769 void ProfileImpl::OnProfileIconCreateSuccess() {
770 prefs_->SetInteger(prefs::kProfileIconVersion, kCurrentProfileIconVersion);
771 }
772
750 bool ProfileImpl::WasCreatedByVersionOrLater(const std::string& version) { 773 bool ProfileImpl::WasCreatedByVersionOrLater(const std::string& version) {
751 Version profile_version(ChromeVersionService::GetVersion(prefs_.get())); 774 Version profile_version(ChromeVersionService::GetVersion(prefs_.get()));
752 Version arg_version(version); 775 Version arg_version(version);
753 return (profile_version.CompareTo(arg_version) >= 0); 776 return (profile_version.CompareTo(arg_version) >= 0);
754 } 777 }
755 778
756 void ProfileImpl::SetExitType(ExitType exit_type) { 779 void ProfileImpl::SetExitType(ExitType exit_type) {
757 if (!prefs_) 780 if (!prefs_)
758 return; 781 return;
759 ExitType current_exit_type = SessionTypePrefValueToExitType( 782 ExitType current_exit_type = SessionTypePrefValueToExitType(
(...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after
1137 base::FilePath* cache_path, 1160 base::FilePath* cache_path,
1138 int* max_size) { 1161 int* max_size) {
1139 DCHECK(cache_path); 1162 DCHECK(cache_path);
1140 DCHECK(max_size); 1163 DCHECK(max_size);
1141 base::FilePath path(prefs_->GetFilePath(prefs::kDiskCacheDir)); 1164 base::FilePath path(prefs_->GetFilePath(prefs::kDiskCacheDir));
1142 if (!path.empty()) 1165 if (!path.empty())
1143 *cache_path = path; 1166 *cache_path = path;
1144 *max_size = is_media_context ? prefs_->GetInteger(prefs::kMediaCacheSize) : 1167 *max_size = is_media_context ? prefs_->GetInteger(prefs::kMediaCacheSize) :
1145 prefs_->GetInteger(prefs::kDiskCacheSize); 1168 prefs_->GetInteger(prefs::kDiskCacheSize);
1146 } 1169 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698