Back to index

lightning-sunbird  0.9+nobinonly
Classes | Public Member Functions | Private Member Functions | Private Attributes
nsProfileCollector Class Reference

#include <nsProfileCollector.h>

Inheritance diagram for nsProfileCollector:
Inheritance graph
[legend]
Collaboration diagram for nsProfileCollector:
Collaboration graph
[legend]

List of all members.

Classes

class  BookmarkCounter
class  ExtensionEnumerator
class  PluginEnumerator

Public Member Functions

NS_DECL_ISUPPORTS
NS_DECL_NSIMETRICSCOLLECTOR 
nsProfileCollector ()
void onAttach ()
 Notification that this collector should be enabled.
void onDetach ()
 Notification that this collector is no longer enabled.
void onNewLog ()
 Notification that the MetricsService is starting a new event log.

Private Member Functions

 ~nsProfileCollector ()
nsresult LogCPU (nsIMetricsEventItem *profile)
nsresult LogMemory (nsIMetricsEventItem *profile)
nsresult LogOS (nsIMetricsEventItem *profile)
nsresult LogInstall (nsIMetricsEventItem *profile)
nsresult LogExtensions (nsIMetricsEventItem *profile)
nsresult LogPlugins (nsIMetricsEventItem *profile)
nsresult LogDisplay (nsIMetricsEventItem *profile)
nsresult LogBookmarks (nsIMetricsEventItem *profile)
void LogBookmarkLocation (nsIMetricsEventItem *bookmarksItem, const nsACString &location, BookmarkCounter *counter, nsIRDFResource *root, PRBool deep)

Private Attributes

PRBool mLoggedProfile

Detailed Description

Definition at line 55 of file nsProfileCollector.h.


Constructor & Destructor Documentation

Definition at line 162 of file nsProfileCollector.cpp.

Definition at line 167 of file nsProfileCollector.cpp.

{
}

Member Function Documentation

void nsProfileCollector::LogBookmarkLocation ( nsIMetricsEventItem bookmarksItem,
const nsACString &  location,
BookmarkCounter counter,
nsIRDFResource root,
PRBool  deep 
) [private]

Definition at line 515 of file nsProfileCollector.cpp.

