diff options
author | sidchat@chromium.org <sidchat@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-10-07 19:55:15 +0000 |
---|---|---|
committer | sidchat@chromium.org <sidchat@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-10-07 19:55:15 +0000 |
commit | 5ffc108781d1d439bb7800a38975c1d022044bee (patch) | |
tree | a8d0f00d494ab6ac3ad1e8e0b7dc511eef2d2992 /chrome/browser/renderer_host | |
parent | 5aae4c66b3b7343677c64c4291982822459f2cba (diff) | |
download | chromium_src-5ffc108781d1d439bb7800a38975c1d022044bee.zip chromium_src-5ffc108781d1d439bb7800a38975c1d022044bee.tar.gz chromium_src-5ffc108781d1d439bb7800a38975c1d022044bee.tar.bz2 |
Change detectLanguage() API to now return the top three languages as well their percentages. Added suitable unit testing to test that top three languages are returned as expected.
BUG=20666
TEST=none
Review URL: http://codereview.chromium.org/223010
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@28293 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/renderer_host')
-rw-r--r-- | chrome/browser/renderer_host/render_view_host.cc | 26 |
1 files changed, 21 insertions, 5 deletions
diff --git a/chrome/browser/renderer_host/render_view_host.cc b/chrome/browser/renderer_host/render_view_host.cc index fdc6d0e..c87fb8a 100644 --- a/chrome/browser/renderer_host/render_view_host.cc +++ b/chrome/browser/renderer_host/render_view_host.cc @@ -13,6 +13,7 @@ #include "base/json_reader.h" #include "base/string_util.h" #include "base/time.h" +#include "base/values.h" #include "base/waitable_event.h" #include "chrome/browser/child_process_security_policy.h" #include "chrome/browser/cross_site_request_manager.h" @@ -1121,14 +1122,29 @@ void RenderViewHost::OnDeterminePageTextReply( #if defined(OS_WIN) // Only for windows. int num_languages = 0; bool is_reliable = false; - const char* language_iso_code = LanguageCodeISO639_1( - DetectLanguageOfUnicodeText(page_text.c_str(), true, &is_reliable, - &num_languages, NULL)); - std::string language(language_iso_code); + Language language[3]; + int percent[3]; + int text_bytes; + DetectLanguageSummaryOfUnicodeText(page_text.c_str(), true, language, + percent, &text_bytes, &is_reliable); + + // The summary returns the top three languages. Put these languages and + // their corresponding percentages as a list of DictionaryValues objects. + scoped_ptr<ListValue> list_value(new ListValue()); + for (int i = 0; i < 3; i++) { + DictionaryValue* language_summary = new DictionaryValue(); + std::string language_string(LanguageCodeISO639_1(language[i])); + language_summary->Set(L"languageName", + Value::CreateStringValue(language_string)); + language_summary->Set(L"percentUsed", + Value::CreateIntegerValue(percent[i])); + list_value->Append(language_summary); + } + NotificationService::current()->Notify( NotificationType::TAB_LANGUAGE_DETERMINED, Source<RenderViewHost>(this), - Details<std::string>(&language)); + Details<ListValue>(list_value.get())); #endif } |