File: ntp_user_data_logger.cc

package info (click to toggle)
chromium 138.0.7204.183-1~deb12u1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm-proposed-updates
  • size: 6,080,960 kB
  • sloc: cpp: 34,937,079; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,954; asm: 946,768; xml: 739,971; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,811; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (506 lines) | stat: -rw-r--r-- 18,979 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
// Copyright 2013 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/browser/ui/search/ntp_user_data_logger.h"

#include <algorithm>
#include <string>

#include "base/logging.h"
#include "base/metrics/histogram_functions.h"
#include "base/metrics/histogram_macros.h"
#include "base/metrics/user_metrics.h"
#include "base/trace_event/trace_event.h"
#include "chrome/browser/after_startup_task_utils.h"
#include "chrome/browser/search/background/ntp_custom_background_service.h"
#include "chrome/browser/search/background/ntp_custom_background_service_factory.h"
#include "chrome/browser/search/search.h"
#include "chrome/browser/ui/search/ntp_user_data_types.h"
#include "chrome/common/pref_names.h"
#include "chrome/common/url_constants.h"
#include "components/ntp_tiles/metrics.h"
#include "components/prefs/pref_service.h"
#include "components/search/ntp_features.h"

namespace {

constexpr char kUIEventCategory[] = "ui";

// Logs CustomizedShortcutSettings on the NTP.
void LogCustomizedShortcutSettings(bool using_most_visited, bool is_visible) {
  CustomizedShortcutSettings setting;
  if (is_visible && using_most_visited) {
    setting =
        CustomizedShortcutSettings::CUSTOMIZED_SHORTCUT_SETTINGS_MOST_VISITED;
  } else if (is_visible && !using_most_visited) {
    setting =
        CustomizedShortcutSettings::CUSTOMIZED_SHORTCUT_SETTINGS_CUSTOM_LINKS;
  } else {
    setting = CustomizedShortcutSettings::CUSTOMIZED_SHORTCUT_SETTINGS_HIDDEN;
  }

  UMA_HISTOGRAM_ENUMERATION("NewTabPage.CustomizedShortcuts", setting);
}

// Converts |NTPLoggingEventType| to a |CustomizedFeature|.
CustomizedFeature LoggingEventToCustomizedFeature(NTPLoggingEventType event) {
  switch (event) {
    case NTP_BACKGROUND_CUSTOMIZED:
      return CustomizedFeature::CUSTOMIZED_FEATURE_BACKGROUND;
    case NTP_SHORTCUT_CUSTOMIZED:
      return CustomizedFeature::CUSTOMIZED_FEATURE_SHORTCUT;
    default:
      break;
  }

  NOTREACHED();
}

// Converts |NTPLoggingEventType| to a |CustomizeChromeBackgroundAction|.
CustomizeChromeBackgroundAction LoggingEventToCustomizeChromeBackgroundAction(
    NTPLoggingEventType event) {
  switch (event) {
    case NTP_CUSTOMIZE_CHROME_BACKGROUND_SELECT_COLLECTION:
      return CustomizeChromeBackgroundAction::
          CUSTOMIZE_CHROME_BACKGROUND_ACTION_SELECT_COLLECTION;
    case NTP_CUSTOMIZE_CHROME_BACKGROUND_SELECT_IMAGE:
      return CustomizeChromeBackgroundAction::
          CUSTOMIZE_CHROME_BACKGROUND_ACTION_SELECT_IMAGE;
    case NTP_CUSTOMIZE_CHROME_BACKGROUND_CANCEL:
      return CustomizeChromeBackgroundAction::
          CUSTOMIZE_CHROME_BACKGROUND_ACTION_CANCEL;
    case NTP_CUSTOMIZE_CHROME_BACKGROUND_DONE:
      return CustomizeChromeBackgroundAction::
          CUSTOMIZE_CHROME_BACKGROUND_ACTION_DONE;
    default:
      break;
  }

  NOTREACHED();
}

// Converts |NTPLoggingEventType| to a |CustomizeLocalImageBackgroundAction|.
CustomizeLocalImageBackgroundAction
LoggingEventToCustomizeLocalImageBackgroundAction(NTPLoggingEventType event) {
  switch (event) {
    case NTP_CUSTOMIZE_LOCAL_IMAGE_CANCEL:
      return CustomizeLocalImageBackgroundAction::
          CUSTOMIZE_LOCAL_IMAGE_BACKGROUND_ACTION_CANCEL;
    case NTP_CUSTOMIZE_LOCAL_IMAGE_DONE:
      return CustomizeLocalImageBackgroundAction::
          CUSTOMIZE_LOCAL_IMAGE_BACKGROUND_ACTION_DONE;
    default:
      break;
  }

  NOTREACHED();
}

// Converts |NTPLoggingEventType| to a |CustomizeShortcutAction|.
CustomizeShortcutAction LoggingEventToCustomizeShortcutAction(
    NTPLoggingEventType event) {
  switch (event) {
    case NTP_CUSTOMIZE_SHORTCUT_ADD:
      return CustomizeShortcutAction::CUSTOMIZE_SHORTCUT_ACTION_ADD;
    case NTP_CUSTOMIZE_SHORTCUT_UPDATE:
      return CustomizeShortcutAction::CUSTOMIZE_SHORTCUT_ACTION_UPDATE;
    case NTP_CUSTOMIZE_SHORTCUT_REMOVE:
      return CustomizeShortcutAction::CUSTOMIZE_SHORTCUT_ACTION_REMOVE;
    case NTP_CUSTOMIZE_SHORTCUT_CANCEL:
      return CustomizeShortcutAction::CUSTOMIZE_SHORTCUT_ACTION_CANCEL;
    case NTP_CUSTOMIZE_SHORTCUT_DONE:
      return CustomizeShortcutAction::CUSTOMIZE_SHORTCUT_ACTION_DONE;
    case NTP_CUSTOMIZE_SHORTCUT_UNDO:
      return CustomizeShortcutAction::CUSTOMIZE_SHORTCUT_ACTION_UNDO;
    case NTP_CUSTOMIZE_SHORTCUT_RESTORE_ALL:
      return CustomizeShortcutAction::CUSTOMIZE_SHORTCUT_ACTION_RESTORE_ALL;
    case NTP_CUSTOMIZE_SHORTCUT_TOGGLE_TYPE:
      return CustomizeShortcutAction::CUSTOMIZE_SHORTCUT_ACTION_TOGGLE_TYPE;
    case NTP_CUSTOMIZE_SHORTCUT_TOGGLE_VISIBILITY:
      return CustomizeShortcutAction::
          CUSTOMIZE_SHORTCUT_ACTION_TOGGLE_VISIBILITY;
    default:
      break;
  }

  NOTREACHED();
}

// Converts a richer picker background related |NTPLoggingEventType|
// to the corresponding UserAction string.
const char* LoggingEventToBackgroundUserActionName(NTPLoggingEventType event) {
  switch (event) {
    case NTP_BACKGROUND_UPLOAD_FROM_DEVICE:
      return "NTPRicherPicker.Backgrounds.UploadClicked";
    case NTP_BACKGROUND_OPEN_COLLECTION:
      return "NTPRicherPicker.Backgrounds.CollectionClicked";
    case NTP_BACKGROUND_SELECT_IMAGE:
      return "NTPRicherPicker.Backgrounds.BackgroundSelected";
    case NTP_BACKGROUND_IMAGE_SET:
      return "NTPRicherPicker.Backgrounds.BackgroundSet";
    case NTP_BACKGROUND_BACK_CLICK:
      return "NTPRicherPicker.Backgrounds.BackClicked";
    case NTP_BACKGROUND_DEFAULT_SELECTED:
      return "NTPRicherPicker.Backgrounds.DefaultSelected";
    case NTP_BACKGROUND_UPLOAD_CANCEL:
      return "NTPRicherPicker.Backgrounds.UploadCanceled";
    case NTP_BACKGROUND_UPLOAD_DONE:
      return "NTPRicherPicker.Backgrounds.UploadConfirmed";
    case NTP_BACKGROUND_IMAGE_RESET:
      return "NTPRicherPicker.Backgrounds.BackgroundReset";
    case NTP_BACKGROUND_REFRESH_TOGGLE_CLICKED:
      return "NTPRicherPicker.Backgrounds.RefreshToggleClicked";
    case NTP_BACKGROUND_DAILY_REFRESH_ENABLED:
      return "NTPRicherPicker.Backgrounds.DailyRefreshEnabled";
    default:
      NOTREACHED();
  }
}

// Converts a richer picker menu |NTPLoggingEventType| to the corresponding
// UserAction string.
const char* LoggingEventToMenuUserActionName(NTPLoggingEventType event) {
  switch (event) {
    case NTP_CUSTOMIZATION_MENU_OPENED:
      return "NTPRicherPicker.Opened";
    case NTP_CUSTOMIZATION_MENU_CANCEL:
      return "NTPRicherPicker.CancelClicked";
    case NTP_CUSTOMIZATION_MENU_DONE:
      return "NTPRicherPicker.DoneClicked";
    default:
      NOTREACHED();
  }
}

// Converts a richer picker shortcut related |NTPLoggingEventType| to the
// corresponding UserAction string.
const char* LoggingEventToShortcutUserActionName(NTPLoggingEventType event) {
  switch (event) {
    case NTP_CUSTOMIZE_SHORTCUT_CUSTOM_LINKS_CLICKED:
      return "NTPRicherPicker.Shortcuts.CustomLinksClicked";
    case NTP_CUSTOMIZE_SHORTCUT_MOST_VISITED_CLICKED:
      return "NTPRicherPicker.Shortcuts.MostVisitedClicked";
    case NTP_CUSTOMIZE_SHORTCUT_VISIBILITY_TOGGLE_CLICKED:
      return "NTPRicherPicker.Shortcuts.VisibilityToggleClicked";
    default:
      NOTREACHED();
  }
}

// This enum must match the numbering for NewTabPageLogoShown in enums.xml.
// Do not reorder or remove items, and only add new items before
// LOGO_IMPRESSION_TYPE_MAX.
enum LogoImpressionType {
  // Static Doodle image.
  LOGO_IMPRESSION_TYPE_STATIC = 0,
  // Call-to-action Doodle image.
  LOGO_IMPRESSION_TYPE_CTA = 1,

