| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef CHROME_BROWSER_CLD_HELPER_H_ | |
| 6 #define CHROME_BROWSER_CLD_HELPER_H_ | |
| 7 | |
| 8 #include <string> | |
| 9 | |
| 10 #include "base/ref_counted.h" | |
| 11 | |
| 12 class TabContents; | |
| 13 | |
| 14 // The CLDHelper class detects the language of a page, using the toolbar CLD | |
| 15 // library. (CLD stands for Compact Language Detection.) | |
| 16 // It should be created and the detection process started on the UI thread. | |
| 17 // The detection happens on the file thread and | |
| 18 // TabContents::PageLanguageDetected() is then called on the associated | |
| 19 // TabContents when the language has been detected. | |
| 20 class CLDHelper : public base::RefCountedThreadSafe<CLDHelper> { | |
| 21 public: | |
| 22 // |tab_contents| should reference the TabContents the page is related to. | |
| 23 // |renderer_process_id|, |page_id| and |page_contents| are the id of the | |
| 24 // render process, the id and contents of the page the language is queried. | |
| 25 CLDHelper(TabContents* tab_contents, | |
| 26 int renderer_process_id, | |
| 27 int page_id, | |
| 28 const std::wstring& page_content); | |
| 29 | |
| 30 // Starts the process of detecting the language of the page. | |
| 31 void DetectLanguage(); | |
| 32 | |
| 33 // Cancel any pending language detection, meaning that the TabContents will | |
| 34 // not be notified. | |
| 35 // This should be on the same thread as DetectLanguage was called. | |
| 36 void CancelLanguageDetection(); | |
| 37 | |
| 38 int renderer_process_id() const { return renderer_process_id_; } | |
| 39 | |
| 40 int page_id() const { return page_id_; } | |
| 41 | |
| 42 std::string language() const { return language_; } | |
| 43 | |
| 44 private: | |
| 45 // Private because the class is ref counted. | |
| 46 friend class base::RefCountedThreadSafe<CLDHelper>; | |
| 47 ~CLDHelper() {} | |
| 48 | |
| 49 // Performs the actual work of detecting the language. | |
| 50 void DoDetectLanguage(); | |
| 51 | |
| 52 // Invoked on the UI thread once the language has been detected. | |
| 53 void DetectionDone(); | |
| 54 | |
| 55 // The tab contents for which the language is being detected. | |
| 56 TabContents* tab_contents_; | |
| 57 | |
| 58 // The id for the render process the page belongs to. | |
| 59 int renderer_process_id_; | |
| 60 | |
| 61 // The id and content of the page for which the language is being detected. | |
| 62 int page_id_; | |
| 63 std::wstring page_content_; | |
| 64 | |
| 65 // The language that was detected. | |
| 66 std::string language_; | |
| 67 | |
| 68 DISALLOW_COPY_AND_ASSIGN(CLDHelper); | |
| 69 }; | |
| 70 | |
| 71 #endif // CHROME_BROWSER_CLD_HELPER_H_ | |
| 72 | |
| OLD | NEW |