| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
| 9 #include "base/environment.h" | 9 #include "base/environment.h" |
| 10 #include "base/file_path.h" | 10 #include "base/file_path.h" |
| 11 #include "base/file_util.h" | 11 #include "base/file_util.h" |
| 12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
| 13 #include "base/metrics/histogram.h" | |
| 14 #include "base/path_service.h" | 13 #include "base/path_service.h" |
| 15 #include "base/string_number_conversions.h" | 14 #include "base/string_number_conversions.h" |
| 16 #include "base/string_util.h" | 15 #include "base/string_util.h" |
| 17 #include "base/utf_string_conversions.h" | 16 #include "base/utf_string_conversions.h" |
| 18 #include "chrome/browser/autocomplete/autocomplete_classifier.h" | 17 #include "chrome/browser/autocomplete/autocomplete_classifier.h" |
| 19 #include "chrome/browser/autofill/personal_data_manager.h" | 18 #include "chrome/browser/autofill/personal_data_manager.h" |
| 20 #include "chrome/browser/background/background_contents_service_factory.h" | 19 #include "chrome/browser/background/background_contents_service_factory.h" |
| 21 #include "chrome/browser/background/background_mode_manager.h" | 20 #include "chrome/browser/background/background_mode_manager.h" |
| 22 #include "chrome/browser/bookmarks/bookmark_model.h" | 21 #include "chrome/browser/bookmarks/bookmark_model.h" |
| 23 #include "chrome/browser/browser_process.h" | 22 #include "chrome/browser/browser_process.h" |
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 212 } | 211 } |
| 213 | 212 |
| 214 FilePath GetCachePath(const FilePath& base) { | 213 FilePath GetCachePath(const FilePath& base) { |
| 215 return base.Append(chrome::kCacheDirname); | 214 return base.Append(chrome::kCacheDirname); |
| 216 } | 215 } |
| 217 | 216 |
| 218 FilePath GetMediaCachePath(const FilePath& base) { | 217 FilePath GetMediaCachePath(const FilePath& base) { |
| 219 return base.Append(chrome::kMediaCacheDirname); | 218 return base.Append(chrome::kMediaCacheDirname); |
| 220 } | 219 } |
| 221 | 220 |
| 222 // Simple task to log the size of the current profile. | |
| 223 class ProfileSizeTask : public Task { | |
| 224 public: | |
| 225 explicit ProfileSizeTask(const FilePath& path) : path_(path) {} | |
| 226 virtual ~ProfileSizeTask() {} | |
| 227 | |
| 228 virtual void Run(); | |
| 229 private: | |
| 230 FilePath path_; | |
| 231 }; | |
| 232 | |
| 233 void ProfileSizeTask::Run() { | |
| 234 int64 size = file_util::ComputeFilesSize(path_, FILE_PATH_LITERAL("*")); | |
| 235 int size_MB = static_cast<int>(size / (1024 * 1024)); | |
| 236 UMA_HISTOGRAM_COUNTS_10000("Profile.TotalSize", size_MB); | |
| 237 | |
| 238 size = file_util::ComputeFilesSize(path_, FILE_PATH_LITERAL("History")); | |
| 239 size_MB = static_cast<int>(size / (1024 * 1024)); | |
| 240 UMA_HISTOGRAM_COUNTS_10000("Profile.HistorySize", size_MB); | |
| 241 | |
| 242 size = file_util::ComputeFilesSize(path_, FILE_PATH_LITERAL("History*")); | |
| 243 size_MB = static_cast<int>(size / (1024 * 1024)); | |
| 244 UMA_HISTOGRAM_COUNTS_10000("Profile.TotalHistorySize", size_MB); | |
| 245 | |
| 246 size = file_util::ComputeFilesSize(path_, FILE_PATH_LITERAL("Cookies")); | |
| 247 size_MB = static_cast<int>(size / (1024 * 1024)); | |
| 248 UMA_HISTOGRAM_COUNTS_10000("Profile.CookiesSize", size_MB); | |
| 249 | |
| 250 size = file_util::ComputeFilesSize(path_, FILE_PATH_LITERAL("Bookmarks")); | |
| 251 size_MB = static_cast<int>(size / (1024 * 1024)); | |
| 252 UMA_HISTOGRAM_COUNTS_10000("Profile.BookmarksSize", size_MB); | |
| 253 | |
| 254 size = file_util::ComputeFilesSize(path_, FILE_PATH_LITERAL("Favicons")); | |
| 255 size_MB = static_cast<int>(size / (1024 * 1024)); | |
| 256 UMA_HISTOGRAM_COUNTS_10000("Profile.FaviconsSize", size_MB); | |
| 257 | |
| 258 size = file_util::ComputeFilesSize(path_, FILE_PATH_LITERAL("Top Sites")); | |
| 259 size_MB = static_cast<int>(size / (1024 * 1024)); | |
| 260 UMA_HISTOGRAM_COUNTS_10000("Profile.TopSitesSize", size_MB); | |
| 261 | |
| 262 size = file_util::ComputeFilesSize(path_, FILE_PATH_LITERAL("Visited Links")); | |
| 263 size_MB = static_cast<int>(size / (1024 * 1024)); | |
| 264 UMA_HISTOGRAM_COUNTS_10000("Profile.VisitedLinksSize", size_MB); | |
| 265 | |
| 266 size = file_util::ComputeFilesSize(path_, FILE_PATH_LITERAL("Web Data")); | |
| 267 size_MB = static_cast<int>(size / (1024 * 1024)); | |
| 268 UMA_HISTOGRAM_COUNTS_10000("Profile.WebDataSize", size_MB); | |
| 269 | |
| 270 size = file_util::ComputeFilesSize(path_, FILE_PATH_LITERAL("Extension*")); | |
| 271 size_MB = static_cast<int>(size / (1024 * 1024)); | |
| 272 UMA_HISTOGRAM_COUNTS_10000("Profile.ExtensionSize", size_MB); | |
| 273 } | |
| 274 | |
| 275 } // namespace | 221 } // namespace |
| 276 | 222 |
| 277 // static | 223 // static |
| 278 Profile* Profile::CreateProfile(const FilePath& path) { | 224 Profile* Profile::CreateProfile(const FilePath& path) { |
| 279 if (!file_util::PathExists(path)) { | 225 if (!file_util::PathExists(path)) { |
| 280 // TODO(tc): http://b/1094718 Bad things happen if we can't write to the | 226 // TODO(tc): http://b/1094718 Bad things happen if we can't write to the |
| 281 // profile directory. We should eventually be able to run in this | 227 // profile directory. We should eventually be able to run in this |
| 282 // situation. | 228 // situation. |
| 283 if (!file_util::CreateDirectory(path)) | 229 if (!file_util::CreateDirectory(path)) |
| 284 return NULL; | 230 return NULL; |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 430 | 376 |
| 431 clear_local_state_on_exit_ = prefs->GetBoolean(prefs::kClearSiteDataOnExit); | 377 clear_local_state_on_exit_ = prefs->GetBoolean(prefs::kClearSiteDataOnExit); |
| 432 if (clear_local_state_on_exit_) { | 378 if (clear_local_state_on_exit_) { |
| 433 UserMetrics::RecordAction( | 379 UserMetrics::RecordAction( |
| 434 UserMetricsAction("ClearSiteDataOnExitEnabled")); | 380 UserMetricsAction("ClearSiteDataOnExitEnabled")); |
| 435 } else { | 381 } else { |
| 436 UserMetrics::RecordAction( | 382 UserMetrics::RecordAction( |
| 437 UserMetricsAction("ClearSiteDataOnExitDisabled")); | 383 UserMetricsAction("ClearSiteDataOnExitDisabled")); |
| 438 } | 384 } |
| 439 | 385 |
| 440 // Log the profile size after a reasonable startup delay. | |
| 441 BrowserThread::PostDelayedTask(BrowserThread::FILE, FROM_HERE, | |
| 442 new ProfileSizeTask(path_), 112000); | |
| 443 | |
| 444 InstantController::RecordMetrics(this); | 386 InstantController::RecordMetrics(this); |
| 445 | 387 |
| 446 // Instantiates Metrics object for spellchecking for use. | 388 // Instantiates Metrics object for spellchecking for use. |
| 447 if (g_browser_process->metrics_service() && | 389 if (g_browser_process->metrics_service() && |
| 448 g_browser_process->metrics_service()->recording_active()) | 390 g_browser_process->metrics_service()->recording_active()) |
| 449 GetSpellCheckProfile()->StartRecordingMetrics( | 391 GetSpellCheckProfile()->StartRecordingMetrics( |
| 450 GetPrefs()->GetBoolean(prefs::kEnableSpellCheck)); | 392 GetPrefs()->GetBoolean(prefs::kEnableSpellCheck)); |
| 451 | 393 |
| 452 FilePath cookie_path = GetPath(); | 394 FilePath cookie_path = GetPath(); |
| 453 cookie_path = cookie_path.Append(chrome::kCookieFilename); | 395 cookie_path = cookie_path.Append(chrome::kCookieFilename); |
| (...skipping 1306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1760 SpellCheckProfile* ProfileImpl::GetSpellCheckProfile() { | 1702 SpellCheckProfile* ProfileImpl::GetSpellCheckProfile() { |
| 1761 if (!spellcheck_profile_.get()) | 1703 if (!spellcheck_profile_.get()) |
| 1762 spellcheck_profile_.reset(new SpellCheckProfile()); | 1704 spellcheck_profile_.reset(new SpellCheckProfile()); |
| 1763 return spellcheck_profile_.get(); | 1705 return spellcheck_profile_.get(); |
| 1764 } | 1706 } |
| 1765 | 1707 |
| 1766 void ProfileImpl::SetDownloadManagerDelegate( | 1708 void ProfileImpl::SetDownloadManagerDelegate( |
| 1767 ChromeDownloadManagerDelegate* delegate) { | 1709 ChromeDownloadManagerDelegate* delegate) { |
| 1768 download_manager_delegate_ = delegate; | 1710 download_manager_delegate_ = delegate; |
| 1769 } | 1711 } |
| OLD | NEW |