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

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

Issue 8086002: Add metrics to help measure effects of installing default apps in a profile. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Change events to histograms Created 9 years, 2 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 | Annotate | Revision Log
OLDNEW
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 <set> 5 #include <set>
6 6
7 #include "chrome/browser/profiles/profile_manager.h" 7 #include "chrome/browser/profiles/profile_manager.h"
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.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/metrics/field_trial.h"
13 #include "base/metrics/histogram.h"
12 #include "base/stl_util.h" 14 #include "base/stl_util.h"
13 #include "base/string_number_conversions.h" 15 #include "base/string_number_conversions.h"
14 #include "base/string_util.h" 16 #include "base/string_util.h"
15 #include "base/utf_string_conversions.h" 17 #include "base/utf_string_conversions.h"
16 #include "chrome/browser/browser_process.h" 18 #include "chrome/browser/browser_process.h"
19 #include "chrome/browser/extensions/default_apps_trial.h"
20 #include "chrome/browser/extensions/extension_service.h"
17 #include "chrome/browser/prefs/pref_service.h" 21 #include "chrome/browser/prefs/pref_service.h"
18 #include "chrome/browser/prefs/scoped_user_pref_update.h" 22 #include "chrome/browser/prefs/scoped_user_pref_update.h"
19 #include "chrome/browser/profiles/profile_info_cache.h" 23 #include "chrome/browser/profiles/profile_info_cache.h"
20 #include "chrome/browser/sessions/session_service_factory.h" 24 #include "chrome/browser/sessions/session_service_factory.h"
21 #include "chrome/browser/sync/profile_sync_service.h" 25 #include "chrome/browser/sync/profile_sync_service.h"
22 #include "chrome/browser/ui/browser.h" 26 #include "chrome/browser/ui/browser.h"
23 #include "chrome/browser/ui/browser_window.h" 27 #include "chrome/browser/ui/browser_window.h"
24 #include "chrome/browser/ui/webui/sync_promo_ui.h" 28 #include "chrome/browser/ui/webui/sync_promo_ui.h"
25 #include "chrome/common/chrome_notification_types.h" 29 #include "chrome/common/chrome_notification_types.h"
26 #include "chrome/common/chrome_constants.h" 30 #include "chrome/common/chrome_constants.h"
(...skipping 17 matching lines...) Expand all
44 #endif 48 #endif
45 49
46 namespace { 50 namespace {
47 51
48 // Profiles that should be deleted on shutdown. 52 // Profiles that should be deleted on shutdown.
49 std::vector<FilePath>& ProfilesToDelete() { 53 std::vector<FilePath>& ProfilesToDelete() {
50 static std::vector<FilePath> profiles_to_delete; 54 static std::vector<FilePath> profiles_to_delete;
51 return profiles_to_delete; 55 return profiles_to_delete;
52 } 56 }
53 57
58 // Simple task to log the size of the current profile.
59 class ProfileSizeTask : public Task {
60 public:
61 explicit ProfileSizeTask(Profile* profile);
62 virtual ~ProfileSizeTask() {}
63
64 virtual void Run();
65 private:
66 FilePath path_;
67 int extension_count_;
68 };
69
70 ProfileSizeTask::ProfileSizeTask(Profile* profile)
71 : path_(profile->GetPath()), extension_count_(-1) {
72 // This object should not remember the profile pointer since it should not
73 // be accessed from IO thread.
74
75 // Count number of extensions in this profile.
76 ExtensionService* extension_service = profile->GetExtensionService();
77 if (extension_service)
78 extension_count_ = extension_service->GetAppIds().size();
79 }
80
81 void ProfileSizeTask::Run() {
82 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
83
84 int64 size = file_util::ComputeFilesSize(path_, FILE_PATH_LITERAL("*"));
85 int size_MB = static_cast<int>(size / (1024 * 1024));
86 UMA_HISTOGRAM_COUNTS_10000("Profile.TotalSize", size_MB);
87
88 size = file_util::ComputeFilesSize(path_, FILE_PATH_LITERAL("History"));
89 size_MB = static_cast<int>(size / (1024 * 1024));
90 UMA_HISTOGRAM_COUNTS_10000("Profile.HistorySize", size_MB);
91
92 size = file_util::ComputeFilesSize(path_, FILE_PATH_LITERAL("History*"));
93 size_MB = static_cast<int>(size / (1024 * 1024));
94 UMA_HISTOGRAM_COUNTS_10000("Profile.TotalHistorySize", size_MB);
95
96 size = file_util::ComputeFilesSize(path_, FILE_PATH_LITERAL("Cookies"));
97 size_MB = static_cast<int>(size / (1024 * 1024));
98 UMA_HISTOGRAM_COUNTS_10000("Profile.CookiesSize", size_MB);
99
100 size = file_util::ComputeFilesSize(path_, FILE_PATH_LITERAL("Bookmarks"));
101 size_MB = static_cast<int>(size / (1024 * 1024));
102 UMA_HISTOGRAM_COUNTS_10000("Profile.BookmarksSize", size_MB);
103
104 size = file_util::ComputeFilesSize(path_, FILE_PATH_LITERAL("Favicons"));
105 size_MB = static_cast<int>(size / (1024 * 1024));
106 UMA_HISTOGRAM_COUNTS_10000("Profile.FaviconsSize", size_MB);
107
108 size = file_util::ComputeFilesSize(path_, FILE_PATH_LITERAL("Top Sites"));
109 size_MB = static_cast<int>(size / (1024 * 1024));
110 UMA_HISTOGRAM_COUNTS_10000("Profile.TopSitesSize", size_MB);
111
112 size = file_util::ComputeFilesSize(path_, FILE_PATH_LITERAL("Visited Links"));
113 size_MB = static_cast<int>(size / (1024 * 1024));
114 UMA_HISTOGRAM_COUNTS_10000("Profile.VisitedLinksSize", size_MB);
115
116 size = file_util::ComputeFilesSize(path_, FILE_PATH_LITERAL("Web Data"));
117 size_MB = static_cast<int>(size / (1024 * 1024));
118 UMA_HISTOGRAM_COUNTS_10000("Profile.WebDataSize", size_MB);
119
120 size = file_util::ComputeFilesSize(path_, FILE_PATH_LITERAL("Extension*"));
121 size_MB = static_cast<int>(size / (1024 * 1024));
122 UMA_HISTOGRAM_COUNTS_10000("Profile.ExtensionSize", size_MB);
123
124 // Count number of extensions in this profile, if we know.
125 if (extension_count_ != -1) {
126 UMA_HISTOGRAM_COUNTS_10000("Profile.AppCount", extension_count_);
127
128 static bool default_apps_trial_exists = base::FieldTrialList::TrialExists(
129 kDefaultAppsTrial_Name);
130 if (default_apps_trial_exists) {
131 UMA_HISTOGRAM_COUNTS_10000(
132 base::FieldTrial::MakeName("Profile.AppCount",
133 kDefaultAppsTrial_Name),
134 extension_count_);
135 }
136 }
137 }
138
54 void QueueProfileDirectoryForDeletion(const FilePath& path) { 139 void QueueProfileDirectoryForDeletion(const FilePath& path) {
55 ProfilesToDelete().push_back(path); 140 ProfilesToDelete().push_back(path);
56 } 141 }
57 142
58 } // namespace 143 } // namespace
59 144
60 bool ProfileManagerObserver::DeleteAfter() { 145 bool ProfileManagerObserver::DeleteAfter() {
61 return false; 146 return false;
62 } 147 }
63 148
(...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after
376 last_active->GetPath().BaseName().MaybeAsASCII()); 461 last_active->GetPath().BaseName().MaybeAsASCII());
377 } 462 }
378 } 463 }
379 464
380 void ProfileManager::DoFinalInit(Profile* profile, bool go_off_the_record) { 465 void ProfileManager::DoFinalInit(Profile* profile, bool go_off_the_record) {
381 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); 466 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
382 profile->InitExtensions(!go_off_the_record); 467 profile->InitExtensions(!go_off_the_record);
383 if (!command_line.HasSwitch(switches::kDisableWebResources)) 468 if (!command_line.HasSwitch(switches::kDisableWebResources))
384 profile->InitPromoResources(); 469 profile->InitPromoResources();
385 AddProfileToCache(profile); 470 AddProfileToCache(profile);
471
472 // Log the profile size after a reasonable startup delay.
473 BrowserThread::PostDelayedTask(BrowserThread::FILE, FROM_HERE,
474 new ProfileSizeTask(profile), 112000);
386 } 475 }
387 476
388 Profile* ProfileManager::CreateProfile(const FilePath& path) { 477 Profile* ProfileManager::CreateProfile(const FilePath& path) {
389 return Profile::CreateProfile(path); 478 return Profile::CreateProfile(path);
390 } 479 }
391 480
392 void ProfileManager::OnProfileCreated(Profile* profile, bool success) { 481 void ProfileManager::OnProfileCreated(Profile* profile, bool success) {
393 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 482 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
394 483
395 ProfilesInfoMap::iterator iter = profiles_info_.find(profile->GetPath()); 484 ProfilesInfoMap::iterator iter = profiles_info_.find(profile->GetPath());
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
548 ProfileManagerWithoutInit::ProfileManagerWithoutInit( 637 ProfileManagerWithoutInit::ProfileManagerWithoutInit(
549 const FilePath& user_data_dir) : ProfileManager(user_data_dir) { 638 const FilePath& user_data_dir) : ProfileManager(user_data_dir) {
550 } 639 }
551 640
552 void ProfileManager::RegisterTestingProfile(Profile* profile, 641 void ProfileManager::RegisterTestingProfile(Profile* profile,
553 bool add_to_cache) { 642 bool add_to_cache) {
554 RegisterProfile(profile, true); 643 RegisterProfile(profile, true);
555 if (add_to_cache) 644 if (add_to_cache)
556 AddProfileToCache(profile); 645 AddProfileToCache(profile);
557 } 646 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698