  LOGO_IMPRESSION_TYPE_MAX
};

// This enum must match the numbering for NewTabPageLogoClick in enums.xml.
// Do not reorder or remove items, and only add new items before
// LOGO_CLICK_TYPE_MAX.
enum LogoClickType {
  // Static Doodle image.
  LOGO_CLICK_TYPE_STATIC = 0,
  // Call-to-action Doodle image.
  LOGO_CLICK_TYPE_CTA = 1,
  // Animated Doodle image.
  LOGO_CLICK_TYPE_ANIMATED = 2,

  LOGO_CLICK_TYPE_MAX
};

// Converts |NTPLoggingEventType| to a |LogoClickType|, if the value
// is an error value. Otherwise, |LOGO_CLICK_TYPE_MAX| is returned.
LogoClickType LoggingEventToLogoClick(NTPLoggingEventType event) {
  switch (event) {
    case NTP_STATIC_LOGO_CLICKED:
      return LOGO_CLICK_TYPE_STATIC;
    case NTP_CTA_LOGO_CLICKED:
      return LOGO_CLICK_TYPE_CTA;
    case NTP_ANIMATED_LOGO_CLICKED:
      return LOGO_CLICK_TYPE_ANIMATED;
    default:
      NOTREACHED();
  }
}

}  // namespace

