experiments.cc 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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/experiments.h"
  5. #include "base/command_line.h"
  6. #include "base/metrics/field_trial.h"
  7. #include "base/notreached.h"
  8. #include "base/strings/string_util.h"
  9. #include "components/dom_distiller/core/dom_distiller_switches.h"
  10. namespace dom_distiller {
  11. DistillerHeuristicsType GetDistillerHeuristicsType() {
  12. // Get the field trial name first to ensure the experiment is initialized.
  13. const std::string group_name =
  14. base::FieldTrialList::FindFullName("ReaderModeUI");
  15. const std::string switch_value =
  16. base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
  17. switches::kReaderModeHeuristics);
  18. if (switch_value != "") {
  19. if (switch_value == switches::reader_mode_heuristics::kAdaBoost) {
  20. return DistillerHeuristicsType::ADABOOST_MODEL;
  21. }
  22. if (switch_value == switches::reader_mode_heuristics::kAllArticles) {
  23. return DistillerHeuristicsType::ALL_ARTICLES;
  24. }
  25. if (switch_value == switches::reader_mode_heuristics::kOGArticle) {
  26. return DistillerHeuristicsType::OG_ARTICLE;
  27. }
  28. if (switch_value == switches::reader_mode_heuristics::kAlwaysTrue) {
  29. return DistillerHeuristicsType::ALWAYS_TRUE;
  30. }
  31. if (switch_value == switches::reader_mode_heuristics::kNone) {
  32. return DistillerHeuristicsType::NONE;
  33. }
  34. NOTREACHED() << "Invalid value for " << switches::kReaderModeHeuristics;
  35. } else {
  36. if (base::StartsWith(group_name, "AdaBoost",
  37. base::CompareCase::INSENSITIVE_ASCII)) {
  38. return DistillerHeuristicsType::ADABOOST_MODEL;
  39. }
  40. if (base::StartsWith(group_name, "AllArticles",
  41. base::CompareCase::INSENSITIVE_ASCII)) {
  42. return DistillerHeuristicsType::ALL_ARTICLES;
  43. }
  44. if (base::StartsWith(group_name, "OGArticle",
  45. base::CompareCase::INSENSITIVE_ASCII)) {
  46. return DistillerHeuristicsType::OG_ARTICLE;
  47. }
  48. if (base::StartsWith(group_name, "Disabled",
  49. base::CompareCase::INSENSITIVE_ASCII)) {
  50. return DistillerHeuristicsType::NONE;
  51. }
  52. }
  53. return DistillerHeuristicsType::ADABOOST_MODEL;
  54. }
  55. } // namespace dom_distiller