diff options
author | rouslan <rouslan@chromium.org> | 2015-10-08 11:44:42 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-10-08 18:45:22 +0000 |
commit | 16fc75c80eda6f80f09c55c0cebe7d62b6585c24 (patch) | |
tree | bcf8abe13d5189948c2283a6dc8e1918da7f6c82 /chrome/common | |
parent | cb0b75575e1ebab71e76aaeb8784c18f95c0c145 (diff) | |
download | chromium_src-16fc75c80eda6f80f09c55c0cebe7d62b6585c24.zip chromium_src-16fc75c80eda6f80f09c55c0cebe7d62b6585c24.tar.gz chromium_src-16fc75c80eda6f80f09c55c0cebe7d62b6585c24.tar.bz2 |
Enable multilingual spellcheck by default.
This patch enables multilingual spellcheck by default with an option to
disable it on demand via field trial.
BUG=5102
Review URL: https://codereview.chromium.org/1389153002
Cr-Commit-Position: refs/heads/master@{#353107}
Diffstat (limited to 'chrome/common')
-rw-r--r-- | chrome/common/OWNERS | 4 | ||||
-rw-r--r-- | chrome/common/chrome_switches.cc | 4 | ||||
-rw-r--r-- | chrome/common/chrome_switches.h | 1 | ||||
-rw-r--r-- | chrome/common/spellcheck_common.cc | 21 | ||||
-rw-r--r-- | chrome/common/spellcheck_common.h | 3 | ||||
-rw-r--r-- | chrome/common/spellcheck_common_unittest.cc | 51 |
6 files changed, 80 insertions, 4 deletions
diff --git a/chrome/common/OWNERS b/chrome/common/OWNERS index 3a447e2..a6396e5 100644 --- a/chrome/common/OWNERS +++ b/chrome/common/OWNERS @@ -27,8 +27,8 @@ per-file *_messages*.h=wfh@chromium.org # Spellcheck files. Not using spellcheck* since it covers IPC messages too. per-file spellcheck_bdict_language.h=groby@chromium.org per-file spellcheck_bdict_language.h=rouslan@chromium.org -per-file spellcheck_common.*=groby@chromium.org -per-file spellcheck_common.*=rouslan@chromium.org +per-file spellcheck_common*=groby@chromium.org +per-file spellcheck_common*=rouslan@chromium.org per-file spellcheck_marker.h=groby@chromium.org per-file spellcheck_marker.h=rouslan@chromium.org per-file spellcheck_result.h=groby@chromium.org diff --git a/chrome/common/chrome_switches.cc b/chrome/common/chrome_switches.cc index f82b2f1..189ab43 100644 --- a/chrome/common/chrome_switches.cc +++ b/chrome/common/chrome_switches.cc @@ -1027,6 +1027,10 @@ const char kSpeculativeResourcePrefetchingEnabled[] = "enabled"; const char kEnableAndroidSpellChecker[] = "enable-android-spellchecker"; #endif +// Disables the multilingual spellchecker. +const char kDisableMultilingualSpellChecker[] = + "disable-multilingual-spellchecker"; + // Enables the multilingual spellchecker. const char kEnableMultilingualSpellChecker[] = "enable-multilingual-spellchecker"; diff --git a/chrome/common/chrome_switches.h b/chrome/common/chrome_switches.h index f66b3d3..7c5691d 100644 --- a/chrome/common/chrome_switches.h +++ b/chrome/common/chrome_switches.h @@ -286,6 +286,7 @@ extern const char kSpeculativeResourcePrefetchingLearning[]; #if defined(OS_ANDROID) extern const char kEnableAndroidSpellChecker[]; #endif +extern const char kDisableMultilingualSpellChecker[]; extern const char kEnableMultilingualSpellChecker[]; extern const char kEnableSpellingAutoCorrect[]; extern const char kEnableSpellingFeedbackFieldTrial[]; diff --git a/chrome/common/spellcheck_common.cc b/chrome/common/spellcheck_common.cc index 9aa3a02..cee0883 100644 --- a/chrome/common/spellcheck_common.cc +++ b/chrome/common/spellcheck_common.cc @@ -8,6 +8,8 @@ #include "base/files/file_path.h" #include "base/logging.h" #include "base/macros.h" +#include "base/metrics/field_trial.h" +#include "base/strings/string_util.h" #include "chrome/common/chrome_switches.h" #include "third_party/icu/source/common/unicode/uloc.h" #include "third_party/icu/source/common/unicode/urename.h" @@ -16,6 +18,8 @@ namespace chrome { namespace spellcheck_common { +const char kMultilingualSpellcheckFieldTrial[] = "MultilingualSpellcheck"; + struct LanguageRegion { const char* language; // The language. const char* language_region; // language & region, used by dictionaries. @@ -184,8 +188,21 @@ void GetISOLanguageCountryCodeFromLocale(const std::string& locale, } bool IsMultilingualSpellcheckEnabled() { - return base::CommandLine::ForCurrentProcess()->HasSwitch( - switches::kEnableMultilingualSpellChecker); + // TODO(rouslan): Remove field trial and command line flags when M49 is + // stable. + const std::string& group_name = + base::FieldTrialList::FindFullName(kMultilingualSpellcheckFieldTrial); + if (base::CommandLine::ForCurrentProcess()->HasSwitch( + switches::kDisableMultilingualSpellChecker)) { + return false; + } + if (base::CommandLine::ForCurrentProcess()->HasSwitch( + switches::kEnableMultilingualSpellChecker)) { + return true; + } + // Enabled by default, but can be disabled in field trial. + return !base::StartsWith(group_name, "Disabled", + base::CompareCase::INSENSITIVE_ASCII); } } // namespace spellcheck_common diff --git a/chrome/common/spellcheck_common.h b/chrome/common/spellcheck_common.h index 7254c8c..deb3617 100644 --- a/chrome/common/spellcheck_common.h +++ b/chrome/common/spellcheck_common.h @@ -39,6 +39,9 @@ static const size_t MAX_SYNCABLE_DICTIONARY_WORDS = 1300; // dictionary. static const size_t MAX_CUSTOM_DICTIONARY_WORD_BYTES = 99; +// The name of the field trial for multilingual spellchecker. +extern const char kMultilingualSpellcheckFieldTrial[]; + base::FilePath GetVersionedFileName(const std::string& input_language, const base::FilePath& dict_dir); diff --git a/chrome/common/spellcheck_common_unittest.cc b/chrome/common/spellcheck_common_unittest.cc new file mode 100644 index 0000000..4f877c5 --- /dev/null +++ b/chrome/common/spellcheck_common_unittest.cc @@ -0,0 +1,51 @@ +// Copyright 2015 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome/common/spellcheck_common.h" + +#include "base/command_line.h" +#include "base/metrics/field_trial.h" +#include "chrome/common/chrome_switches.h" +#include "components/variations/entropy_provider.h" +#include "testing/gtest/include/gtest/gtest.h" + +namespace { + +using chrome::spellcheck_common::IsMultilingualSpellcheckEnabled; +using chrome::spellcheck_common::kMultilingualSpellcheckFieldTrial; + +TEST(SpellcheckCommonTest, MultilingualByDefault) { + EXPECT_TRUE(IsMultilingualSpellcheckEnabled()); +} + +TEST(SpellcheckCommonTest, CanDisableMultlingualInFieldTrial) { + base::FieldTrialList trials(new metrics::SHA1EntropyProvider("foo")); + scoped_refptr<base::FieldTrial> trial = + base::FieldTrialList::CreateFieldTrial(kMultilingualSpellcheckFieldTrial, + "Disabled"); + trial->group(); + + EXPECT_FALSE(IsMultilingualSpellcheckEnabled()); +} + +TEST(SpellcheckCommonTest, CanDisableMultlingualFromCommandLine) { + base::CommandLine::ForCurrentProcess()->AppendSwitch( + switches::kDisableMultilingualSpellChecker); + + EXPECT_FALSE(IsMultilingualSpellcheckEnabled()); +} + +TEST(SpellcheckCommonTest, CanForceMultlingualFromCommandLine) { + base::FieldTrialList trials(new metrics::SHA1EntropyProvider("foo")); + scoped_refptr<base::FieldTrial> trial = + base::FieldTrialList::CreateFieldTrial(kMultilingualSpellcheckFieldTrial, + "Disabled"); + trial->group(); + base::CommandLine::ForCurrentProcess()->AppendSwitch( + switches::kEnableMultilingualSpellChecker); + + EXPECT_TRUE(IsMultilingualSpellcheckEnabled()); +} + +} // namespace |