| Index: chrome/browser/managed_mode/managed_mode.cc
|
| ===================================================================
|
| --- chrome/browser/managed_mode/managed_mode.cc (revision 177135)
|
| +++ chrome/browser/managed_mode/managed_mode.cc (working copy)
|
| @@ -5,11 +5,17 @@
|
| #include "chrome/browser/managed_mode/managed_mode.h"
|
|
|
| #include "base/command_line.h"
|
| +#include "base/metrics/histogram.h"
|
| #include "base/prefs/public/pref_change_registrar.h"
|
| +#include "base/rand_util.h"
|
| #include "base/sequenced_task_runner.h"
|
| #include "chrome/browser/browser_process.h"
|
| #include "chrome/browser/extensions/extension_service.h"
|
| #include "chrome/browser/extensions/extension_system.h"
|
| +#include "chrome/browser/history/history.h"
|
| +#include "chrome/browser/history/history_service_factory.h"
|
| +#include "chrome/browser/history/history_types.h"
|
| +#include "chrome/browser/history/url_database.h"
|
| #include "chrome/browser/managed_mode/managed_mode_site_list.h"
|
| #include "chrome/browser/managed_mode/managed_mode_url_filter.h"
|
| #include "chrome/browser/policy/url_blacklist_manager.h"
|
| @@ -25,10 +31,13 @@
|
| #include "chrome/common/pref_names.h"
|
| #include "content/public/browser/browser_thread.h"
|
| #include "content/public/browser/notification_service.h"
|
| +#include "content/public/browser/user_metrics.h"
|
| +#include "googleurl/src/gurl.h"
|
| #include "grit/generated_resources.h"
|
| #include "ui/base/l10n/l10n_util.h"
|
|
|
| using content::BrowserThread;
|
| +using content::UserMetricsAction;
|
|
|
| // A bridge from ManagedMode (which lives on the UI thread) to
|
| // ManagedModeURLFilter (which might live on a different thread).
|
| @@ -136,12 +145,61 @@
|
| // CommandLinePrefStore so we can change it at runtime.
|
| if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kNoManaged)) {
|
| SetInManagedMode(NULL);
|
| + content::RecordAction(
|
| + UserMetricsAction("ManagedMode_StartupNoManagedSwitch"));
|
| } else if (IsInManagedModeImpl() ||
|
| CommandLine::ForCurrentProcess()->HasSwitch(switches::kManaged)) {
|
| SetInManagedMode(original_profile);
|
| + content::RecordAction(
|
| + UserMetricsAction("ManagedMode_StartupManagedSwitch"));
|
| }
|
| +
|
| + // Only compute these statistics sometimes, because they can be expensive.
|
| + if (base::RandInt(1, 100) == 50) {
|
| + base::TimeTicks start_time = base::TimeTicks::Now();
|
| + base::Time query_start = base::Time::Now() - base::TimeDelta::FromDays(7);
|
| + CollectDetailedHistoryMetrics(original_profile, query_start, "Weekly");
|
| + query_start = base::Time::Now() - base::TimeDelta::FromDays(30);
|
| + CollectDetailedHistoryMetrics(original_profile, query_start, "Monthly");
|
| + UMA_HISTOGRAM_TIMES("History.DatabaseAdvancedMetricsTime",
|
| + base::TimeTicks::Now() - start_time);
|
| + }
|
| }
|
|
|
| +void ManagedMode::CollectDetailedHistoryMetrics(Profile* profile,
|
| + base::Time start_time,
|
| + std::string description) {
|
| + // We have to collect statistics about the categories here; the history
|
| + // database dosn't know about managed users or categories. So we gather
|
| + // statistics about the URLs and hosts here too, since we have the data.
|
| + HistoryService* const history_service =
|
| + HistoryServiceFactory::GetForProfile(profile, Profile::IMPLICIT_ACCESS);
|
| + history::URLDatabase* url_db = history_service ?
|
| + history_service->InMemoryDatabase() : NULL;
|
| +
|
| + if (!url_db)
|
| + return;
|
| +
|
| + std::string base_metric_name = std::string("History.").append(description);
|
| +
|
| + history::URLRows urls;
|
| + url_db->GetUniqueURLsInRange(start_time, base::Time(), 0, &urls);
|
| + UMA_HISTOGRAM_COUNTS(base_metric_name.append("URLCount"), urls.size());
|
| +
|
| + std::set<std::string> hosts;
|
| + std::set<int> categories;
|
| + for (history::URLRows::iterator row = urls.begin();
|
| + row != urls.end(); ++row) {
|
| + GURL url = row->url();
|
| + hosts.insert(url.host());
|
| + categories.insert(ManagedMode::GetCategory(url));
|
| + }
|
| + UMA_HISTOGRAM_COUNTS_10000(base_metric_name.append("HostCount"),
|
| + hosts.size());
|
| + UMA_HISTOGRAM_CUSTOM_COUNTS(base_metric_name.append("CategoryCount"),
|
| + categories.size(), 0, 30, 30);
|
| +}
|
| +
|
| // static
|
| bool ManagedMode::IsInManagedMode() {
|
| return GetInstance()->IsInManagedModeImpl();
|
| @@ -314,6 +372,24 @@
|
| prefs::kManagedModeBlacklist)->DeepCopy()).Pass();
|
| }
|
|
|
| + // Items not on any list must return -1 (CATEGORY_NOT_ON_LIST in history.js).
|
| + // Items on a list, but with no category, must return 0 (CATEGORY_OTHER).
|
| + #define CATEGORY_NOT_ON_LIST -1;
|
| + #define CATEGORY_OTHER 0;
|
| + // static
|
| + int ManagedMode::GetCategory(const GURL& url) {
|
| + return GetInstance()->GetCategoryImpl(url);
|
| + }
|
| +
|
| + int ManagedMode::GetCategoryImpl(const GURL& url) {
|
| + std::vector<ManagedModeSiteList::Site*> sites;
|
| + GetURLFilterForUIThreadImpl()->GetSites(url, &sites);
|
| + if (sites.empty())
|
| + return CATEGORY_NOT_ON_LIST;
|
| +
|
| + return (*sites.begin())->category_id;
|
| + }
|
| +
|
| std::string ManagedMode::GetDebugPolicyProviderName() const {
|
| // Save the string space in official builds.
|
| #ifdef NDEBUG
|
|
|