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.h b/chrome/browser/ui/webui/help/version_updater.h
index 720569a..535ccd3 100644
--- a/chrome/browser/ui/webui/help/version_updater.h
+++ b/chrome/browser/ui/webui/help/version_updater.h
@@ -5,6 +5,7 @@
#ifndef CHROME_BROWSER_UI_WEBUI_HELP_VERSION_UPDATER_H_
#define CHROME_BROWSER_UI_WEBUI_HELP_VERSION_UPDATER_H_
+#include <memory>
#include <string>
#include "base/functional/callback.h"
@@ -90,7 +91,8 @@
// specialization. |web_contents| may be null, in which case any required UX
// (e.g., UAC to elevate on Windows) may not be associated with any existing
// browser windows.
- static VersionUpdater* Create(content::WebContents* web_contents);
+ static std::unique_ptr<VersionUpdater> Create(
+ content::WebContents* web_contents);
// Begins the update process by checking for update availability.
// |status_callback| is called for each status update. |promote_callback|
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>();
}
diff --git a/chrome/browser/ui/webui/help/version_updater_basic.h b/chrome/browser/ui/webui/help/version_updater_basic.h
deleted file mode 100644
index d950d1f..0000000
--- a/chrome/browser/ui/webui/help/version_updater_basic.h
+++ /dev/null
@@ -1,27 +0,0 @@
-// Copyright 2012 The Chromium Authors
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef CHROME_BROWSER_UI_WEBUI_HELP_VERSION_UPDATER_BASIC_H_
-#define CHROME_BROWSER_UI_WEBUI_HELP_VERSION_UPDATER_BASIC_H_
-
-#include "chrome/browser/ui/webui/help/version_updater.h"
-
-// 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;
-
- // VersionUpdater implementation.
- void CheckForUpdate(StatusCallback callback, PromoteCallback) override;
-
- protected:
- friend class VersionUpdater;
-
- // Clients must use VersionUpdater::Create().
- VersionUpdaterBasic() {}
- ~VersionUpdaterBasic() override {}
-};
-
-#endif // CHROME_BROWSER_UI_WEBUI_HELP_VERSION_UPDATER_BASIC_H_
diff --git a/chrome/browser/ui/webui/help/version_updater_chromeos.cc b/chrome/browser/ui/webui/help/version_updater_chromeos.cc
index 3a7526c..01038cf 100644
--- a/chrome/browser/ui/webui/help/version_updater_chromeos.cc
+++ b/chrome/browser/ui/webui/help/version_updater_chromeos.cc
@@ -5,11 +5,13 @@
#include "chrome/browser/ui/webui/help/version_updater_chromeos.h"
#include <cmath>
+#include <memory>
#include <optional>
#include <string>
#include "base/functional/bind.h"
#include "base/functional/callback_helpers.h"
+#include "base/memory/ptr_util.h"
#include "base/strings/string_number_conversions.h"
#include "chrome/browser/ash/login/startup_utils.h"
#include "chrome/browser/ash/login/wizard_controller.h"
@@ -133,8 +135,9 @@
} // namespace
-VersionUpdater* VersionUpdater::Create(content::WebContents* web_contents) {
- return new VersionUpdaterCros(web_contents);
+std::unique_ptr<VersionUpdater> VersionUpdater::Create(
+ content::WebContents* web_contents) {
+ return base::WrapUnique(new VersionUpdaterCros(web_contents));
}
void VersionUpdaterCros::GetUpdateStatus(StatusCallback callback) {
diff --git a/chrome/browser/ui/webui/help/version_updater_chromeos.h b/chrome/browser/ui/webui/help/version_updater_chromeos.h
index c7466622..cf809d24 100644
--- a/chrome/browser/ui/webui/help/version_updater_chromeos.h
+++ b/chrome/browser/ui/webui/help/version_updater_chromeos.h
@@ -19,8 +19,10 @@
class VersionUpdaterCros : public VersionUpdater,
public ash::UpdateEngineClient::Observer {
public:
+ explicit VersionUpdaterCros(content::WebContents* web_contents);
VersionUpdaterCros(const VersionUpdaterCros&) = delete;
VersionUpdaterCros& operator=(const VersionUpdaterCros&) = delete;
+ ~VersionUpdaterCros() override;
// VersionUpdater implementation.
void CheckForUpdate(StatusCallback callback, PromoteCallback) override;
@@ -40,13 +42,6 @@
// Gets the last update status, without triggering a new check or download.
void GetUpdateStatus(StatusCallback callback);
- protected:
- friend class VersionUpdater;
-
- // Clients must use VersionUpdater::Create().
- explicit VersionUpdaterCros(content::WebContents* web_contents);
- ~VersionUpdaterCros() override;
-
private:
// UpdateEngineClient::Observer implementation.
void UpdateStatusChanged(const update_engine::StatusResult& status) override;
diff --git a/chrome/browser/ui/webui/help/version_updater_chromeos_unittest.cc b/chrome/browser/ui/webui/help/version_updater_chromeos_unittest.cc
index 14a61d9..65919a3 100644
--- a/chrome/browser/ui/webui/help/version_updater_chromeos_unittest.cc
+++ b/chrome/browser/ui/webui/help/version_updater_chromeos_unittest.cc
@@ -50,9 +50,7 @@
protected:
VersionUpdaterCrosTest()
- : version_updater_(VersionUpdater::Create(nullptr)),
- version_updater_cros_ptr_(
- reinterpret_cast<VersionUpdaterCros*>(version_updater_.get())),
+ : version_updater_(std::make_unique<VersionUpdaterCros>(nullptr)),
fake_update_engine_client_(nullptr),
user_manager_enabler_(std::make_unique<FakeChromeUserManager>()) {}
@@ -97,8 +95,7 @@
content::BrowserTaskEnvironment task_environment_;
std::unique_ptr<ash::NetworkHandlerTestHelper> network_handler_test_helper_;
- std::unique_ptr<VersionUpdater> version_updater_;
- raw_ptr<VersionUpdaterCros, DanglingUntriaged> version_updater_cros_ptr_;
+ std::unique_ptr<VersionUpdaterCros> version_updater_;
raw_ptr<ash::FakeUpdateEngineClient, DanglingUntriaged>
fake_update_engine_client_; // Not owned.
@@ -201,7 +198,7 @@
// Expect the callback not to be called as it's an installation (not update).
StrictMock<base::MockCallback<VersionUpdater::StatusCallback>> mock_callback;
- version_updater_cros_ptr_->GetUpdateStatus(mock_callback.Get());
+ version_updater_->GetUpdateStatus(mock_callback.Get());
}
TEST_F(VersionUpdaterCrosTest, GetUpdateStatus_CallbackDuringUpdates) {
@@ -212,7 +209,7 @@
// Expect the callbac kto be called as it's an update status change.
StrictMock<base::MockCallback<VersionUpdater::StatusCallback>> mock_callback;
EXPECT_CALL(mock_callback, Run(_, _, _, _, _, _, _)).Times(1);
- version_updater_cros_ptr_->GetUpdateStatus(mock_callback.Get());
+ version_updater_->GetUpdateStatus(mock_callback.Get());
}
TEST_F(VersionUpdaterCrosTest,
@@ -228,7 +225,7 @@
StrictMock<base::MockCallback<VersionUpdater::StatusCallback>> mock_callback;
EXPECT_CALL(mock_callback, Run(VersionUpdater::UPDATED, 0, _, _, _, _, _))
.Times(1);
- version_updater_cros_ptr_->GetUpdateStatus(mock_callback.Get());
+ version_updater_->GetUpdateStatus(mock_callback.Get());
}
TEST_F(VersionUpdaterCrosTest, GetUpdateStatus_UpdatedButDeferred) {
@@ -244,7 +241,7 @@
StrictMock<base::MockCallback<VersionUpdater::StatusCallback>> mock_callback;
EXPECT_CALL(mock_callback, Run(VersionUpdater::DEFERRED, _, _, _, _, _, _))
.Times(1);
- version_updater_cros_ptr_->GetUpdateStatus(mock_callback.Get());
+ version_updater_->GetUpdateStatus(mock_callback.Get());
}
TEST_F(VersionUpdaterCrosTest, GetUpdateStatus_UpdatedNeedReboot) {
@@ -259,7 +256,7 @@
EXPECT_CALL(mock_callback,
Run(VersionUpdater::NEARLY_UPDATED, _, _, _, _, _, _))
.Times(1);
- version_updater_cros_ptr_->GetUpdateStatus(mock_callback.Get());
+ version_updater_->GetUpdateStatus(mock_callback.Get());
}
TEST_F(VersionUpdaterCrosTest,
@@ -279,7 +276,7 @@
Run(VersionUpdater::UPDATE_TO_ROLLBACK_VERSION_DISALLOWED, _, _,
_, _, _, _))
.Times(1);
- version_updater_cros_ptr_->GetUpdateStatus(mock_callback.Get());
+ version_updater_->GetUpdateStatus(mock_callback.Get());
}
TEST_F(VersionUpdaterCrosTest, ToggleFeature) {
@@ -296,8 +293,7 @@
StrictMock<base::MockCallback<VersionUpdater::IsFeatureEnabledCallback>>
mock_callback;
EXPECT_CALL(mock_callback, Run(_)).Times(1);
- version_updater_cros_ptr_->IsFeatureEnabled("feature-foo",
- mock_callback.Get());
+ version_updater_->IsFeatureEnabled("feature-foo", mock_callback.Get());
EXPECT_EQ(1, fake_update_engine_client_->is_feature_enabled_count());
}
@@ -309,7 +305,7 @@
fake_update_engine_client_->NotifyObserversThatStatusChanged(status);
EXPECT_EQ(0, fake_update_engine_client_->apply_deferred_update_count());
- version_updater_cros_ptr_->ApplyDeferredUpdate();
+ version_updater_->ApplyDeferredUpdate();
EXPECT_EQ(1, fake_update_engine_client_->apply_deferred_update_count());
}
diff --git a/chrome/browser/ui/webui/help/version_updater_mac.h b/chrome/browser/ui/webui/help/version_updater_mac.h
deleted file mode 100644
index 31ac6281..0000000
--- a/chrome/browser/ui/webui/help/version_updater_mac.h
+++ /dev/null
@@ -1,30 +0,0 @@
-// Copyright 2012 The Chromium Authors
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef CHROME_BROWSER_UI_WEBUI_HELP_VERSION_UPDATER_MAC_H_
-#define CHROME_BROWSER_UI_WEBUI_HELP_VERSION_UPDATER_MAC_H_
-
-#include "chrome/browser/ui/webui/help/version_updater.h"
-
-// macOS implementation of version update functionality, used by the WebUI
-// About/Help page.
-class VersionUpdaterMac : public VersionUpdater {
- public:
- VersionUpdaterMac(const VersionUpdaterMac&) = delete;
- VersionUpdaterMac& operator=(const VersionUpdaterMac&) = delete;
-
- // VersionUpdater implementation.
- void CheckForUpdate(StatusCallback status_callback,
- PromoteCallback promote_callback) override;
- void PromoteUpdater() override;
-
- protected:
- friend class VersionUpdater;
-
- // Clients must use VersionUpdater::Create().
- VersionUpdaterMac();
- ~VersionUpdaterMac() override;
-};
-
-#endif // CHROME_BROWSER_UI_WEBUI_HELP_VERSION_UPDATER_MAC_H_
diff --git a/chrome/browser/ui/webui/help/version_updater_mac.mm b/chrome/browser/ui/webui/help/version_updater_mac.mm
index bc581271..c390f80 100644
--- a/chrome/browser/ui/webui/help/version_updater_mac.mm
+++ b/chrome/browser/ui/webui/help/version_updater_mac.mm
@@ -2,11 +2,12 @@
// 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_mac.h"
+#include "chrome/browser/ui/webui/help/version_updater.h"
#import <Foundation/Foundation.h>
#include <algorithm>
+#include <memory>
#include <string>
#include <utility>
@@ -16,6 +17,7 @@
#include "base/functional/callback_helpers.h"
#include "base/logging.h"
#include "base/mac/authorization_util.h"
+#include "base/memory/ptr_util.h"
#include "base/memory/scoped_refptr.h"
#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
@@ -86,43 +88,49 @@
base::UTF8ToUTF16(err_message));
}
+// macOS implementation of version update functionality, used by the WebUI
+// About/Help page.
+class VersionUpdaterMac : public VersionUpdater {
+ public:
+ VersionUpdaterMac() = default;
+ VersionUpdaterMac(const VersionUpdaterMac&) = delete;
+ VersionUpdaterMac& operator=(const VersionUpdaterMac&) = delete;
+ ~VersionUpdaterMac() override = default;
+
+ // VersionUpdater implementation.
+ void CheckForUpdate(StatusCallback status_callback,
+ PromoteCallback promote_callback) override {
+ EnsureUpdater(
+ base::BindOnce(
+ [](PromoteCallback prompt) {
+ prompt.Run(PromotionState::PROMOTE_ENABLED);
+ },
+ promote_callback),
+ base::BindOnce(
+ [](base::RepeatingCallback<void(
+ const updater::UpdateService::UpdateState&)>
+ status_callback) {
+ base::ThreadPool::PostTaskAndReplyWithResult(
+ FROM_HERE, {base::MayBlock()},
+ base::BindOnce(&GetUpdaterScope),
+ base::BindOnce(
+ [](base::RepeatingCallback<void(
+ const updater::UpdateService::UpdateState&)>
+ status_callback,
+ updater::UpdaterScope scope) {
+ BrowserUpdaterClient::Create(scope)->CheckForUpdate(
+ status_callback);
+ },
+ status_callback));
+ },
+ base::BindRepeating(&UpdateStatus, status_callback)));
+ }
+ void PromoteUpdater() override { SetupSystemUpdater(); }
+};
+
} // namespace
-VersionUpdater* VersionUpdater::Create(
+std::unique_ptr<VersionUpdater> VersionUpdater::Create(
content::WebContents* /* web_contents */) {
- return new VersionUpdaterMac;
-}
-
-VersionUpdaterMac::VersionUpdaterMac() = default;
-
-VersionUpdaterMac::~VersionUpdaterMac() = default;
-
-void VersionUpdaterMac::CheckForUpdate(StatusCallback status_callback,
- PromoteCallback promote_callback) {
- EnsureUpdater(
- base::BindOnce(
- [](PromoteCallback prompt) {
- prompt.Run(PromotionState::PROMOTE_ENABLED);
- },
- promote_callback),
- base::BindOnce(
- [](base::RepeatingCallback<void(
- const updater::UpdateService::UpdateState&)> status_callback) {
- base::ThreadPool::PostTaskAndReplyWithResult(
- FROM_HERE, {base::MayBlock()}, base::BindOnce(&GetUpdaterScope),
- base::BindOnce(
- [](base::RepeatingCallback<void(
- const updater::UpdateService::UpdateState&)>
- status_callback,
- updater::UpdaterScope scope) {
- BrowserUpdaterClient::Create(scope)->CheckForUpdate(
- status_callback);
- },
- status_callback));
- },
- base::BindRepeating(&UpdateStatus, status_callback)));
-}
-
-void VersionUpdaterMac::PromoteUpdater() {
- SetupSystemUpdater();
+ return base::WrapUnique(new VersionUpdaterMac());
}
diff --git a/chrome/browser/ui/webui/help/version_updater_win.cc b/chrome/browser/ui/webui/help/version_updater_win.cc
index 4c966d07..fe488d67 100644
--- a/chrome/browser/ui/webui/help/version_updater_win.cc
+++ b/chrome/browser/ui/webui/help/version_updater_win.cc
@@ -2,7 +2,10 @@
// 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_win.h"
+#include "chrome/browser/ui/webui/help/version_updater.h"
+
+#include <memory>
+#include <string>
#include "base/functional/bind.h"
#include "base/memory/weak_ptr.h"
@@ -10,6 +13,7 @@
#include "base/win/win_util.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/first_run/upgrade_util.h"
+#include "chrome/browser/google/google_update_win.h"
#include "chrome/grit/generated_resources.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/web_contents.h"
@@ -18,100 +22,129 @@
#include "ui/base/l10n/l10n_util.h"
#include "ui/gfx/native_widget_types.h"
-VersionUpdaterWin::VersionUpdaterWin(gfx::AcceleratedWidget owner_widget)
- : owner_widget_(owner_widget), weak_factory_(this) {
-}
+namespace {
-VersionUpdaterWin::~VersionUpdaterWin() {
-}
+// Windows implementation of version update functionality, used by the WebUI
+// About/Help page.
+class VersionUpdaterWin : public VersionUpdater, public UpdateCheckDelegate {
+ public:
+ // |owner_widget| is the parent widget hosting the update check UI. Any UI
+ // needed to install an update (e.g., a UAC prompt for a system-level install)
+ // will be parented to this widget. |owner_widget| may be given a value of
+ // nullptr in which case the UAC prompt will be parented to the desktop.
+ explicit VersionUpdaterWin(gfx::AcceleratedWidget owner_widget)
+ : owner_widget_(owner_widget), weak_factory_(this) {}
-void VersionUpdaterWin::CheckForUpdate(StatusCallback callback,
- PromoteCallback) {
- // There is no supported integration with Google Update for Chromium.
- callback_ = std::move(callback);
+ VersionUpdaterWin(const VersionUpdaterWin&) = delete;
+ VersionUpdaterWin& operator=(const VersionUpdaterWin&) = delete;
- callback_.Run(CHECKING, 0, false, false, std::string(), 0, std::u16string());
- DoBeginUpdateCheck(false /* !install_update_if_possible */);
-}
+ ~VersionUpdaterWin() override = default;
-void VersionUpdaterWin::OnUpdateCheckComplete(
- const std::u16string& new_version) {
- DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
- if (new_version.empty()) {
- // Google Update says that no new version is available. Check to see if a
- // restart is needed for a previously-applied update to take effect.
- base::ThreadPool::PostTaskAndReplyWithResult(
- FROM_HERE, {base::MayBlock(), base::TaskPriority::USER_VISIBLE},
- base::BindOnce(&upgrade_util::IsUpdatePendingRestart),
- base::BindOnce(&VersionUpdaterWin::OnPendingRestartCheck,
- weak_factory_.GetWeakPtr()));
- // Early exit since callback_ will be Run in OnPendingRestartCheck.
- return;
+ // VersionUpdater:
+ void CheckForUpdate(StatusCallback callback, PromoteCallback) override {
+ // There is no supported integration with Google Update for Chromium.
+ callback_ = std::move(callback);
+
+ callback_.Run(CHECKING, 0, false, false, std::string(), 0,
+ std::u16string());
+ DoBeginUpdateCheck(false /* !install_update_if_possible */);
}
- // Notify the caller that the update is now beginning and initiate it.
- DoBeginUpdateCheck(true /* install_update_if_possible */);
- callback_.Run(UPDATING, 0, false, false, std::string(), 0, std::u16string());
-}
+ // UpdateCheckDelegate:
+ void OnUpdateCheckComplete(const std::u16string& new_version) override {
+ DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
+ if (new_version.empty()) {
+ // Google Update says that no new version is available. Check to see if a
+ // restart is needed for a previously-applied update to take effect.
+ base::ThreadPool::PostTaskAndReplyWithResult(
+ FROM_HERE, {base::MayBlock(), base::TaskPriority::USER_VISIBLE},
+ base::BindOnce(&upgrade_util::IsUpdatePendingRestart),
+ base::BindOnce(&VersionUpdaterWin::OnPendingRestartCheck,
+ weak_factory_.GetWeakPtr()));
+ // Early exit since callback_ will be Run in OnPendingRestartCheck.
+ return;
+ }
-void VersionUpdaterWin::OnUpgradeProgress(int progress,
- const std::u16string& new_version) {
- DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
- callback_.Run(UPDATING, progress, false, false, std::string(), 0,
- std::u16string());
-}
-
-void VersionUpdaterWin::OnUpgradeComplete(const std::u16string& new_version) {
- DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
- callback_.Run(NEARLY_UPDATED, 0, false, false, std::string(), 0,
- std::u16string());
-}
-
-void VersionUpdaterWin::OnError(GoogleUpdateErrorCode error_code,
- const std::u16string& html_error_message,
- const std::u16string& new_version) {
- DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
- std::u16string message;
- Status status = FAILED;
-
- switch (error_code) {
- case GOOGLE_UPDATE_DISABLED_BY_POLICY:
- status = DISABLED_BY_ADMIN;
- message =
- l10n_util::GetStringUTF16(IDS_UPGRADE_DISABLED_BY_POLICY);
- break;
- case GOOGLE_UPDATE_DISABLED_BY_POLICY_AUTO_ONLY:
- status = DISABLED_BY_ADMIN;
- message =
- l10n_util::GetStringUTF16(IDS_UPGRADE_DISABLED_BY_POLICY_MANUAL);
- break;
- default:
- // html_error_message mentions error_code so don't combine messages.
- if (html_error_message.empty()) {
- message = l10n_util::GetStringFUTF16Int(IDS_UPGRADE_ERROR, error_code);
- } else {
- message = l10n_util::GetStringFUTF16(
- IDS_ABOUT_BOX_ERROR_DURING_UPDATE_CHECK, html_error_message);
- }
- break;
+ // Notify the caller that the update is now beginning and initiate it.
+ DoBeginUpdateCheck(true /* install_update_if_possible */);
+ callback_.Run(UPDATING, 0, false, false, std::string(), 0,
+ std::u16string());
}
- callback_.Run(status, 0, false, false, std::string(), 0, message);
-}
-void VersionUpdaterWin::DoBeginUpdateCheck(bool install_update_if_possible) {
- // Disconnect from any previous attempts to avoid redundant callbacks.
- weak_factory_.InvalidateWeakPtrs();
- BeginUpdateCheck(g_browser_process->GetApplicationLocale(),
- install_update_if_possible, owner_widget_,
- weak_factory_.GetWeakPtr());
-}
+ void OnUpgradeProgress(int progress,
+ const std::u16string& new_version) override {
+ DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
+ callback_.Run(UPDATING, progress, false, false, std::string(), 0,
+ std::u16string());
+ }
-void VersionUpdaterWin::OnPendingRestartCheck(bool is_update_pending_restart) {
- callback_.Run(is_update_pending_restart ? NEARLY_UPDATED : UPDATED, 0, false,
- false, std::string(), 0, std::u16string());
-}
+ void OnUpgradeComplete(const std::u16string& new_version) override {
+ DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
+ callback_.Run(NEARLY_UPDATED, 0, false, false, std::string(), 0,
+ std::u16string());
+ }
-VersionUpdater* VersionUpdater::Create(content::WebContents* web_contents) {
+ void OnError(GoogleUpdateErrorCode error_code,
+ const std::u16string& html_error_message,
+ const std::u16string& new_version) override {
+ DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
+ std::u16string message;
+ Status status = FAILED;
+
+ switch (error_code) {
+ case GOOGLE_UPDATE_DISABLED_BY_POLICY:
+ status = DISABLED_BY_ADMIN;
+ message = l10n_util::GetStringUTF16(IDS_UPGRADE_DISABLED_BY_POLICY);
+ break;
+ case GOOGLE_UPDATE_DISABLED_BY_POLICY_AUTO_ONLY:
+ status = DISABLED_BY_ADMIN;
+ message =
+ l10n_util::GetStringUTF16(IDS_UPGRADE_DISABLED_BY_POLICY_MANUAL);
+ break;
+ default:
+ // html_error_message mentions error_code so don't combine messages.
+ if (html_error_message.empty()) {
+ message =
+ l10n_util::GetStringFUTF16Int(IDS_UPGRADE_ERROR, error_code);
+ } else {
+ message = l10n_util::GetStringFUTF16(
+ IDS_ABOUT_BOX_ERROR_DURING_UPDATE_CHECK, html_error_message);
+ }
+ break;
+ }
+ callback_.Run(status, 0, false, false, std::string(), 0, message);
+ }
+
+ private:
+ void DoBeginUpdateCheck(bool install_update_if_possible) {
+ // Disconnect from any previous attempts to avoid redundant callbacks.
+ weak_factory_.InvalidateWeakPtrs();
+ BeginUpdateCheck(g_browser_process->GetApplicationLocale(),
+ install_update_if_possible, owner_widget_,
+ weak_factory_.GetWeakPtr());
+ }
+
+ // A task run on the UI thread with the result of checking for a pending
+ // restart.
+ void OnPendingRestartCheck(bool is_update_pending_restart) {
+ callback_.Run(is_update_pending_restart ? NEARLY_UPDATED : UPDATED, 0,
+ false, false, std::string(), 0, std::u16string());
+ }
+
+ // The widget owning the UI for the update check.
+ gfx::AcceleratedWidget owner_widget_;
+
+ // Callback used to communicate update status to the client.
+ StatusCallback callback_;
+
+ // Used for callbacks.
+ base::WeakPtrFactory<VersionUpdaterWin> weak_factory_;
+};
+
+} // namespace
+
+std::unique_ptr<VersionUpdater> VersionUpdater::Create(
+ content::WebContents* web_contents) {
// Retrieve the HWND for the browser window that is hosting the update check.
// This will be used as the parent for a UAC prompt, if needed. It's possible
// this this window will no longer have focus by the time UAC is needed. In
@@ -126,6 +159,6 @@
// bar.
gfx::NativeWindow window = web_contents->GetTopLevelNativeWindow();
aura::WindowTreeHost* window_tree_host = window ? window->GetHost() : nullptr;
- return new VersionUpdaterWin(
+ return std::make_unique<VersionUpdaterWin>(
window_tree_host ? window_tree_host->GetAcceleratedWidget() : nullptr);
}
diff --git a/chrome/browser/ui/webui/help/version_updater_win.h b/chrome/browser/ui/webui/help/version_updater_win.h
deleted file mode 100644
index 09250ae..0000000
--- a/chrome/browser/ui/webui/help/version_updater_win.h
+++ /dev/null
@@ -1,60 +0,0 @@
-// Copyright 2015 The Chromium Authors
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-// Windows implementation of version update functionality, used by the WebUI
-// About/Help page.
-
-#ifndef CHROME_BROWSER_UI_WEBUI_HELP_VERSION_UPDATER_WIN_H_
-#define CHROME_BROWSER_UI_WEBUI_HELP_VERSION_UPDATER_WIN_H_
-
-#include <string>
-
-#include "base/memory/weak_ptr.h"
-#include "chrome/browser/google/google_update_win.h"
-#include "chrome/browser/ui/webui/help/version_updater.h"
-
-class VersionUpdaterWin : public VersionUpdater,
- public UpdateCheckDelegate {
- public:
- // |owner_widget| is the parent widget hosting the update check UI. Any UI
- // needed to install an update (e.g., a UAC prompt for a system-level install)
- // will be parented to this widget. |owner_widget| may be given a value of
- // nullptr in which case the UAC prompt will be parented to the desktop.
- explicit VersionUpdaterWin(gfx::AcceleratedWidget owner_widget);
-
- VersionUpdaterWin(const VersionUpdaterWin&) = delete;
- VersionUpdaterWin& operator=(const VersionUpdaterWin&) = delete;
-
- ~VersionUpdaterWin() override;
-
- // VersionUpdater:
- void CheckForUpdate(StatusCallback callback, PromoteCallback) override;
-
- // UpdateCheckDelegate:
- void OnUpdateCheckComplete(const std::u16string& new_version) override;
- void OnUpgradeProgress(int progress,
- const std::u16string& new_version) override;
- void OnUpgradeComplete(const std::u16string& new_version) override;
- void OnError(GoogleUpdateErrorCode error_code,
- const std::u16string& html_error_message,
- const std::u16string& new_version) override;
-
- private:
- void DoBeginUpdateCheck(bool install_update_if_possible);
-
- // A task run on the UI thread with the result of checking for a pending
- // restart.
- void OnPendingRestartCheck(bool is_update_pending_restart);
-
- // The widget owning the UI for the update check.
- gfx::AcceleratedWidget owner_widget_;
-
- // Callback used to communicate update status to the client.
- StatusCallback callback_;
-
- // Used for callbacks.
- base::WeakPtrFactory<VersionUpdaterWin> weak_factory_;
-};
-
-#endif // CHROME_BROWSER_UI_WEBUI_HELP_VERSION_UPDATER_WIN_H_