prerender_histograms.h 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. // Copyright (c) 2012 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. #ifndef COMPONENTS_NO_STATE_PREFETCH_BROWSER_PRERENDER_HISTOGRAMS_H_
  5. #define COMPONENTS_NO_STATE_PREFETCH_BROWSER_PRERENDER_HISTOGRAMS_H_
  6. #include <stddef.h>
  7. #include <stdint.h>
  8. #include <string>
  9. #include "base/threading/thread_checker.h"
  10. #include "base/time/time.h"
  11. #include "components/no_state_prefetch/common/no_state_prefetch_final_status.h"
  12. #include "components/no_state_prefetch/common/prerender_origin.h"
  13. #include "url/gurl.h"
  14. namespace prerender {
  15. // Navigation type for histograms.
  16. enum NavigationType {
  17. // A normal completed navigation.
  18. NAVIGATION_TYPE_NORMAL,
  19. // A completed navigation or swap that began as a prerender.
  20. NAVIGATION_TYPE_PRERENDERED,
  21. };
  22. // Records histograms for NoStatePrefetchManager.
  23. //
  24. // A few histograms are dynamically constructed to avoid binary size bloat from
  25. // histogram_macros.h. Such histograms require careful handling:
  26. // 1. slow - make sure only rare events are recorded this way, a handful of such
  27. // events per page load should be OK
  28. // 2. may lead to small sporadic memory leaks in Histogram::Factory::Build() -
  29. // ensuring that they are recorded from the same thread is sufficient
  30. //
  31. // Besides thread checking this class is stateless, all public methods are
  32. // const.
  33. class PrerenderHistograms {
  34. public:
  35. // Owned by a NoStatePrefetchManager object for the lifetime of the
  36. // NoStatePrefetchManager.
  37. PrerenderHistograms();
  38. PrerenderHistograms(const PrerenderHistograms&) = delete;
  39. PrerenderHistograms& operator=(const PrerenderHistograms&) = delete;
  40. // Return the string to use as a prefix for histograms depending on the origin
  41. // of the prerender.
  42. static std::string GetHistogramPrefix(Origin origin);
  43. // Record a PerSessionCount data point.
  44. void RecordPerSessionCount(Origin origin, int count) const;
  45. // Record a final status of a prerendered page in a histogram.
  46. void RecordFinalStatus(Origin origin, FinalStatus final_status) const;
  47. // To be called when a new prerender is started.
  48. void RecordPrerenderStarted(Origin origin) const;
  49. // Record the histogram for number of bytes consumed by the prerender, and the
  50. // total number of bytes fetched for this profile since the last call to
  51. // RecordBytes.
  52. void RecordNetworkBytesConsumed(Origin origin,
  53. int64_t prerender_bytes,
  54. int64_t profile_bytes) const;
  55. // Records the time to first contentful paint with respect to a possible
  56. // prefetch of the page. The time to first contentful paint with respect to
  57. // the navigation start is recorded (even if the page was prererendered in
  58. // advance of navigation start). One of several histograms is used, depending
  59. // on whether this URL could have been prefetched before the navigation
  60. // leading to the paint.
  61. void RecordPrefetchFirstContentfulPaintTime(
  62. Origin origin,
  63. bool is_no_store,
  64. bool was_hidden,
  65. base::TimeDelta time,
  66. base::TimeDelta prefetch_age) const;
  67. private:
  68. THREAD_CHECKER(thread_checker_);
  69. };
  70. } // namespace prerender
  71. #endif // COMPONENTS_NO_STATE_PREFETCH_BROWSER_PRERENDER_HISTOGRAMS_H_