// Helper macro to log a load time to UMA. There's no good reason why we don't
// use one of the standard UMA_HISTORAM_*_TIMES macros, but all their ranges are
// different, and it's not worth changing all the existing histograms.
#define UMA_HISTOGRAM_LOAD_TIME(name, sample)                     \
  UMA_HISTOGRAM_CUSTOM_TIMES(name, sample, base::Milliseconds(1), \
                             base::Seconds(60), 100)

NTPUserDataLogger::NTPUserDataLogger(Profile* profile,
                                     const GURL& ntp_url,
                                     base::Time ntp_navigation_start_time)
    : during_startup_(!AfterStartupTaskUtils::IsBrowserStartupComplete()),
      ntp_url_(ntp_url),
      profile_(profile),
      // TODO(crbug.com/40811386): Migrate NTP navigation startup time
      // from base::Time to base::TimeTicks to avoid time glitches.
      ntp_navigation_start_time_(
          base::TimeTicks::UnixEpoch() +
          (ntp_navigation_start_time - base::Time::UnixEpoch())) {}

NTPUserDataLogger::~NTPUserDataLogger() = default;

// static
void NTPUserDataLogger::LogOneGoogleBarFetchDuration(
    bool success,
    const base::TimeDelta& duration) {
  DEPRECATED_UMA_HISTOGRAM_MEDIUM_TIMES(
      "NewTabPage.OneGoogleBar.RequestLatency", duration);
  if (success) {
    DEPRECATED_UMA_HISTOGRAM_MEDIUM_TIMES(
        "NewTabPage.OneGoogleBar.RequestLatency.Success", duration);
  } else {
    DEPRECATED_UMA_HISTOGRAM_MEDIUM_TIMES(
        "NewTabPage.OneGoogleBar.RequestLatency.Failure", duration);
  }
}

