Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2)

Side by Side Diff: chrome/browser/extensions/api/i18n/i18n_api.h

Issue 1208993011: New thin layer of API extension chrome.i18n.detectLanguage (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed issues and changes to functions due to added LanguageDetectionResult struct Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CHROME_BROWSER_EXTENSIONS_API_I18N_I18N_API_H_ 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_I18N_I18N_API_H_
6 #define CHROME_BROWSER_EXTENSIONS_API_I18N_I18N_API_H_ 6 #define CHROME_BROWSER_EXTENSIONS_API_I18N_I18N_API_H_
7 7
8 #include <string>
9 #include <vector>
10
8 #include "chrome/browser/extensions/chrome_extension_function.h" 11 #include "chrome/browser/extensions/chrome_extension_function.h"
9 #include "extensions/browser/browser_context_keyed_api_factory.h" 12 #include "extensions/browser/browser_context_keyed_api_factory.h"
13 #include "extensions/browser/extension_function.h"
14 #include "third_party/cld_2/src/public/compact_lang_det.h"
15 #include "third_party/cld_2/src/public/encodings.h"
10 16
11 class Profile; 17 class Profile;
12 18
13 namespace extensions { 19 namespace extensions {
14 20
15 class I18nGetAcceptLanguagesFunction : public ChromeSyncExtensionFunction { 21 class I18nGetAcceptLanguagesFunction : public ChromeSyncExtensionFunction {
16 ~I18nGetAcceptLanguagesFunction() override {} 22 ~I18nGetAcceptLanguagesFunction() override {}
17 bool RunSync() override; 23 bool RunSync() override;
18 DECLARE_EXTENSION_FUNCTION("i18n.getAcceptLanguages", I18N_GETACCEPTLANGUAGES) 24 DECLARE_EXTENSION_FUNCTION("i18n.getAcceptLanguages", I18N_GETACCEPTLANGUAGES)
19 }; 25 };
20 26
27 class I18nDetectLanguageFunction : public UIThreadExtensionFunction {
28 public:
29 // Results returned by CLD
30 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.
31 DetectedLanguage();
32 DetectedLanguage(std::string language, int percentage);
33 ~DetectedLanguage();
34 // Returns a new base::DictionaryValue representing the serialized form of
35 // this LanguagesType object.
36 scoped_ptr<base::DictionaryValue> ToValue() const;
37
38 std::string language;
39 int percentage;
40 };
41
42 // LanguageDetectionResult object that holds detected langugae reliability and
43 // array of DetectedLanguage
44 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.
45 LanguageDetectionResult();
46 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.
47 std::vector<linked_ptr<DetectedLanguage> > detected_langs);
48 ~LanguageDetectionResult();
49
50 // Returns a new base::DictionaryValue representing the serialized form of
51 // this Result object.
52 scoped_ptr<base::DictionaryValue> ToValue() const;
53
54 // CLD detected language reliability
55 bool is_reliable;
56
57 // array of detectedLanguage of size 1-3. The null is returned if
58 // there were no languages detected
59 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.
60 };
61
62 private:
63 ~I18nDetectLanguageFunction() override {};
64 ResponseAction Run() override;
65 void GetLanguage(const std::string& text);
66 void SendLanguagesResult(
67 std::vector<linked_ptr<DetectedLanguage> > detected_langs,
68 bool is_reliable);
69 void InitDetectedLanguages(CLD2::Language* langs, int* percent3,
70 std::vector<linked_ptr<DetectedLanguage> >* detected_langs);
71
72 DECLARE_EXTENSION_FUNCTION("i18n.detectLanguage", I18N_DETECTLANGUAGE)
73 };
74
21 } // namespace extensions 75 } // namespace extensions
22 76
23 #endif // CHROME_BROWSER_EXTENSIONS_API_I18N_I18N_API_H_ 77 #endif // CHROME_BROWSER_EXTENSIONS_API_I18N_I18N_API_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698