dom_distiller_features.cc 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. // Copyright 2015 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include "components/dom_distiller/core/dom_distiller_features.h"
  5. #include <string>
  6. #include "base/command_line.h"
  7. #include "base/metrics/field_trial_params.h"
  8. #include "components/dom_distiller/core/dom_distiller_switches.h"
  9. #include "components/dom_distiller/core/pref_names.h"
  10. #include "components/pref_registry/pref_registry_syncable.h"
  11. #include "components/prefs/pref_service.h"
  12. namespace dom_distiller {
  13. const base::Feature kReaderMode{"ReaderMode",
  14. base::FEATURE_DISABLED_BY_DEFAULT};
  15. void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry) {
  16. // Whether the reader mode option should be shown on distillable pages.
  17. registry->RegisterBooleanPref(
  18. dom_distiller::prefs::kOfferReaderMode, false,
  19. user_prefs::PrefRegistrySyncable::SYNCABLE_PREF);
  20. }
  21. bool IsDomDistillerEnabled() {
  22. return base::CommandLine::ForCurrentProcess()->HasSwitch(
  23. switches::kEnableDomDistiller) ||
  24. base::FeatureList::IsEnabled(kReaderMode);
  25. }
  26. bool OfferReaderModeInSettings() {
  27. if (!base::FeatureList::IsEnabled(kReaderMode))
  28. return false;
  29. // Check if the settings parameter is set.
  30. std::string parameter = base::GetFieldTrialParamValueByFeature(
  31. kReaderMode, switches::kReaderModeDiscoverabilityParamName);
  32. return parameter == switches::kReaderModeOfferInSettings;
  33. }
  34. bool ShowReaderModeOption(PrefService* pref_service) {
  35. if (OfferReaderModeInSettings())
  36. return pref_service->GetBoolean(prefs::kOfferReaderMode);
  37. return IsDomDistillerEnabled();
  38. }
  39. bool ShouldStartDistillabilityService() {
  40. return base::CommandLine::ForCurrentProcess()->HasSwitch(
  41. switches::kEnableDistillabilityService) ||
  42. base::FeatureList::IsEnabled(kReaderMode);
  43. }
  44. } // namespace dom_distiller