void NTPUserDataLogger::LogEvent(NTPLoggingEventType event,
                                 base::TimeDelta time) {
  if (!DefaultSearchProviderIsGoogle()) {
    return;
  }

  switch (event) {
    case NTP_STATIC_LOGO_SHOWN_FROM_CACHE:
      RecordDoodleImpression(time, /*is_cta=*/false, /*from_cache=*/true);
      break;
    case NTP_STATIC_LOGO_SHOWN_FRESH:
      RecordDoodleImpression(time, /*is_cta=*/false, /*from_cache=*/false);
      break;
    case NTP_CTA_LOGO_SHOWN_FROM_CACHE:
      RecordDoodleImpression(time, /*is_cta=*/true, /*from_cache=*/true);
      break;
    case NTP_CTA_LOGO_SHOWN_FRESH:
      RecordDoodleImpression(time, /*is_cta=*/true, /*from_cache=*/false);
      break;
    case NTP_STATIC_LOGO_CLICKED:
    case NTP_CTA_LOGO_CLICKED:
    case NTP_ANIMATED_LOGO_CLICKED:
      UMA_HISTOGRAM_ENUMERATION("NewTabPage.LogoClick",
                                LoggingEventToLogoClick(event),
                                LOGO_CLICK_TYPE_MAX);
      break;
    case NTP_ONE_GOOGLE_BAR_SHOWN:
      UMA_HISTOGRAM_LOAD_TIME("NewTabPage.OneGoogleBar.ShownTime", time);
      EmitNtpTraceEvent("NewTabPage.OneGoogleBar.ShownTime", time);

      break;
    case NTP_BACKGROUND_CUSTOMIZED:
    case NTP_SHORTCUT_CUSTOMIZED:
      UMA_HISTOGRAM_ENUMERATION("NewTabPage.Customized",
                                LoggingEventToCustomizedFeature(event));
      break;
    case NTP_CUSTOMIZE_CHROME_BACKGROUND_SELECT_COLLECTION:
    case NTP_CUSTOMIZE_CHROME_BACKGROUND_SELECT_IMAGE:
    case NTP_CUSTOMIZE_CHROME_BACKGROUND_CANCEL:
    case NTP_CUSTOMIZE_CHROME_BACKGROUND_DONE:
      UMA_HISTOGRAM_ENUMERATION(
          "NewTabPage.CustomizeChromeBackgroundAction",
          LoggingEventToCustomizeChromeBackgroundAction(event));
      break;
    case NTP_CUSTOMIZE_LOCAL_IMAGE_CANCEL:
    case NTP_CUSTOMIZE_LOCAL_IMAGE_DONE:
      UMA_HISTOGRAM_ENUMERATION(
          "NewTabPage.CustomizeLocalImageBackgroundAction",
          LoggingEventToCustomizeLocalImageBackgroundAction(event));
      break;
    case NTP_CUSTOMIZE_SHORTCUT_ADD:
    case NTP_CUSTOMIZE_SHORTCUT_UPDATE:
    case NTP_CUSTOMIZE_SHORTCUT_REMOVE:
    case NTP_CUSTOMIZE_SHORTCUT_CANCEL:
    case NTP_CUSTOMIZE_SHORTCUT_DONE:
    case NTP_CUSTOMIZE_SHORTCUT_UNDO:
    case NTP_CUSTOMIZE_SHORTCUT_RESTORE_ALL:
    case NTP_CUSTOMIZE_SHORTCUT_TOGGLE_TYPE:
    case NTP_CUSTOMIZE_SHORTCUT_TOGGLE_VISIBILITY:
      UMA_HISTOGRAM_ENUMERATION("NewTabPage.CustomizeShortcutAction",
                                LoggingEventToCustomizeShortcutAction(event));
      break;
    case NTP_MIDDLE_SLOT_PROMO_SHOWN:
      UMA_HISTOGRAM_LOAD_TIME("NewTabPage.Promos.ShownTime", time);
      EmitNtpTraceEvent("NewTabPage.Promos.ShownTime", time);

      break;
    case NTP_MIDDLE_SLOT_PROMO_LINK_CLICKED:
      UMA_HISTOGRAM_EXACT_LINEAR("NewTabPage.Promos.LinkClicked", 1, 1);
      break;
    case NTP_BACKGROUND_UPLOAD_FROM_DEVICE:
    case NTP_BACKGROUND_OPEN_COLLECTION:
    case NTP_BACKGROUND_SELECT_IMAGE:
    case NTP_BACKGROUND_IMAGE_SET:
    case NTP_BACKGROUND_BACK_CLICK:
    case NTP_BACKGROUND_DEFAULT_SELECTED:
    case NTP_BACKGROUND_UPLOAD_CANCEL:
    case NTP_BACKGROUND_UPLOAD_DONE:
    case NTP_BACKGROUND_IMAGE_RESET:
    case NTP_BACKGROUND_REFRESH_TOGGLE_CLICKED:
    case NTP_BACKGROUND_DAILY_REFRESH_ENABLED:
      RecordAction(LoggingEventToBackgroundUserActionName(event));
      break;
    case NTP_CUSTOMIZATION_MENU_OPENED:
    case NTP_CUSTOMIZATION_MENU_CANCEL:
    case NTP_CUSTOMIZATION_MENU_DONE:
      RecordAction(LoggingEventToMenuUserActionName(event));
      break;
    case NTP_CUSTOMIZE_SHORTCUT_CUSTOM_LINKS_CLICKED:
    case NTP_CUSTOMIZE_SHORTCUT_MOST_VISITED_CLICKED:
    case NTP_CUSTOMIZE_SHORTCUT_VISIBILITY_TOGGLE_CLICKED:
      RecordAction(LoggingEventToShortcutUserActionName(event));
      break;
    case NTP_APP_RENDERED:
      UMA_HISTOGRAM_LOAD_TIME("NewTabPage.MainUi.ShownTime", time);
      EmitNtpTraceEvent("NewTabPage.MainUi.ShownTime", time);
      break;
  }
}

