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

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: Addressing spacing 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_window.h" 26 #include "chrome/browser/ui/browser_window.h"
23 #include "chrome/common/chrome_notification_types.h" 27 #include "chrome/common/chrome_notification_types.h"
24 #include "chrome/common/chrome_constants.h" 28 #include "chrome/common/chrome_constants.h"
25 #include "chrome/common/chrome_switches.h" 29 #include "chrome/common/chrome_switches.h"
26 #include "chrome/common/logging_chrome.h" 30 #include "chrome/common/logging_chrome.h"
(...skipping 16 matching lines...) Expand all
43 namespace { 47 namespace {
44 48
45 void DeleteProfileDirectories(const std::vector<FilePath>& paths) { 49 void DeleteProfileDirectories(const std::vector<FilePath>& paths) {
46 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 50 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
47 for (std::vector<FilePath>::const_iterator it = paths.begin(); 51 for (std::vector<FilePath>::const_iterator it = paths.begin();
48 it != paths.end(); ++it) { 52 it != paths.end(); ++it) {
49 file_util::Delete(*it, true); 53 file_util::Delete(*it, true);
50 } 54 }
51 } 55 }
52 56
57 // Simple task to log the size of the current profile.
58 class ProfileSizeTask : public Task {
59 public:
60 explicit ProfileSizeTask(Profile* profile);
61 virtual ~ProfileSizeTask() {}
62
63 virtual void Run();
64 private:
65 FilePath path_;
66 int extension_count_;
67 };
68
69 ProfileSizeTask::ProfileSizeTask(Profile* profile)
70 : path_(profile->GetPath()), extension_count_(-1) {
71 // This object should not remember the profile pointer since it should not
72 // be accessed from IO thread.
73
74 // Count number of extensions in this profile.
75 ExtensionService* extension_service = profile->GetExtensionService();
76 DCHECK(extension_service);
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
53 } // namespace 139 } // namespace
54 140
55 bool ProfileManagerObserver::DeleteAfter() { 141 bool ProfileManagerObserver::DeleteAfter() {
56 return false; 142 return false;
57 } 143 }
58 144
59 // The NewProfileLauncher class is created when to wait for a multi-profile 145 // The NewProfileLauncher class is created when to wait for a multi-profile
60 // to be created asynchronously. Upon completion of profile creation, the 146 // to be created asynchronously. Upon completion of profile creation, the
61 // NPL takes care of launching a new browser window and signing the user 147 // NPL takes care of launching a new browser window and signing the user
62 // in to their Google account. 148 // in to their Google account.
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after
363 last_active->GetPath().BaseName().MaybeAsASCII()); 449 last_active->GetPath().BaseName().MaybeAsASCII());
364 } 450 }
365 } 451 }
366 452
367 void ProfileManager::DoFinalInit(Profile* profile, bool go_off_the_record) { 453 void ProfileManager::DoFinalInit(Profile* profile, bool go_off_the_record) {
368 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); 454 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
369 profile->InitExtensions(!go_off_the_record); 455 profile->InitExtensions(!go_off_the_record);
370 if (!command_line.HasSwitch(switches::kDisableWebResources)) 456 if (!command_line.HasSwitch(switches::kDisableWebResources))
371 profile->InitPromoResources(); 457 profile->InitPromoResources();
372 AddProfileToCache(profile); 458 AddProfileToCache(profile);
459
460 // Log the profile size after a reasonable startup delay.
461 BrowserThread::PostDelayedTask(BrowserThread::FILE, FROM_HERE,
462 new ProfileSizeTask(profile), 112000);
373 } 463 }
374 464
375 Profile* ProfileManager::CreateProfile(const FilePath& path) { 465 Profile* ProfileManager::CreateProfile(const FilePath& path) {
376 return Profile::CreateProfile(path); 466 return Profile::CreateProfile(path);
377 } 467 }
378 468
379 void ProfileManager::OnProfileCreated(Profile* profile, bool success) { 469 void ProfileManager::OnProfileCreated(Profile* profile, bool success) {
380 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 470 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
381 471
382 ProfilesInfoMap::iterator iter = profiles_info_.find(profile->GetPath()); 472 ProfilesInfoMap::iterator iter = profiles_info_.find(profile->GetPath());
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
580 ProfileManagerWithoutInit::ProfileManagerWithoutInit( 670 ProfileManagerWithoutInit::ProfileManagerWithoutInit(
581 const FilePath& user_data_dir) : ProfileManager(user_data_dir) { 671 const FilePath& user_data_dir) : ProfileManager(user_data_dir) {
582 } 672 }
583 673
584 void ProfileManager::RegisterTestingProfile(Profile* profile, 674 void ProfileManager::RegisterTestingProfile(Profile* profile,
585 bool add_to_cache) { 675 bool add_to_cache) {
586 RegisterProfile(profile, true); 676 RegisterProfile(profile, true);
587 if (add_to_cache) 677 if (add_to_cache)
588 AddProfileToCache(profile); 678 AddProfileToCache(profile);
589 } 679 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698