Chromium Code Reviews| Index: chrome/browser/extensions/api/i18n/i18n_api.h |
| diff --git a/chrome/browser/extensions/api/i18n/i18n_api.h b/chrome/browser/extensions/api/i18n/i18n_api.h |
| index 5863aaacf22c42625d43467e99cc5928bb968db7..5505f4e180d19d9a8f41bc8265012c0480fb4209 100644 |
| --- a/chrome/browser/extensions/api/i18n/i18n_api.h |
| +++ b/chrome/browser/extensions/api/i18n/i18n_api.h |
| @@ -5,8 +5,14 @@ |
| #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 "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; |
| @@ -18,6 +24,54 @@ class I18nGetAcceptLanguagesFunction : public ChromeSyncExtensionFunction { |
| DECLARE_EXTENSION_FUNCTION("i18n.getAcceptLanguages", I18N_GETACCEPTLANGUAGES) |
| }; |
| +class I18nDetectLanguageFunction : public UIThreadExtensionFunction { |
| + public: |
| + // Results returned by CLD |
| + struct DetectedLanguage { |
|
not at google - send to devlin
2015/07/10 16:21:09
You shouldn't need to make this public, and in fac
amalika
2015/07/10 18:18:36
I think we finally understand what you meant in th
not at google - send to devlin
2015/07/13 21:25:10
Yep you can typedef, but only in the .cc file (not
amalika
2015/07/13 23:57:01
Done.
|
| + DetectedLanguage(); |
| + DetectedLanguage(std::string language, int percentage); |
| + ~DetectedLanguage(); |
| + // Returns a new base::DictionaryValue representing the serialized form of |
| + // this LanguagesType object. |
| + scoped_ptr<base::DictionaryValue> ToValue() const; |
| + |
| + std::string language; |
| + int percentage; |
| + }; |
| + |
| + // LanguageDetectionResult object that holds detected langugae reliability and |
| + // array of DetectedLanguage |
| + struct LanguageDetectionResult { |
|
not at google - send to devlin
2015/07/10 16:21:09
You should be able to define this entirely in an a
amalika
2015/07/13 23:57:01
Acknowledged.
|
| + LanguageDetectionResult(); |
| + LanguageDetectionResult(bool is_reliable, |
|
not at google - send to devlin
2015/07/10 16:21:09
This is not the style we use, but running "git cl
amalika
2015/07/13 23:57:01
Done.
|
| + std::vector<linked_ptr<DetectedLanguage> > detected_langs); |
| + ~LanguageDetectionResult(); |
| + |
| + // Returns a new base::DictionaryValue representing the serialized form of |
| + // this Result object. |
| + scoped_ptr<base::DictionaryValue> ToValue() const; |
| + |
| + // CLD detected language reliability |
| + bool is_reliable; |
| + |
| + // array of detectedLanguage of size 1-3. The null is returned if |
| + // there were no languages detected |
| + std::vector<linked_ptr<DetectedLanguage> > detected_langs; |
|
not at google - send to devlin
2015/07/10 16:21:09
No space needed between "> >" anymore. Same goes f
amalika
2015/07/13 23:57:01
Done.
|
| + }; |
| + |
| + private: |
| + ~I18nDetectLanguageFunction() override {}; |
| + ResponseAction Run() override; |
| + void GetLanguage(const std::string& text); |
| + void SendLanguagesResult( |
| + std::vector<linked_ptr<DetectedLanguage> > detected_langs, |
| + bool is_reliable); |
| + void InitDetectedLanguages(CLD2::Language* langs, int* percent3, |
| + std::vector<linked_ptr<DetectedLanguage> >* detected_langs); |
| + |
| + DECLARE_EXTENSION_FUNCTION("i18n.detectLanguage", I18N_DETECTLANGUAGE) |
| +}; |
| + |
| } // namespace extensions |
| #endif // CHROME_BROWSER_EXTENSIONS_API_I18N_I18N_API_H_ |