void NTPUserDataLogger::LogMostVisitedLoaded(base::TimeDelta time,
                                             bool using_most_visited,
                                             bool is_visible) {
  EmitNtpStatistics(time, using_most_visited, is_visible);
}

void NTPUserDataLogger::LogMostVisitedImpression(
    const ntp_tiles::NTPTileImpression& impression) {
  if ((impression.index >= ntp_tiles::kMaxNumTiles) ||
      logged_impressions_[impression.index].has_value()) {
    return;
  }
  logged_impressions_[impression.index] = impression;
}

void NTPUserDataLogger::LogMostVisitedNavigation(
    const ntp_tiles::NTPTileImpression& impression) {
  ntp_tiles::metrics::RecordTileClick(impression);

  // Records the action. This will be available as a time-stamped stream
  // server-side and can be used to compute time-to-long-dwell.
  base::RecordAction(base::UserMetricsAction("MostVisited_Clicked"));
}

bool NTPUserDataLogger::DefaultSearchProviderIsGoogle() const {
  return search::DefaultSearchProviderIsGoogle(profile_);
}

bool NTPUserDataLogger::CustomBackgroundIsConfigured() const {
  return NtpCustomBackgroundServiceFactory::GetForProfile(profile_)
      ->IsCustomBackgroundSet();
}

