#include "chrome/browser/default_browser/default_browser_monitor.h"
#include <windows.h>
#include <array>
#include <memory>
#include <string>
#include <string_view>
#include <vector>
#include "base/functional/bind.h"
#include "chrome/browser/win/registry_watcher.h"
namespace default_browser {
namespace {
constexpr std::array<std::wstring_view, 2> kDefaultBrowserSchemes = {
L"Software\\Microsoft\\Windows\\Shell\\Associations\\UrlAssociations\\http"
L"\\UserChoice",
L"Software\\Microsoft\\Windows\\Shell\\Associations\\UrlAssociations\\https"
L"\\UserChoice"};
}
void DefaultBrowserMonitor::StartMonitor() {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
registry_watcher_ = std::make_unique<RegistryWatcher>(
std::vector<std::wstring>(kDefaultBrowserSchemes.begin(),
kDefaultBrowserSchemes.end()),
base::BindOnce(&DefaultBrowserMonitor::OnDefaultBrowserChangedWin,
base::Unretained(this)));
}
void DefaultBrowserMonitor::OnDefaultBrowserChangedWin() {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
registry_watcher_.reset();
NotifyObservers();
StartMonitor();
}
}