Webui: Switch raw ptr to unique ptr.
The original plan was to just switch some "new" to "make_unique".
However, this doesn't work since the ctors and dtors of some of the
classes are protected.
Instead, I've made the ctors and dtors public (which also eliminated a
dangling raw ptr and reinterpret cast in one of the tests), and where
possible, restricted visibility by moving the subclasses into
anonymous namespaces.
This is a follow-up to an issue identified during review of https://crrev.com/c/5077326
Bug: 1504587
Change-Id: I7cdce9add337da35b28c8b94f7892ba68a6dab75
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5161007
Reviewed-by: Denis Kuznetsov <[email protected]>
Auto-Submit: Joshua Pawlicki <[email protected]>
Commit-Queue: Joshua Pawlicki <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1259829}
diff --git a/chrome/browser/ui/webui/help/version_updater_basic.cc b/chrome/browser/ui/webui/help/version_updater_basic.cc
index 5e6e9df..753c402 100644
--- a/chrome/browser/ui/webui/help/version_updater_basic.cc
+++ b/chrome/browser/ui/webui/help/version_updater_basic.cc
@@ -2,21 +2,35 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "chrome/browser/ui/webui/help/version_updater_basic.h"
+#include "chrome/browser/ui/webui/help/version_updater.h"
+#include <memory>
#include <string>
#include "chrome/browser/upgrade_detector/upgrade_detector.h"
-void VersionUpdaterBasic::CheckForUpdate(StatusCallback status_callback,
- PromoteCallback) {
- const Status status = UpgradeDetector::GetInstance()->is_upgrade_available()
- ? NEARLY_UPDATED
- : DISABLED;
- status_callback.Run(status, 0, false, false, std::string(), 0,
- std::u16string());
-}
+namespace {
-VersionUpdater* VersionUpdater::Create(content::WebContents* web_contents) {
- return new VersionUpdaterBasic;
+// Bare bones implementation just checks if a new version is ready.
+class VersionUpdaterBasic : public VersionUpdater {
+ public:
+ VersionUpdaterBasic(const VersionUpdaterBasic&) = delete;
+ VersionUpdaterBasic& operator=(const VersionUpdaterBasic&) = delete;
+ VersionUpdaterBasic() = default;
+ ~VersionUpdaterBasic() override = default;
+
+ // VersionUpdater implementation.
+ void CheckForUpdate(StatusCallback callback, PromoteCallback) override {
+ const Status status = UpgradeDetector::GetInstance()->is_upgrade_available()
+ ? NEARLY_UPDATED
+ : DISABLED;
+ callback.Run(status, 0, false, false, std::string(), 0, std::u16string());
+ }
+};
+
+} // namespace
+
+std::unique_ptr<VersionUpdater> VersionUpdater::Create(
+ content::WebContents* web_contents) {
+ return std::make_unique<VersionUpdaterBasic>();
}