void NTPUserDataLogger::EmitNtpStatistics(base::TimeDelta load_time,
                                          bool using_most_visited,
                                          bool is_visible) {
  // We only send statistics once per page.
  if (has_emitted_) {
    return;
  }

  int tiles_count = 0;
  for (const std::optional<ntp_tiles::NTPTileImpression>& impression :
       logged_impressions_) {
    if (!impression.has_value()) {
      break;
    }
    ntp_tiles::metrics::RecordTileImpression(*impression);
    ++tiles_count;
  }
  ntp_tiles::metrics::RecordPageImpression(tiles_count);

  DVLOG(1) << "Emitting NTP load time: " << load_time << ", "
           << "number of tiles: " << tiles_count;

  UMA_HISTOGRAM_LOAD_TIME("NewTabPage.LoadTime", load_time);
  UMA_HISTOGRAM_LOAD_TIME("NewTabPage.LoadTime.MostVisited", load_time);

  // Note: This could be inaccurate if the default search engine was changed
  // since the page load started. That's unlikely enough to not warrant special
  // handling.
  bool is_google = DefaultSearchProviderIsGoogle();

  // Split between NTP variants.
  if (ntp_url_ == GURL(chrome::kChromeUINewTabPageURL)) {
    UMA_HISTOGRAM_LOAD_TIME("NewTabPage.LoadTime.WebUINTP", load_time);
  } else if (ntp_url_ == GURL(chrome::kChromeUINewTabPageThirdPartyURL)) {
    UMA_HISTOGRAM_LOAD_TIME("NewTabPage.LoadTime.WebUI3PNTP", load_time);
  }

  // Split between Startup and non-startup.
  if (during_startup_) {
    UMA_HISTOGRAM_LOAD_TIME("NewTabPage.LoadTime.Startup", load_time);
  } else {
    UMA_HISTOGRAM_LOAD_TIME("NewTabPage.LoadTime.NewTab", load_time);
  }

  if (is_google) {
    LogCustomizedShortcutSettings(using_most_visited, is_visible);

    if (!using_most_visited) {
      UMA_HISTOGRAM_ENUMERATION(
          "NewTabPage.Customized",
          LoggingEventToCustomizedFeature(NTP_SHORTCUT_CUSTOMIZED));
    }

    if (CustomBackgroundIsConfigured()) {
      UMA_HISTOGRAM_ENUMERATION(
          "NewTabPage.Customized",
          LoggingEventToCustomizedFeature(NTP_BACKGROUND_CUSTOMIZED));
    }
  }

  has_emitted_ = true;
  during_startup_ = false;
}

void NTPUserDataLogger::EmitNtpTraceEvent(const char* event_name,
                                          base::TimeDelta duration) {
  TRACE_EVENT_NESTABLE_ASYNC_BEGIN_WITH_TIMESTAMP0(kUIEventCategory, event_name,
                                                   TRACE_ID_LOCAL(this),
                                                   ntp_navigation_start_time_);
  TRACE_EVENT_NESTABLE_ASYNC_END_WITH_TIMESTAMP0(
      kUIEventCategory, event_name, TRACE_ID_LOCAL(this),
      ntp_navigation_start_time_ + duration);
}

void NTPUserDataLogger::RecordDoodleImpression(base::TimeDelta time,
                                               bool is_cta,
                                               bool from_cache) {
  LogoImpressionType logo_type =
      is_cta ? LOGO_IMPRESSION_TYPE_CTA : LOGO_IMPRESSION_TYPE_STATIC;
  UMA_HISTOGRAM_ENUMERATION("NewTabPage.LogoShown", logo_type,
                            LOGO_IMPRESSION_TYPE_MAX);
  EmitNtpTraceEvent("NewTabPage.LogoShown", time);

  if (from_cache) {
    UMA_HISTOGRAM_ENUMERATION("NewTabPage.LogoShown.FromCache", logo_type,
                              LOGO_IMPRESSION_TYPE_MAX);
  } else {
    UMA_HISTOGRAM_ENUMERATION("NewTabPage.LogoShown.Fresh", logo_type,
                              LOGO_IMPRESSION_TYPE_MAX);
  }

  if (should_record_doodle_load_time_) {
    DEPRECATED_UMA_HISTOGRAM_MEDIUM_TIMES("NewTabPage.LogoShownTime2", time);
    should_record_doodle_load_time_ = false;
  }
}

void NTPUserDataLogger::RecordAction(const char* action) {
  if (!action || !DefaultSearchProviderIsGoogle()) {
    return;
  }

  base::RecordAction(base::UserMetricsAction(action));
}