diff options
author | jcampan@chromium.org <jcampan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-01-07 21:41:50 +0000 |
---|---|---|
committer | jcampan@chromium.org <jcampan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-01-07 21:41:50 +0000 |
commit | 807cb1036f557b8e24306c66a6bac9bfb0c804af (patch) | |
tree | b10af2181ae1e2ce1640f868a217a868332ecc3e /chrome/browser/tab_contents/tab_contents.cc | |
parent | 462474b9444dcda47b5c140f5d31b790610b6176 (diff) | |
download | chromium_src-807cb1036f557b8e24306c66a6bac9bfb0c804af.zip chromium_src-807cb1036f557b8e24306c66a6bac9bfb0c804af.tar.gz chromium_src-807cb1036f557b8e24306c66a6bac9bfb0c804af.tar.bz2 |
Relanding the language detection code.
The code would crash if multiple PageContents notifications
were received rapidly. The CLDHelper now notifies the
TabContents directly and the TabContents ensures only one
language detection can be performed at a time.
Added unit-tests to validate these cases in web_contents_unittest.cc.
Note that patch set 1 is the original patch, patch set 2 contains the new changes.
Original review:
http://codereview.chromium.org/492024/show
BUG=30662
TEST=Run the unit-tests.
Review URL: http://codereview.chromium.org/504051
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@35735 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/tab_contents/tab_contents.cc')
-rw-r--r-- | chrome/browser/tab_contents/tab_contents.cc | 57 |
1 files changed, 53 insertions, 4 deletions
diff --git a/chrome/browser/tab_contents/tab_contents.cc b/chrome/browser/tab_contents/tab_contents.cc index 10efa22..e8275ce 100644 --- a/chrome/browser/tab_contents/tab_contents.cc +++ b/chrome/browser/tab_contents/tab_contents.cc @@ -369,6 +369,9 @@ TabContents::~TabContents() { UMA_HISTOGRAM_TIMES("Tab.Close", base::TimeTicks::Now() - tab_close_start_time_); } + + if (cld_helper_.get()) + cld_helper_->CancelLanguageDetection(); } // static @@ -637,6 +640,24 @@ void TabContents::Activate() { delegate_->ActivateContents(this); } +void TabContents::PageLanguageDetected() { + DCHECK(cld_helper_.get()); + + NavigationEntry* entry = controller_.GetActiveEntry(); + if (process()->id() == cld_helper_->renderer_process_id() && + entry && entry->page_id() == cld_helper_->page_id()) { + entry->set_language(cld_helper_->language()); + } + + std::string lang = cld_helper_->language(); + NotificationService::current()->Notify( + NotificationType::TAB_LANGUAGE_DETERMINED, + Source<RenderViewHost>(render_view_host()), + Details<std::string>(&lang)); + + cld_helper_ = NULL; // Release the CLD helper. +} + void TabContents::ShowContents() { if (render_widget_host_view()) render_widget_host_view()->DidBecomeSelected(); @@ -1076,10 +1097,6 @@ void TabContents::StopFinding(bool clear_selection) { render_view_host()->StopFinding(clear_selection); } -void TabContents::GetPageLanguage() { - render_view_host()->GetPageLanguage(); -} - void TabContents::OnSavePage() { // If we can not save the page, try to download it. if (!SavePackage::IsSavableContents(contents_mime_type())) { @@ -1735,6 +1752,38 @@ void TabContents::OnDidGetApplicationInfo( delegate()->OnDidGetApplicationInfo(this, page_id); } +void TabContents::OnPageContents(const GURL& url, + int renderer_process_id, + int32 page_id, + const std::wstring& contents) { + // Don't index any https pages. People generally don't want their bank + // accounts, etc. indexed on their computer, especially since some of these + // things are not marked cachable. + // TODO(brettw) we may want to consider more elaborate heuristics such as + // the cachability of the page. We may also want to consider subframes (this + // test will still index subframes if the subframe is SSL). + if (!url.SchemeIsSecure()) { + Profile* p = profile(); + if (p && !p->IsOffTheRecord()) { + HistoryService* hs = p->GetHistoryService(Profile::IMPLICIT_ACCESS); + if (hs) + hs->SetPageContents(url, contents); + } + } + + // Detect the page language. The detection happens on the file thread. + // PageLanguageDetected() is called when the language has been detected. + if (cld_helper_.get()) { + // There is already a language detection in flight, cancel it to avoid + // having multiple PageLanguageDetected() notifications on this tab. (They + // would cause a crasher as cld_helper_ would be NULLed on the 1st + // notification). + cld_helper_->CancelLanguageDetection(); + } + cld_helper_ = new CLDHelper(this, renderer_process_id, page_id, contents); + cld_helper_->DetectLanguage(); +} + void TabContents::DidStartProvisionalLoadForFrame( RenderViewHost* render_view_host, bool is_main_frame, |