blob: e1ad7a503c462090d2fe8588b6ec4994adbf9254 [file] [log] [blame]
// Copyright 2022 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/download/bubble/download_bubble_prefs.h"
#include "chrome/browser/download/download_core_service.h"
#include "chrome/browser/download/download_core_service_factory.h"
#include "chrome/browser/headless/headless_mode_util.h"
#include "chrome/common/pref_names.h"
#include "components/prefs/pref_service.h"
namespace download {
bool ShouldShowDownloadBubble(Profile* profile) {
// There is no need to display download bubble in headless mode. This prevents
// http://crbug.com/379994807 but also makes sense on other platforms.
if (headless::IsHeadlessMode()) {
return false;
}
// If the download UI is disabled by at least one extension, do not show the
// bubble and the toolbar icon.
return DownloadCoreServiceFactory::GetForBrowserContext(
profile->GetOriginalProfile())
->IsDownloadUiEnabled();
}
bool IsDownloadBubblePartialViewEnabled(Profile* profile) {
return profile->GetPrefs()->GetBoolean(
prefs::kDownloadBubblePartialViewEnabled);
}
void SetDownloadBubblePartialViewEnabled(Profile* profile, bool enabled) {
profile->GetPrefs()->SetBoolean(prefs::kDownloadBubblePartialViewEnabled,
enabled);
}
bool IsDownloadBubblePartialViewEnabledDefaultPrefValue(Profile* profile) {
return profile->GetPrefs()
->FindPreference(prefs::kDownloadBubblePartialViewEnabled)
->IsDefaultValue();
}
int DownloadBubblePartialViewImpressions(Profile* profile) {
return profile->GetPrefs()->GetInteger(
prefs::kDownloadBubblePartialViewImpressions);
}
void SetDownloadBubblePartialViewImpressions(Profile* profile, int count) {
profile->GetPrefs()->SetInteger(prefs::kDownloadBubblePartialViewImpressions,
count);
}
} // namespace download