Add the Noop Site Data Writer to Performance Manager

PM copy of https://cs.chromium.org/chromium/src/chrome/browser/resource_coordinator/local_site_characteristics_noop_data_writer.h

Bug: 961336
Change-Id: Ic9c6f75119effa55f4e530554eb7b03bb0075dd3
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1627664
Commit-Queue: S├ębastien Marchand <sebmarchand@chromium.org>
Reviewed-by: Chris Hamilton <chrisha@chromium.org>
Cr-Commit-Position: refs/heads/master@{#663265}
diff --git a/chrome/browser/BUILD.gn b/chrome/browser/BUILD.gn
index 4f61fb9..50d69de 100644
--- a/chrome/browser/BUILD.gn
+++ b/chrome/browser/BUILD.gn
@@ -1097,6 +1097,8 @@
     "performance_manager/persistence/site_data/exponential_moving_average.cc",
     "performance_manager/persistence/site_data/exponential_moving_average.h",
     "performance_manager/persistence/site_data/feature_usage.h",
+    "performance_manager/persistence/site_data/noop_site_data_writer.cc",
+    "performance_manager/persistence/site_data/noop_site_data_writer.h",
     "performance_manager/persistence/site_data/site_data_impl.cc",
     "performance_manager/persistence/site_data/site_data_impl.h",
     "performance_manager/persistence/site_data/site_data_reader.cc",
diff --git a/chrome/browser/performance_manager/persistence/site_data/noop_site_data_writer.cc b/chrome/browser/performance_manager/persistence/site_data/noop_site_data_writer.cc
new file mode 100644
index 0000000..498dae3
--- /dev/null
+++ b/chrome/browser/performance_manager/persistence/site_data/noop_site_data_writer.cc
@@ -0,0 +1,35 @@
+// Copyright 2019 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/performance_manager/persistence/site_data/noop_site_data_writer.h"
+
+namespace performance_manager {
+
+NoopSiteDataWriter::~NoopSiteDataWriter() = default;
+
+void NoopSiteDataWriter::NotifySiteLoaded() {}
+
+void NoopSiteDataWriter::NotifySiteUnloaded() {}
+
+void NoopSiteDataWriter::NotifySiteVisibilityChanged(
+    performance_manager::TabVisibility visibility) {}
+
+void NoopSiteDataWriter::NotifyUpdatesFaviconInBackground() {}
+
+void NoopSiteDataWriter::NotifyUpdatesTitleInBackground() {}
+
+void NoopSiteDataWriter::NotifyUsesAudioInBackground() {}
+
+void NoopSiteDataWriter::NotifyUsesNotificationsInBackground() {}
+
+void NoopSiteDataWriter::NotifyLoadTimePerformanceMeasurement(
+    base::TimeDelta load_duration,
+    base::TimeDelta cpu_usage_estimate,
+    uint64_t private_footprint_kb_estimate) {}
+
+NoopSiteDataWriter::NoopSiteDataWriter()
+    : SiteDataWriter(nullptr, performance_manager::TabVisibility::kForeground) {
+}
+
+}  // namespace performance_manager
diff --git a/chrome/browser/performance_manager/persistence/site_data/noop_site_data_writer.h b/chrome/browser/performance_manager/persistence/site_data/noop_site_data_writer.h
new file mode 100644
index 0000000..0542377
--- /dev/null
+++ b/chrome/browser/performance_manager/persistence/site_data/noop_site_data_writer.h
@@ -0,0 +1,42 @@
+// Copyright 2019 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_PERFORMANCE_MANAGER_PERSISTENCE_SITE_DATA_NOOP_SITE_DATA_WRITER_H_
+#define CHROME_BROWSER_PERFORMANCE_MANAGER_PERSISTENCE_SITE_DATA_NOOP_SITE_DATA_WRITER_H_
+
+#include "base/macros.h"
+#include "chrome/browser/performance_manager/persistence/site_data/site_data_writer.h"
+
+namespace performance_manager {
+
+// Specialization of a SiteDataWriter that doesn't record anything.
+class NoopSiteDataWriter : public SiteDataWriter {
+ public:
+  ~NoopSiteDataWriter() override;
+
+  // Implementation of SiteDataWriter:
+  void NotifySiteLoaded() override;
+  void NotifySiteUnloaded() override;
+  void NotifySiteVisibilityChanged(
+      performance_manager::TabVisibility visibility) override;
+  void NotifyUpdatesFaviconInBackground() override;
+  void NotifyUpdatesTitleInBackground() override;
+  void NotifyUsesAudioInBackground() override;
+  void NotifyUsesNotificationsInBackground() override;
+  void NotifyLoadTimePerformanceMeasurement(
+      base::TimeDelta load_duration,
+      base::TimeDelta cpu_usage_estimate,
+      uint64_t private_footprint_kb_estimate) override;
+
+ private:
+  // Private constructor, these objects are meant to be created by a noop site
+  // data store.
+  NoopSiteDataWriter();
+
+  DISALLOW_COPY_AND_ASSIGN(NoopSiteDataWriter);
+};
+
+}  // namespace performance_manager
+
+#endif  // CHROME_BROWSER_PERFORMANCE_MANAGER_PERSISTENCE_SITE_DATA_NOOP_SITE_DATA_WRITER_H_
diff --git a/chrome/browser/performance_manager/persistence/site_data/site_data_writer.cc b/chrome/browser/performance_manager/persistence/site_data/site_data_writer.cc
index 65e5355..16b94e3 100644
--- a/chrome/browser/performance_manager/persistence/site_data/site_data_writer.cc
+++ b/chrome/browser/performance_manager/persistence/site_data/site_data_writer.cc
@@ -91,9 +91,7 @@
 SiteDataWriter::SiteDataWriter(
     scoped_refptr<internal::SiteDataImpl> impl,
     performance_manager::TabVisibility tab_visibility)
-    : impl_(std::move(impl)),
-      tab_visibility_(tab_visibility),
-      is_loaded_(false) {
+    : impl_(std::move(impl)), tab_visibility_(tab_visibility) {
   DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
 }
 
diff --git a/chrome/browser/performance_manager/persistence/site_data/site_data_writer.h b/chrome/browser/performance_manager/persistence/site_data/site_data_writer.h
index 23a1a9a..7ce97113 100644
--- a/chrome/browser/performance_manager/persistence/site_data/site_data_writer.h
+++ b/chrome/browser/performance_manager/persistence/site_data/site_data_writer.h
@@ -17,39 +17,40 @@
 // should be sent if/when the tab using it gets loaded.
 class SiteDataWriter {
  public:
-  ~SiteDataWriter();
+  virtual ~SiteDataWriter();
 
   // Records tab load/unload events.
-  void NotifySiteLoaded();
-  void NotifySiteUnloaded();
+  virtual void NotifySiteLoaded();
+  virtual void NotifySiteUnloaded();
 
   // Records visibility change events.
-  void NotifySiteVisibilityChanged(
+  virtual void NotifySiteVisibilityChanged(
       performance_manager::TabVisibility visibility);
 
   // Records feature usage.
-  void NotifyUpdatesFaviconInBackground();
-  void NotifyUpdatesTitleInBackground();
-  void NotifyUsesAudioInBackground();
-  void NotifyUsesNotificationsInBackground();
+  virtual void NotifyUpdatesFaviconInBackground();
+  virtual void NotifyUpdatesTitleInBackground();
+  virtual void NotifyUsesAudioInBackground();
+  virtual void NotifyUsesNotificationsInBackground();
 
   // Records performance measurements.
-  void NotifyLoadTimePerformanceMeasurement(
+  virtual void NotifyLoadTimePerformanceMeasurement(
       base::TimeDelta load_duration,
       base::TimeDelta cpu_usage_estimate,
       uint64_t private_footprint_kb_estimate);
 
   internal::SiteDataImpl* impl_for_testing() const { return impl_.get(); }
 
- private:
+ protected:
   friend class SiteDataWriterTest;
   friend class SiteDataStore;
 
-  // Private constructor, these objects are meant to be created by a site data
+  // Protected constructor, these objects are meant to be created by a site data
   // store.
   SiteDataWriter(scoped_refptr<internal::SiteDataImpl> impl,
                  performance_manager::TabVisibility tab_visibility);
 
+ private:
   // The SiteDataImpl object we delegate to.
   const scoped_refptr<internal::SiteDataImpl> impl_;
 
@@ -57,7 +58,7 @@
   performance_manager::TabVisibility tab_visibility_;
 
   // Indicates if the tab using this writer is loaded.
-  bool is_loaded_;
+  bool is_loaded_ = false;
 
   SEQUENCE_CHECKER(sequence_checker_);