168043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)// Copyright 2013 The Chromium Authors. All rights reserved.
268043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
368043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)// found in the LICENSE file.
468043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)
568043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)#include "chrome/browser/bookmarks/bookmark_stats.h"
668043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)
768043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)#include "base/metrics/histogram.h"
8cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)#include "components/bookmarks/browser/bookmark_model.h"
968043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)#include "content/public/browser/user_metrics.h"
1068043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)
110f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)void RecordBookmarkLaunch(const BookmarkNode* node,
120f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)                          BookmarkLaunchLocation location) {
1368043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)  if (location == BOOKMARK_LAUNCH_LOCATION_DETACHED_BAR ||
1468043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)      location == BOOKMARK_LAUNCH_LOCATION_ATTACHED_BAR) {
1568043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)    content::RecordAction(
165d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)        base::UserMetricsAction("ClickedBookmarkBarURLButton"));
1768043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)  }
1868043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)  UMA_HISTOGRAM_ENUMERATION(
1968043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)      "Bookmarks.LaunchLocation", location, BOOKMARK_LAUNCH_LOCATION_LIMIT);
200f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)
210f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  if (!node)
220f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)    return;
230f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)
240f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  // In the cases where a bookmark node is provided, record the depth of the
250f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  // bookmark in the tree.
260f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  int depth = 0;
270f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  for (const BookmarkNode* iter = node; iter != NULL; iter = iter->parent()) {
280f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)    depth++;
290f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  }
300f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  // Record |depth - 2| to offset the invisible root node and permanent nodes
310f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  // (Bookmark Bar, Mobile Bookmarks or Other Bookmarks)
320f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  UMA_HISTOGRAM_COUNTS("Bookmarks.LaunchDepth", depth - 2);
3368043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)}
3468043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)
3568043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)void RecordBookmarkFolderOpen(BookmarkLaunchLocation location) {
3668043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)  if (location == BOOKMARK_LAUNCH_LOCATION_DETACHED_BAR ||
3768043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)      location == BOOKMARK_LAUNCH_LOCATION_ATTACHED_BAR) {
3868043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)    content::RecordAction(
395d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)        base::UserMetricsAction("ClickedBookmarkBarFolder"));
4068043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)  }
4168043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)}
4268043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)
4368043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)void RecordBookmarkAppsPageOpen(BookmarkLaunchLocation location) {
4468043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)  if (location == BOOKMARK_LAUNCH_LOCATION_DETACHED_BAR ||
4568043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)      location == BOOKMARK_LAUNCH_LOCATION_ATTACHED_BAR) {
4668043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)    content::RecordAction(
475d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)        base::UserMetricsAction("ClickedBookmarkBarAppsShortcutButton"));
4868043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)  }
4968043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)}
50