| OLD | NEW |
| 1 // Copyright 2011 The Chromium Authors. All rights reserved. | 1 // Copyright 2011 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_TRANSLATE_TRANSLATE_TAB_HELPER_H_ | 5 #ifndef CHROME_BROWSER_TRANSLATE_TRANSLATE_TAB_HELPER_H_ |
| 6 #define CHROME_BROWSER_TRANSLATE_TRANSLATE_TAB_HELPER_H_ | 6 #define CHROME_BROWSER_TRANSLATE_TRANSLATE_TAB_HELPER_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| 11 #include "base/memory/weak_ptr.h" | 11 #include "base/memory/weak_ptr.h" |
| 12 #include "chrome/browser/ui/translate/translate_bubble_model.h" | 12 #include "chrome/browser/ui/translate/translate_bubble_model.h" |
| 13 #include "components/translate/content/browser/content_translate_driver.h" | 13 #include "components/translate/content/browser/content_translate_driver.h" |
| 14 #include "components/translate/core/browser/translate_client.h" | 14 #include "components/translate/core/browser/translate_client.h" |
| 15 #include "components/translate/core/browser/translate_step.h" | 15 #include "components/translate/core/browser/translate_step.h" |
| 16 #include "components/translate/core/common/translate_errors.h" | 16 #include "components/translate/core/common/translate_errors.h" |
| 17 #include "content/public/browser/web_contents_observer.h" | 17 #include "content/public/browser/web_contents_observer.h" |
| 18 #include "content/public/browser/web_contents_user_data.h" | 18 #include "content/public/browser/web_contents_user_data.h" |
| 19 | 19 |
| 20 #if defined(CLD2_DYNAMIC_MODE) | 20 #if defined(CLD2_DYNAMIC_MODE) |
| 21 #include "base/basictypes.h" | 21 #include "base/basictypes.h" |
| 22 #include "base/lazy_instance.h" | 22 #include "base/lazy_instance.h" |
| 23 #include "base/synchronization/lock.h" | 23 #include "base/synchronization/lock.h" |
| 24 #include "base/task_runner.h" | 24 #include "base/task_runner.h" |
| 25 #endif | 25 #endif |
| 26 | 26 |
| 27 namespace base { | 27 namespace base { |
| 28 class File; | 28 class File; |
| 29 } | 29 } // namespace base |
| 30 | 30 |
| 31 namespace content { | 31 namespace content { |
| 32 class BrowserContext; | 32 class BrowserContext; |
| 33 class WebContents; | 33 class WebContents; |
| 34 } | 34 } // namespace content |
| 35 |
| 36 namespace test { |
| 37 class ScopedCLDDynamicDataHarness; |
| 38 } // namespace test |
| 35 | 39 |
| 36 struct LanguageDetectionDetails; | 40 struct LanguageDetectionDetails; |
| 37 class PrefService; | 41 class PrefService; |
| 38 class TranslateAcceptLanguages; | 42 class TranslateAcceptLanguages; |
| 39 class TranslatePrefs; | 43 class TranslatePrefs; |
| 40 class TranslateManager; | 44 class TranslateManager; |
| 41 | 45 |
| 42 class TranslateTabHelper | 46 class TranslateTabHelper |
| 43 : public TranslateClient, | 47 : public TranslateClient, |
| 44 public content::WebContentsObserver, | 48 public content::WebContentsObserver, |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 93 const std::string target_language, | 97 const std::string target_language, |
| 94 TranslateErrors::Type error_type, | 98 TranslateErrors::Type error_type, |
| 95 bool triggered_from_menu) OVERRIDE; | 99 bool triggered_from_menu) OVERRIDE; |
| 96 virtual bool IsTranslatableURL(const GURL& url) OVERRIDE; | 100 virtual bool IsTranslatableURL(const GURL& url) OVERRIDE; |
| 97 virtual void ShowReportLanguageDetectionErrorUI( | 101 virtual void ShowReportLanguageDetectionErrorUI( |
| 98 const GURL& report_url) OVERRIDE; | 102 const GURL& report_url) OVERRIDE; |
| 99 | 103 |
| 100 private: | 104 private: |
| 101 explicit TranslateTabHelper(content::WebContents* web_contents); | 105 explicit TranslateTabHelper(content::WebContents* web_contents); |
| 102 friend class content::WebContentsUserData<TranslateTabHelper>; | 106 friend class content::WebContentsUserData<TranslateTabHelper>; |
| 107 friend class test::ScopedCLDDynamicDataHarness; // For cleaning static state. |
| 103 | 108 |
| 104 // content::WebContentsObserver implementation. | 109 // content::WebContentsObserver implementation. |
| 105 virtual void NavigationEntryCommitted( | 110 virtual void NavigationEntryCommitted( |
| 106 const content::LoadCommittedDetails& load_details) OVERRIDE; | 111 const content::LoadCommittedDetails& load_details) OVERRIDE; |
| 107 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; | 112 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; |
| 108 virtual void DidNavigateAnyFrame( | 113 virtual void DidNavigateAnyFrame( |
| 109 const content::LoadCommittedDetails& details, | 114 const content::LoadCommittedDetails& details, |
| 110 const content::FrameNavigateParams& params) OVERRIDE; | 115 const content::FrameNavigateParams& params) OVERRIDE; |
| 111 virtual void WebContentsDestroyed() OVERRIDE; | 116 virtual void WebContentsDestroyed() OVERRIDE; |
| 112 | 117 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 138 // If the CLD data is ready, send it to the renderer. Briefly checks the lock. | 143 // If the CLD data is ready, send it to the renderer. Briefly checks the lock. |
| 139 void MaybeSendCLDDataAvailable(); | 144 void MaybeSendCLDDataAvailable(); |
| 140 | 145 |
| 141 // Sends the renderer a response containing the data file handle. No locking. | 146 // Sends the renderer a response containing the data file handle. No locking. |
| 142 void SendCLDDataAvailable(const base::File* handle, | 147 void SendCLDDataAvailable(const base::File* handle, |
| 143 const uint64 data_offset, | 148 const uint64 data_offset, |
| 144 const uint64 data_length); | 149 const uint64 data_length); |
| 145 | 150 |
| 146 // The data file, cached as long as the process stays alive. | 151 // The data file, cached as long as the process stays alive. |
| 147 // We also track the offset at which the data starts, and its length. | 152 // We also track the offset at which the data starts, and its length. |
| 148 static base::File* s_cached_file_; // guarded by file_lock_ | 153 static base::File* s_cached_file_; // guarded by file_lock_ |
| 149 static uint64 s_cached_data_offset_; // guarded by file_lock_ | 154 static uint64 s_cached_data_offset_; // guarded by file_lock_ |
| 150 static uint64 s_cached_data_length_; // guarded by file_lock_ | 155 static uint64 s_cached_data_length_; // guarded by file_lock_ |
| 151 | 156 |
| 152 // Guards s_cached_file_ | 157 // Guards s_cached_file_ |
| 153 static base::LazyInstance<base::Lock> s_file_lock_; | 158 static base::LazyInstance<base::Lock> s_file_lock_; |
| 154 | 159 |
| 155 #endif | 160 #endif |
| 156 | 161 |
| 157 // Shows the translate bubble. | 162 // Shows the translate bubble. |
| 158 void ShowBubble(translate::TranslateStep step, | 163 void ShowBubble(translate::TranslateStep step, |
| 159 TranslateErrors::Type error_type); | 164 TranslateErrors::Type error_type); |
| 160 | 165 |
| 161 // Max number of attempts before checking if a page has been reloaded. | 166 // Max number of attempts before checking if a page has been reloaded. |
| 162 int max_reload_check_attempts_; | 167 int max_reload_check_attempts_; |
| 163 | 168 |
| 164 ContentTranslateDriver translate_driver_; | 169 ContentTranslateDriver translate_driver_; |
| 165 scoped_ptr<TranslateManager> translate_manager_; | 170 scoped_ptr<TranslateManager> translate_manager_; |
| 166 | 171 |
| 167 // Necessary for binding the callback to HandleCLDDataRequest on the blocking | 172 // Necessary for binding the callback to HandleCLDDataRequest on the blocking |
| 168 // pool and for delaying translation initialization until the page has | 173 // pool and for delaying translation initialization until the page has |
| 169 // finished loading on a reload. | 174 // finished loading on a reload. |
| 170 base::WeakPtrFactory<TranslateTabHelper> weak_pointer_factory_; | 175 base::WeakPtrFactory<TranslateTabHelper> weak_pointer_factory_; |
| 171 | 176 |
| 172 DISALLOW_COPY_AND_ASSIGN(TranslateTabHelper); | 177 DISALLOW_COPY_AND_ASSIGN(TranslateTabHelper); |
| 173 }; | 178 }; |
| 174 | 179 |
| 175 #endif // CHROME_BROWSER_TRANSLATE_TRANSLATE_TAB_HELPER_H_ | 180 #endif // CHROME_BROWSER_TRANSLATE_TRANSLATE_TAB_HELPER_H_ |
| OLD | NEW |