| 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 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 429 | 375 |
| 430 clear_local_state_on_exit_ = prefs->GetBoolean(prefs::kClearSiteDataOnExit); | 376 clear_local_state_on_exit_ = prefs->GetBoolean(prefs::kClearSiteDataOnExit); |
| 431 if (clear_local_state_on_exit_) { | 377 if (clear_local_state_on_exit_) { |
| 432 UserMetrics::RecordAction( | 378 UserMetrics::RecordAction( |
| 433 UserMetricsAction("ClearSiteDataOnExitEnabled")); | 379 UserMetricsAction("ClearSiteDataOnExitEnabled")); |
| 434 } else { | 380 } else { |
| 435 UserMetrics::RecordAction( | 381 UserMetrics::RecordAction( |
| 436 UserMetricsAction("ClearSiteDataOnExitDisabled")); | 382 UserMetricsAction("ClearSiteDataOnExitDisabled")); |
| 437 } | 383 } |
| 438 | 384 |
| 439 // Log the profile size after a reasonable startup delay. | |
| 440 BrowserThread::PostDelayedTask(BrowserThread::FILE, FROM_HERE, | |
| 441 new ProfileSizeTask(path_), 112000); | |
| 442 | |
| 443 InstantController::RecordMetrics(this); | 385 InstantController::RecordMetrics(this); |
| 444 | 386 |
| 445 // Instantiates Metrics object for spellchecking for use. | 387 // Instantiates Metrics object for spellchecking for use. |
| 446 if (g_browser_process->metrics_service() && | 388 if (g_browser_process->metrics_service() && |
| 447 g_browser_process->metrics_service()->recording_active()) | 389 g_browser_process->metrics_service()->recording_active()) |
| 448 GetSpellCheckProfile()->StartRecordingMetrics( | 390 GetSpellCheckProfile()->StartRecordingMetrics( |
| 449 GetPrefs()->GetBoolean(prefs::kEnableSpellCheck)); | 391 GetPrefs()->GetBoolean(prefs::kEnableSpellCheck)); |
| 450 | 392 |
| 451 FilePath cookie_path = GetPath(); | 393 FilePath cookie_path = GetPath(); |
| 452 cookie_path = cookie_path.Append(chrome::kCookieFilename); | 394 cookie_path = cookie_path.Append(chrome::kCookieFilename); |
| (...skipping 1277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1730 | 1672 |
| 1731 void ProfileImpl::ClearNetworkingHistorySince(base::Time time) { | 1673 void ProfileImpl::ClearNetworkingHistorySince(base::Time time) { |
| 1732 io_data_.ClearNetworkingHistorySince(time); | 1674 io_data_.ClearNetworkingHistorySince(time); |
| 1733 } | 1675 } |
| 1734 | 1676 |
| 1735 SpellCheckProfile* ProfileImpl::GetSpellCheckProfile() { | 1677 SpellCheckProfile* ProfileImpl::GetSpellCheckProfile() { |
| 1736 if (!spellcheck_profile_.get()) | 1678 if (!spellcheck_profile_.get()) |
| 1737 spellcheck_profile_.reset(new SpellCheckProfile()); | 1679 spellcheck_profile_.reset(new SpellCheckProfile()); |
| 1738 return spellcheck_profile_.get(); | 1680 return spellcheck_profile_.get(); |
| 1739 } | 1681 } |
| OLD | NEW |