{
  nsTArray<PRInt32> count;
  counter->CountChildren(root, deep, count);

  nsCOMPtr<nsIWritablePropertyBag2> props;
  nsMetricsUtils::NewPropertyBag(getter_AddRefs(props));
  if (!props) {
    return;
  }

  props->SetPropertyAsACString(NS_LITERAL_STRING("name"), location);
  props->SetPropertyAsInt32(NS_LITERAL_STRING("itemcount"),
                            count[BookmarkCounter::ITEM]);
  props->SetPropertyAsInt32(NS_LITERAL_STRING("foldercount"),
                            count[BookmarkCounter::FOLDER]);
  props->SetPropertyAsInt32(NS_LITERAL_STRING("livemarkcount"),
                            count[BookmarkCounter::LIVEMARK]);
  props->SetPropertyAsInt32(NS_LITERAL_STRING("separatorcount"),
                            count[BookmarkCounter::SEPARATOR]);

  nsMetricsUtils::AddChildItem(bookmarksItem,
                               NS_LITERAL_STRING("bookmarklocation"), props);
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 433 of file nsProfileCollector.cpp.

{
  nsresult rv;

  nsMetricsService *ms = nsMetricsService::get();
  NS_ENSURE_STATE(ms);

  nsCOMPtr<nsIMetricsEventItem> bookmarksItem;
  ms->CreateEventItem(NS_LITERAL_STRING("bookmarks"),
                      getter_AddRefs(bookmarksItem));
  NS_ENSURE_STATE(bookmarksItem);

#ifdef MOZ_PLACES
  nsCOMPtr<nsINavBookmarksService> bmSvc =
    do_GetService(NS_NAVBOOKMARKSSERVICE_CONTRACTID);
  NS_ENSURE_STATE(bmSvc);

  PRInt64 root = 0;
  rv = bmSvc->GetPlacesRoot(&root);
  NS_ENSURE_SUCCESS(rv, rv);

  BookmarkCounter counter;
  rv = counter.Init();
  NS_ENSURE_SUCCESS(rv, rv);

  LogBookmarkLocation(bookmarksItem, NS_LITERAL_CSTRING("full-tree"),
                      &counter, root, PR_TRUE);

  rv = bmSvc->GetBookmarksRoot(&root);
  NS_ENSURE_SUCCESS(rv, rv);

  LogBookmarkLocation(bookmarksItem, NS_LITERAL_CSTRING("root"),
                      &counter, root, PR_FALSE);

  rv = bmSvc->GetToolbarRoot(&root);
  NS_ENSURE_SUCCESS(rv, rv);

  LogBookmarkLocation(bookmarksItem, NS_LITERAL_CSTRING("toolbar"),
                  &counter, root, PR_FALSE);

#else
  nsCOMPtr<nsIBookmarksService> bmSvc =
    do_GetService(NS_BOOKMARKS_SERVICE_CONTRACTID);
  NS_ENSURE_STATE(bmSvc);

  // This just ensures that the bookmarks are loaded, it doesn't
  // read them again if they've already been read.
  PRBool loaded;
  bmSvc->ReadBookmarks(&loaded);

  nsCOMPtr<nsIRDFService> rdfSvc =
    do_GetService("@mozilla.org/rdf/rdf-service;1");
  NS_ENSURE_STATE(rdfSvc);

  nsCOMPtr<nsIRDFResource> root;
  rdfSvc->GetResource(NS_LITERAL_CSTRING("NC:BookmarksRoot"),
                      getter_AddRefs(root));
  NS_ENSURE_STATE(root);

  BookmarkCounter counter;
  rv = counter.Init();
  NS_ENSURE_SUCCESS(rv, rv);

  LogBookmarkLocation(bookmarksItem, NS_LITERAL_CSTRING("full-tree"),
                      &counter, root, PR_TRUE);
  LogBookmarkLocation(bookmarksItem, NS_LITERAL_CSTRING("root"),
                      &counter, root, PR_FALSE);

  bmSvc->GetBookmarksToolbarFolder(getter_AddRefs(root));
  if (root) {
    LogBookmarkLocation(bookmarksItem, NS_LITERAL_CSTRING("toolbar"),
                        &counter, root, PR_FALSE);
  }
#endif

  rv = profile->AppendChild(bookmarksItem);
  NS_ENSURE_SUCCESS(rv, rv);

  return NS_OK;
}

Here is the call graph for this function:

Definition at line 216 of file nsProfileCollector.cpp.

{
  nsCOMPtr<nsIWritablePropertyBag2> properties;
  nsMetricsUtils::NewPropertyBag(getter_AddRefs(properties));
  NS_ENSURE_STATE(properties);

  char buf[SYS_INFO_BUFFER_LENGTH];
  if (PR_GetSystemInfo(PR_SI_ARCHITECTURE, buf, sizeof(buf)) != PR_SUCCESS) {
    MS_LOG(("Failed to get architecture"));
    return NS_ERROR_FAILURE;
  }

  properties->SetPropertyAsACString(NS_LITERAL_STRING("arch"),
                                    nsDependentCString(buf));
  MS_LOG(("Logged CPU arch=%s", buf));

  nsresult rv = nsMetricsUtils::AddChildItem(
      profile, NS_LITERAL_STRING("cpu"), properties);
  NS_ENSURE_SUCCESS(rv, rv);

  return NS_OK;
}

Here is the call graph for this function:

Definition at line 395 of file nsProfileCollector.cpp.

{
  nsCOMPtr<nsIWritablePropertyBag2> properties;
  nsMetricsUtils::NewPropertyBag(getter_AddRefs(properties));
  NS_ENSURE_STATE(properties);

  nsCOMPtr<nsIScreenManager> screenManager =
    do_GetService("@mozilla.org/gfx/screenmanager;1");
  NS_ENSURE_STATE(screenManager);

  nsCOMPtr<nsIScreen> primaryScreen;
  screenManager->GetPrimaryScreen(getter_AddRefs(primaryScreen));
  NS_ENSURE_STATE(primaryScreen);

  PRInt32 left, top, width, height;
  nsresult rv = primaryScreen->GetRect(&left, &top, &width, &height);
  NS_ENSURE_SUCCESS(rv, rv);

  properties->SetPropertyAsInt32(NS_LITERAL_STRING("xsize"), width);
  properties->SetPropertyAsInt32(NS_LITERAL_STRING("ysize"), height);
  MS_LOG(("Logged display xsize=%d ysize=%d", width, height));

  PRUint32 numScreens = 0;
  if (NS_SUCCEEDED(screenManager->GetNumberOfScreens(&numScreens))) {
    properties->SetPropertyAsUint32(NS_LITERAL_STRING("screens"), numScreens);
    MS_LOG(("Logged display screens=%d", numScreens));
  } else {
    MS_LOG(("Could not get number of screens"));
  }

  rv = nsMetricsUtils::AddChildItem(profile,
                                    NS_LITERAL_STRING("display"), properties);
  NS_ENSURE_SUCCESS(rv, rv);

  return NS_OK;
}

Here is the call graph for this function:

Definition at line 353 of file nsProfileCollector.cpp.

{
  nsCOMPtr<nsIMetricsEventItem> extensions;
  nsMetricsService::get()->CreateEventItem(NS_LITERAL_STRING("extensions"),
                                           getter_AddRefs(extensions));
  NS_ENSURE_STATE(extensions);

  ExtensionEnumerator enumerator;
  nsresult rv = enumerator.Init();
  NS_ENSURE_SUCCESS(rv, rv);

  rv = enumerator.LogExtensions(extensions);
  NS_ENSURE_SUCCESS(rv, rv);

  rv = profile->AppendChild(extensions);
  NS_ENSURE_SUCCESS(rv, rv);

  return NS_OK;
}

Here is the call graph for this function:

Definition at line 297 of file nsProfileCollector.cpp.

{
  nsCOMPtr<nsIWritablePropertyBag2> properties;
  nsMetricsUtils::NewPropertyBag(getter_AddRefs(properties));
  NS_ENSURE_STATE(properties);

  nsCOMPtr<nsIXULAppInfo> appInfo =
    do_GetService(XULAPPINFO_SERVICE_CONTRACTID);
  NS_ENSURE_STATE(appInfo);

  nsCString buildID;
  appInfo->GetAppBuildID(buildID);
  properties->SetPropertyAsACString(NS_LITERAL_STRING("buildid"), buildID);
  MS_LOG(("Logged install buildid=%s", buildID.get()));

  // The file defaults/pref/channel-prefs.js is exlucded from any
  // security update, so we can use its creation time as an indicator
  // of when this installation was performed.

  nsCOMPtr<nsIFile> prefsDirectory;
  NS_GetSpecialDirectory(NS_APP_PREF_DEFAULTS_50_DIR,
                         getter_AddRefs(prefsDirectory));

  nsCOMPtr<nsILocalFile> channelPrefs = do_QueryInterface(prefsDirectory);
  NS_ENSURE_STATE(channelPrefs);

  nsresult rv = channelPrefs->Append(NS_LITERAL_STRING("channel-prefs.js"));
  NS_ENSURE_SUCCESS(rv, rv);

  nsCString nativePath;
  channelPrefs->GetNativePath(nativePath);
  PRFileInfo64 fileInfo;
  if (PR_GetFileInfo64(nativePath.get(), &fileInfo) == PR_SUCCESS) {
    // Convert the time to seconds since the epoch
    PRInt64 installTime = fileInfo.creationTime / PR_USEC_PER_SEC;

    static const int kSecondsPerDay = 60 * 60 * 24;

    // Round down to the nearest full day
    installTime = ((installTime / kSecondsPerDay) * kSecondsPerDay);
    properties->SetPropertyAsInt64(NS_LITERAL_STRING("installdate"),
                                   installTime);
    MS_LOG(("Logged install installdate=%lld", installTime));
  }

  // TODO: log default= based on default-browser selection
  properties->SetPropertyAsBool(NS_LITERAL_STRING("default"), PR_TRUE);

  rv = nsMetricsUtils::AddChildItem(profile,
                                    NS_LITERAL_STRING("install"), properties);
  NS_ENSURE_SUCCESS(rv, rv);

  return NS_OK;
}

Here is the call graph for this function:

Definition at line 240 of file nsProfileCollector.cpp.

{
  nsCOMPtr<nsIWritablePropertyBag2> properties;
  nsMetricsUtils::NewPropertyBag(getter_AddRefs(properties));
  NS_ENSURE_STATE(properties);

  PRUint64 size = PR_GetPhysicalMemorySize();
  if (size == 0) {
    MS_LOG(("Failed to get physical memory size"));
    return NS_ERROR_FAILURE;
  }

  PRUint64 sizeMB = size >> 20;
  properties->SetPropertyAsUint64(NS_LITERAL_STRING("mb"), sizeMB);
  MS_LOG(("Logged memory mb=%ull", sizeMB));

  nsresult rv = nsMetricsUtils::AddChildItem(
      profile, NS_LITERAL_STRING("memory"), properties);
  NS_ENSURE_SUCCESS(rv, rv);

  return NS_OK;
}

Here is the call graph for this function:

Definition at line 264 of file nsProfileCollector.cpp.

{
  nsCOMPtr<nsIWritablePropertyBag2> properties;
  nsMetricsUtils::NewPropertyBag(getter_AddRefs(properties));
  NS_ENSURE_STATE(properties);

  char buf[SYS_INFO_BUFFER_LENGTH];
  if (PR_GetSystemInfo(PR_SI_SYSNAME, buf, sizeof(buf)) != PR_SUCCESS) {
    MS_LOG(("Failed to get OS name"));
    return NS_ERROR_FAILURE;
  }

  properties->SetPropertyAsACString(NS_LITERAL_STRING("name"),
                                    nsDependentCString(buf));
  MS_LOG(("Logged os name=%s", buf));

  if (PR_GetSystemInfo(PR_SI_RELEASE, buf, sizeof(buf)) != PR_SUCCESS) {
    MS_LOG(("Failed to get OS version"));
    return NS_ERROR_FAILURE;
  }

  properties->SetPropertyAsACString(NS_LITERAL_STRING("version"),
                                    nsDependentCString(buf));
  MS_LOG(("Logged os version=%s", buf));

  nsresult rv = nsMetricsUtils::AddChildItem(
      profile, NS_LITERAL_STRING("os"), properties);
  NS_ENSURE_SUCCESS(rv, rv);

  return NS_OK;
}

Here is the call graph for this function:

Definition at line 374 of file nsProfileCollector.cpp.

{
  nsCOMPtr<nsIMetricsEventItem> plugins;
  nsMetricsService::get()->CreateEventItem(NS_LITERAL_STRING("plugins"),
                                           getter_AddRefs(plugins));
  NS_ENSURE_STATE(plugins);

  PluginEnumerator enumerator;
  nsresult rv = enumerator.Init();
  NS_ENSURE_SUCCESS(rv, rv);

  rv = enumerator.LogPlugins(plugins);
  NS_ENSURE_SUCCESS(rv, rv);

  rv = profile->AppendChild(plugins);
  NS_ENSURE_SUCCESS(rv, rv);

  return NS_OK;
}

Here is the call graph for this function:

Notification that this collector should be enabled.

The collector should register itself for observer and event notifications as necessary.

Notification that this collector is no longer enabled.

The collector should unregister itself from observer and event notifications so that the object can be freed.

Notification that the MetricsService is starting a new event log.

This happens after any onDetach() notifications that result from parsing the new configuration.


Member Data Documentation

Definition at line 93 of file nsProfileCollector.h.


The documentation for this class was generated from the following files: