OLD | NEW |
(Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 package org.chromium.chrome.browser.widget.bottomsheet; |
| 6 |
| 7 import org.chromium.base.metrics.RecordUserAction; |
| 8 import org.chromium.chrome.browser.widget.bottomsheet.BottomSheet.BottomSheetCon
tent; |
| 9 |
| 10 /** |
| 11 * Records user action and histograms related to the {@link BottomSheet}. |
| 12 */ |
| 13 public class BottomSheetMetrics extends EmptyBottomSheetObserver { |
| 14 private boolean mIsSheetOpen; |
| 15 private BottomSheetContent mLastContent; |
| 16 |
| 17 @Override |
| 18 public void onSheetOpened() { |
| 19 mIsSheetOpen = true; |
| 20 RecordUserAction.record("Android.ChromeHome.Opened"); |
| 21 } |
| 22 |
| 23 @Override |
| 24 public void onSheetClosed() { |
| 25 mIsSheetOpen = false; |
| 26 RecordUserAction.record("Android.ChromeHome.Closed"); |
| 27 } |
| 28 |
| 29 @Override |
| 30 public void onSheetStateChanged(int newState) { |
| 31 if (newState == BottomSheet.SHEET_STATE_HALF) { |
| 32 RecordUserAction.record("Android.ChromeHome.HalfState"); |
| 33 } else if (newState == BottomSheet.SHEET_STATE_FULL) { |
| 34 RecordUserAction.record("Android.ChromeHome.FullState"); |
| 35 } |
| 36 } |
| 37 |
| 38 @Override |
| 39 public void onSheetContentChanged(BottomSheetContent newContent) { |
| 40 // Return early if the sheet content is being set during initialization
(previous content |
| 41 // is null) or while the sheet is closed (sheet content being reset), so
that we only |
| 42 // record actions when the user explicitly takes an action. |
| 43 if (mLastContent == null || !mIsSheetOpen) { |
| 44 mLastContent = newContent; |
| 45 return; |
| 46 } |
| 47 |
| 48 if (newContent.getType() == BottomSheetContentController.TYPE_SUGGESTION
S) { |
| 49 RecordUserAction.record("Android.ChromeHome.ShowSuggestions"); |
| 50 } else if (newContent.getType() == BottomSheetContentController.TYPE_DOW
NLOADS) { |
| 51 RecordUserAction.record("Android.ChromeHome.ShowDownloads"); |
| 52 } else if (newContent.getType() == BottomSheetContentController.TYPE_BOO
KMARKS) { |
| 53 RecordUserAction.record("Android.ChromeHome.ShowBookmarks"); |
| 54 } else if (newContent.getType() == BottomSheetContentController.TYPE_HIS
TORY) { |
| 55 RecordUserAction.record("Android.ChromeHome.ShowHistory"); |
| 56 } else { |
| 57 assert false; |
| 58 } |
| 59 mLastContent = newContent; |
| 60 } |
| 61 |
| 62 } |
OLD | NEW |