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

Side by Side Diff: chrome/browser/managed_mode/managed_mode.cc

Issue 12033021: Add UMA metrics and histograms for locally managed users. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 7 years, 11 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) 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/managed_mode/managed_mode.h" 5 #include "chrome/browser/managed_mode/managed_mode.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/metrics/histogram.h"
8 #include "base/prefs/public/pref_change_registrar.h" 9 #include "base/prefs/public/pref_change_registrar.h"
10 #include "base/rand_util.h"
9 #include "base/sequenced_task_runner.h" 11 #include "base/sequenced_task_runner.h"
10 #include "chrome/browser/browser_process.h" 12 #include "chrome/browser/browser_process.h"
11 #include "chrome/browser/extensions/extension_service.h" 13 #include "chrome/browser/extensions/extension_service.h"
12 #include "chrome/browser/extensions/extension_system.h" 14 #include "chrome/browser/extensions/extension_system.h"
15 #include "chrome/browser/history/history.h"
16 #include "chrome/browser/history/history_service_factory.h"
17 #include "chrome/browser/history/history_types.h"
18 #include "chrome/browser/history/url_database.h"
13 #include "chrome/browser/managed_mode/managed_mode_site_list.h" 19 #include "chrome/browser/managed_mode/managed_mode_site_list.h"
14 #include "chrome/browser/managed_mode/managed_mode_url_filter.h" 20 #include "chrome/browser/managed_mode/managed_mode_url_filter.h"
15 #include "chrome/browser/policy/url_blacklist_manager.h" 21 #include "chrome/browser/policy/url_blacklist_manager.h"
16 #include "chrome/browser/prefs/pref_service.h" 22 #include "chrome/browser/prefs/pref_service.h"
17 #include "chrome/browser/prefs/scoped_user_pref_update.h" 23 #include "chrome/browser/prefs/scoped_user_pref_update.h"
18 #include "chrome/browser/profiles/profile.h" 24 #include "chrome/browser/profiles/profile.h"
19 #include "chrome/browser/ui/browser.h" 25 #include "chrome/browser/ui/browser.h"
20 #include "chrome/browser/ui/browser_list.h" 26 #include "chrome/browser/ui/browser_list.h"
21 #include "chrome/browser/ui/browser_window.h" 27 #include "chrome/browser/ui/browser_window.h"
22 #include "chrome/common/chrome_notification_types.h" 28 #include "chrome/common/chrome_notification_types.h"
23 #include "chrome/common/chrome_switches.h" 29 #include "chrome/common/chrome_switches.h"
24 #include "chrome/common/extensions/extension_set.h" 30 #include "chrome/common/extensions/extension_set.h"
25 #include "chrome/common/pref_names.h" 31 #include "chrome/common/pref_names.h"
26 #include "content/public/browser/browser_thread.h" 32 #include "content/public/browser/browser_thread.h"
27 #include "content/public/browser/notification_service.h" 33 #include "content/public/browser/notification_service.h"
34 #include "content/public/browser/user_metrics.h"
35 #include "googleurl/src/gurl.h"
28 #include "grit/generated_resources.h" 36 #include "grit/generated_resources.h"
29 #include "ui/base/l10n/l10n_util.h" 37 #include "ui/base/l10n/l10n_util.h"
30 38
31 using content::BrowserThread; 39 using content::BrowserThread;
40 using content::UserMetricsAction;
32 41
33 // A bridge from ManagedMode (which lives on the UI thread) to 42 // A bridge from ManagedMode (which lives on the UI thread) to
34 // ManagedModeURLFilter (which might live on a different thread). 43 // ManagedModeURLFilter (which might live on a different thread).
35 class ManagedMode::URLFilterContext { 44 class ManagedMode::URLFilterContext {
36 public: 45 public:
37 explicit URLFilterContext( 46 explicit URLFilterContext(
38 scoped_refptr<base::SequencedTaskRunner> task_runner) 47 scoped_refptr<base::SequencedTaskRunner> task_runner)
39 : task_runner_(task_runner) {} 48 : task_runner_(task_runner) {}
40 ~URLFilterContext() {} 49 ~URLFilterContext() {}
41 50
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 138
130 void ManagedMode::InitImpl(Profile* profile) { 139 void ManagedMode::InitImpl(Profile* profile) {
131 DCHECK(g_browser_process); 140 DCHECK(g_browser_process);
132 DCHECK(g_browser_process->local_state()); 141 DCHECK(g_browser_process->local_state());
133 142
134 Profile* original_profile = profile->GetOriginalProfile(); 143 Profile* original_profile = profile->GetOriginalProfile();
135 // Set the value directly in the PrefService instead of using 144 // Set the value directly in the PrefService instead of using
136 // CommandLinePrefStore so we can change it at runtime. 145 // CommandLinePrefStore so we can change it at runtime.
137 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kNoManaged)) { 146 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kNoManaged)) {
138 SetInManagedMode(NULL); 147 SetInManagedMode(NULL);
148 content::RecordAction(
149 UserMetricsAction("ManagedMode_StartupNoManagedSwitch"));
139 } else if (IsInManagedModeImpl() || 150 } else if (IsInManagedModeImpl() ||
140 CommandLine::ForCurrentProcess()->HasSwitch(switches::kManaged)) { 151 CommandLine::ForCurrentProcess()->HasSwitch(switches::kManaged)) {
141 SetInManagedMode(original_profile); 152 SetInManagedMode(original_profile);
153 content::RecordAction(
154 UserMetricsAction("ManagedMode_StartupManagedSwitch"));
142 } 155 }
156
157 // Only compute these statistics sometimes, because they can be expensive.
158 if (base::RandInt(1, 100) == 50) {
159 base::TimeTicks start_time = base::TimeTicks::Now();
160 base::Time query_start = base::Time::Now() - base::TimeDelta::FromDays(7);
161 CollectDetailedHistoryMetrics(original_profile, query_start, "Weekly");
162 query_start = base::Time::Now() - base::TimeDelta::FromDays(30);
163 CollectDetailedHistoryMetrics(original_profile, query_start, "Monthly");
164 UMA_HISTOGRAM_TIMES("History.DatabaseAdvancedMetricsTime",
165 base::TimeTicks::Now() - start_time);
166 }
167 }
168
169 void ManagedMode::CollectDetailedHistoryMetrics(Profile* profile,
170 base::Time start_time,
171 std::string description) {
172 // We have to collect statistics about the categories here; the history
173 // database dosn't know about managed users or categories. So we gather
174 // statistics about the URLs and hosts here too, since we have the data.
175 HistoryService* const history_service =
176 HistoryServiceFactory::GetForProfile(profile, Profile::IMPLICIT_ACCESS);
177 history::URLDatabase* url_db = history_service ?
178 history_service->InMemoryDatabase() : NULL;
179
180 if (!url_db)
181 return;
182
183 std::string base_metric_name = std::string("History.").append(description);
184
185 history::URLRows urls;
186 url_db->GetUniqueURLsInRange(start_time, base::Time(), 0, &urls);
187 UMA_HISTOGRAM_COUNTS(base_metric_name.append("URLCount"), urls.size());
188
189 std::set<std::string> hosts;
190 std::set<int> categories;
191 for (history::URLRows::iterator row = urls.begin();
192 row != urls.end(); ++row) {
193 GURL url = row->url();
194 hosts.insert(url.host());
195 categories.insert(ManagedMode::GetCategory(url));
196 }
197 UMA_HISTOGRAM_COUNTS_10000(base_metric_name.append("HostCount"),
198 hosts.size());
199 UMA_HISTOGRAM_CUSTOM_COUNTS(base_metric_name.append("CategoryCount"),
200 categories.size(), 0, 30, 30);
143 } 201 }
144 202
145 // static 203 // static
146 bool ManagedMode::IsInManagedMode() { 204 bool ManagedMode::IsInManagedMode() {
147 return GetInstance()->IsInManagedModeImpl(); 205 return GetInstance()->IsInManagedModeImpl();
148 } 206 }
149 207
150 bool ManagedMode::IsInManagedModeImpl() const { 208 bool ManagedMode::IsInManagedModeImpl() const {
151 // |g_browser_process| can be NULL during startup. 209 // |g_browser_process| can be NULL during startup.
152 if (!g_browser_process) 210 if (!g_browser_process)
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
307 return list->Find(pattern) != list->end(); 365 return list->Find(pattern) != list->end();
308 } 366 }
309 367
310 // static 368 // static
311 scoped_ptr<base::ListValue> ManagedMode::GetBlacklist() { 369 scoped_ptr<base::ListValue> ManagedMode::GetBlacklist() {
312 return scoped_ptr<base::ListValue>( 370 return scoped_ptr<base::ListValue>(
313 GetInstance()->managed_profile_->GetPrefs()->GetList( 371 GetInstance()->managed_profile_->GetPrefs()->GetList(
314 prefs::kManagedModeBlacklist)->DeepCopy()).Pass(); 372 prefs::kManagedModeBlacklist)->DeepCopy()).Pass();
315 } 373 }
316 374
375 // Items not on any list must return -1 (CATEGORY_NOT_ON_LIST in history.js).
376 // Items on a list, but with no category, must return 0 (CATEGORY_OTHER).
377 #define CATEGORY_NOT_ON_LIST -1;
378 #define CATEGORY_OTHER 0;
379 // static
380 int ManagedMode::GetCategory(const GURL& url) {
381 return GetInstance()->GetCategoryImpl(url);
382 }
383
384 int ManagedMode::GetCategoryImpl(const GURL& url) {
385 std::vector<ManagedModeSiteList::Site*> sites;
386 GetURLFilterForUIThreadImpl()->GetSites(url, &sites);
387 if (sites.empty())
388 return CATEGORY_NOT_ON_LIST;
389
390 return (*sites.begin())->category_id;
391 }
392
317 std::string ManagedMode::GetDebugPolicyProviderName() const { 393 std::string ManagedMode::GetDebugPolicyProviderName() const {
318 // Save the string space in official builds. 394 // Save the string space in official builds.
319 #ifdef NDEBUG 395 #ifdef NDEBUG
320 NOTREACHED(); 396 NOTREACHED();
321 return std::string(); 397 return std::string();
322 #else 398 #else
323 return "Managed Mode"; 399 return "Managed Mode";
324 #endif 400 #endif
325 } 401 }
326 402
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
530 managed_profile_->GetPrefs()->GetList( 606 managed_profile_->GetPrefs()->GetList(
531 prefs::kManagedModeWhitelist)->DeepCopy()); 607 prefs::kManagedModeWhitelist)->DeepCopy());
532 } 608 }
533 609
534 void ManagedMode::AddURLPatternToManualList( 610 void ManagedMode::AddURLPatternToManualList(
535 bool is_whitelist, 611 bool is_whitelist,
536 const std::string& url_pattern) { 612 const std::string& url_pattern) {
537 io_url_filter_context_->AddURLPatternToManualList(true, url_pattern); 613 io_url_filter_context_->AddURLPatternToManualList(true, url_pattern);
538 ui_url_filter_context_->AddURLPatternToManualList(true, url_pattern); 614 ui_url_filter_context_->AddURLPatternToManualList(true, url_pattern);
539 } 615 }
OLDNEW
« no previous file with comments | « chrome/browser/managed_mode/managed_mode.h ('k') | chrome/browser/managed_mode/managed_mode_interstitial.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698