Commit 01176aed authored by mgiuca's avatar mgiuca Committed by Commit bot

Revert of New thin layer of API extension chrome.i18n.detectLanguage (patchset...

Revert of New thin layer of API extension chrome.i18n.detectLanguage (patchset #11 id:300001 of https://codereview.chromium.org/1208993011)

Reason for revert:
Suspect that this increased the size of chrome.dll on Windows by 1.63 MB
(4%). Proactively reverting.

Original issue's description:
> New thin layer of API extension chrome.i18n.detectLanguage
>
> R=kalman@chromium.org, toyoshim@chromium.org
> BUG=
>
> Review URL: https://codereview.chromium.org/1208993011
>
> Cr-Commit-Position: refs/heads/master@{#339819}

TBR=amalika@google.com,toyoshim@chromium.org,kalman@chromium.org,asvitkine@chromium.org,rockot@chromium.org
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
BUG=512666

Review URL: https://codereview.chromium.org/1244343002

Cr-Commit-Position: refs/heads/master@{#339837}
parent f56afe12
......@@ -208,8 +208,4 @@ source_set("extensions") {
if (!use_ozone) {
sources -= [ "global_shortcut_listener_ozone.cc" ]
}
if (cld_version == 0 || cld_version == 2) {
deps += [ "//third_party/cld_2:cld2_platform_impl" ]
}
}
......@@ -5,7 +5,6 @@ include_rules = [
"+device/hid",
# Enable remote assistance on Chrome OS
"+remoting/host",
"+third_party/cld_2/src",
]
specific_include_rules = {
......
......@@ -35,11 +35,6 @@
'<(DEPTH)/components/components.gyp:drive_proto',
],
}],
['cld_version==0 or cld_version==2', {
'dependencies': [
'<(DEPTH)/third_party/cld_2/cld_2.gyp:cld2_platform_impl',
],
}],
],
},
],
......
......@@ -5,27 +5,23 @@
#include "chrome/browser/extensions/api/i18n/i18n_api.h"
#include <algorithm>
#include <string>
#include <vector>
#include "base/lazy_instance.h"
#include "base/prefs/pref_service.h"
#include "base/strings/string_piece.h"
#include "base/strings/string_split.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/common/extensions/api/i18n.h"
#include "chrome/common/pref_names.h"
#include "third_party/cld_2/src/internal/compact_lang_det_impl.h"
namespace extensions {
namespace GetAcceptLanguages = extensions::api::i18n::GetAcceptLanguages;
namespace GetAcceptLanguages = api::i18n::GetAcceptLanguages;
using DetectedLanguage =
api::i18n::DetectLanguage::Results::Result::LanguagesType;
using LanguageDetectionResult = api::i18n::DetectLanguage::Results::Result;
namespace extensions {
namespace {
// Max number of languages detected by CLD2.
const int kCldNumLangs = 3;
// Errors.
static const char kEmptyAcceptLanguagesError[] = "accept-languages is empty.";
......@@ -63,83 +59,4 @@ bool I18nGetAcceptLanguagesFunction::RunSync() {
return true;
}
ExtensionFunction::ResponseAction I18nDetectLanguageFunction::Run() {
scoped_ptr<api::i18n::DetectLanguage::Params> params(
api::i18n::DetectLanguage::Params::Create(*args_));
EXTENSION_FUNCTION_VALIDATE(params);
return RespondNow(ArgumentList(GetLanguage(params->text)));
}
scoped_ptr<base::ListValue> I18nDetectLanguageFunction::GetLanguage(
const std::string& text) {
// TODO(mcindy): improve this by providing better CLD hints
// asummed no cld hints is provided
CLD2::CLDHints cldhints = {
nullptr, "", CLD2::UNKNOWN_ENCODING, CLD2::UNKNOWN_LANGUAGE};
bool is_plain_text = true; // assume the text is a plain text
int flags = 0; // no flags, see compact_lang_det.h for details
int text_bytes; // amount of non-tag/letters-only text (assumed 0)
int valid_prefix_bytes; // amount of valid UTF8 character in the string
double normalized_score[kCldNumLangs];
CLD2::Language languages[kCldNumLangs];
int percents[kCldNumLangs];
bool is_reliable = false;
// populating languages and percents
int cld_language = CLD2::ExtDetectLanguageSummaryCheckUTF8(
text.c_str(), static_cast<int>(text.size()), is_plain_text, &cldhints,
flags, languages, percents, normalized_score,
nullptr, // assumed no ResultChunkVector is used
&text_bytes, &is_reliable, &valid_prefix_bytes);
// Check if non-UTF8 character is encountered
// See bug http://crbug.com/444258.
if (valid_prefix_bytes < static_cast<int>(text.size()) &&
cld_language == CLD2::UNKNOWN_LANGUAGE) {
// Detect Language upto before the first non-UTF8 character
CLD2::DetectLanguageSummaryV2(
text.c_str(), valid_prefix_bytes, is_plain_text, &cldhints,
true, // allow extended languages
flags, CLD2::UNKNOWN_LANGUAGE, languages, percents, normalized_score,
nullptr, // assumed no ResultChunkVector is used
&text_bytes, &is_reliable);
}
LanguageDetectionResult result;
result.is_reliable = is_reliable;
InitDetectedLanguages(languages, percents, &result.languages);
return api::i18n::DetectLanguage::Results::Create(result);
}
void I18nDetectLanguageFunction::InitDetectedLanguages(
CLD2::Language* languages,
int* percents,
std::vector<linked_ptr<DetectedLanguage>>* detected_languages) {
for (int i = 0; i < kCldNumLangs; i++) {
std::string language_code = "";
// Convert LanguageCode 'zh' to 'zh-CN' and 'zh-Hant' to 'zh-TW' for
// Translate server usage. see DetermineTextLanguage in
// components/translate/core/language_detection/language_detection_util.cc
if (languages[i] == CLD2::UNKNOWN_LANGUAGE) {
// no need to save in detected_languages
break;
} else if (languages[i] == CLD2::CHINESE) {
language_code = "zh-CN";
} else if (languages[i] == CLD2::CHINESE_T) {
language_code = "zh-TW";
} else {
language_code =
CLD2::LanguageCode(static_cast<CLD2::Language>(languages[i]));
}
linked_ptr<DetectedLanguage> detected_lang(new DetectedLanguage);
detected_lang->language = language_code;
detected_lang->percentage = percents[i];
detected_languages->push_back(detected_lang);
}
}
} // namespace extensions
......@@ -5,15 +5,8 @@
#ifndef CHROME_BROWSER_EXTENSIONS_API_I18N_I18N_API_H_
#define CHROME_BROWSER_EXTENSIONS_API_I18N_I18N_API_H_
#include <string>
#include <vector>
#include "chrome/browser/extensions/chrome_extension_function.h"
#include "chrome/common/extensions/api/i18n.h"
#include "extensions/browser/browser_context_keyed_api_factory.h"
#include "extensions/browser/extension_function.h"
#include "third_party/cld_2/src/public/compact_lang_det.h"
#include "third_party/cld_2/src/public/encodings.h"
class Profile;
......@@ -25,24 +18,6 @@ class I18nGetAcceptLanguagesFunction : public ChromeSyncExtensionFunction {
DECLARE_EXTENSION_FUNCTION("i18n.getAcceptLanguages", I18N_GETACCEPTLANGUAGES)
};
class I18nDetectLanguageFunction : public UIThreadExtensionFunction {
private:
~I18nDetectLanguageFunction() override{};
// UIThreadExtensionFunction:
ResponseAction Run() override;
scoped_ptr<base::ListValue> GetLanguage(const std::string& text);
void InitDetectedLanguages(
CLD2::Language* langs,
int* percent3,
std::vector<linked_ptr<
api::i18n::DetectLanguage::Results::Result::LanguagesType>>*
detected_langs);
DECLARE_EXTENSION_FUNCTION("i18n.detectLanguage", I18N_DETECTLANGUAGE)
};
} // namespace extensions
#endif // CHROME_BROWSER_EXTENSIONS_API_I18N_I18N_API_H_
......@@ -6,13 +6,7 @@
{
"namespace": "i18n",
"description": "Use the <code>chrome.i18n</code> infrastructure to implement internationalization across your whole app or extension.",
"types": [
{
"id": "LanguageCode",
"type": "string",
"description": "An ISO language code such as <code>en</code> or <code>fr</code>. For a complete list of languages supported by this method, see <a href='http://src.chromium.org/viewvc/chrome/trunk/src/third_party/cld/languages/internal/languages.cc'>kLanguageInfoTable</a>."
}
],
"types": [],
"functions": [
{
"name": "getAcceptLanguages",
......@@ -23,7 +17,7 @@
"type": "function",
"name": "callback",
"parameters": [
{"name": "languages", "type": "array", "items": {"$ref": "LanguageCode"}, "description": "Array of LanguageCode"}
{"name": "languages", "type": "array", "items": {"type": "string"}, "description": "Array of the accept languages of the browser, such as en-US,en,zh-CN"}
]
}
]
......@@ -61,57 +55,8 @@
"type": "string",
"description": "The browser UI language code such as en-US or fr-FR."
}
},
{
"name": "detectLanguage",
"type": "function",
"description": "Detects the language of the provided text using CLD.",
"parameters": [
{
"type": "string",
"name": "text",
"minimum": 0,
"description": "User input string to be translated."
},
{
"type": "function",
"name": "callback",
"parameters": [
{
"type": "object",
"name": "result",
"description": "LanguageDetectionResult object that holds detected langugae reliability and array of DetectedLanguage",
"properties": {
"isReliable": { "type": "boolean", "description": "CLD detected language reliability" },
"languages":
{
"type": "array",
"description": "array of detectedLanguage of size 0-3",
"items":
{
"type": "object",
"description": "DetectedLanguage object that holds detected ISO language code and its percentage in the input string",
"properties":
{
"language":
{
"$ref": "LanguageCode"
},
"percentage":
{
"type": "integer",
"description": "The percentage of the detected language"
}
}
}
}
}
}
]
}
]
}
],
"events": []
}
]
\ No newline at end of file
]
......@@ -1130,7 +1130,6 @@ enum HistogramValue {
LANGUAGESETTINGSPRIVATE_ADDINPUTMETHOD,
LANGUAGESETTINGSPRIVATE_REMOVEINPUTMETHOD,
FILEMANAGERPRIVATE_CANCELALLFILETRANSFERS,
I18N_DETECTLANGUAGE,
// Last entry: Add new entries above, then run:
// python tools/metrics/histograms/update_extension_histograms.py
ENUM_BOUNDARY
......
......@@ -56498,7 +56498,6 @@ http://cs/file:chrome/histograms.xml - but prefer this file for new entries.
<int value="1069" label="LANGUAGESETTINGSPRIVATE_ADDINPUTMETHOD"/>
<int value="1070" label="LANGUAGESETTINGSPRIVATE_REMOVEINPUTMETHOD"/>
<int value="1071" label="FILEMANAGERPRIVATE_CANCELALLFILETRANSFERS"/>
<int value="1072" label="I18N_DETECTLANGUAGE"/>
</enum>
<enum name="ExtensionInstallCause" type="int">
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment