Chromium Code Reviews| 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" | |
| 12 #include "base/platform_file.h" | |
| 13 #include "base/synchronization/lock.h" | |
| 14 #include "base/task_runner.h" | |
| 11 #include "chrome/browser/ui/translate/translate_bubble_model.h" | 15 #include "chrome/browser/ui/translate/translate_bubble_model.h" |
| 12 #include "components/translate/content/browser/content_translate_driver.h" | 16 #include "components/translate/content/browser/content_translate_driver.h" |
| 13 #include "components/translate/core/common/translate_errors.h" | 17 #include "components/translate/core/common/translate_errors.h" |
| 14 #include "content/public/browser/web_contents_observer.h" | 18 #include "content/public/browser/web_contents_observer.h" |
| 15 #include "content/public/browser/web_contents_user_data.h" | 19 #include "content/public/browser/web_contents_user_data.h" |
| 16 | 20 |
| 17 namespace content { | 21 namespace content { |
| 18 class BrowserContext; | 22 class BrowserContext; |
| 19 class WebContents; | 23 class WebContents; |
| 20 } | 24 } |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 85 virtual void WebContentsDestroyed( | 89 virtual void WebContentsDestroyed( |
| 86 content::WebContents* web_contents) OVERRIDE; | 90 content::WebContents* web_contents) OVERRIDE; |
| 87 | 91 |
| 88 void OnLanguageDetermined(const LanguageDetectionDetails& details, | 92 void OnLanguageDetermined(const LanguageDetectionDetails& details, |
| 89 bool page_needs_translation); | 93 bool page_needs_translation); |
| 90 void OnPageTranslated(int32 page_id, | 94 void OnPageTranslated(int32 page_id, |
| 91 const std::string& original_lang, | 95 const std::string& original_lang, |
| 92 const std::string& translated_lang, | 96 const std::string& translated_lang, |
| 93 TranslateErrors::Type error_type); | 97 TranslateErrors::Type error_type); |
| 94 | 98 |
| 99 #if defined(CLD2_DYNAMIC_MODE) | |
| 100 // Called when we receive ChromeViewHostMsg_NeedCLDData from a renderer. | |
| 101 // If we have already cached the data, responds immediately; else, enqueues | |
| 102 // a HandleCLDDataRequest on the blocking pool to cache the data. | |
| 103 // Acquires and releases s_file_lock_ in a non-blocking manner; queries | |
| 104 // handled while the file is being cached will gracefully and immediately | |
| 105 // fail. | |
| 106 // It is up to the originator of the message to poll again later if required; | |
| 107 // no "negative response" will be generated. | |
| 108 void OnCLDDataRequested(); | |
| 109 | |
| 110 // Invoked on the blocking pool in order to cache the data. When successful, | |
| 111 // immediately responds to the request that initiated OnCLDDataRequested. | |
| 112 // Holds s_file_lock_ while the file is being cached. | |
| 113 void HandleCLDDataRequest(); | |
| 114 | |
| 115 // Sends the renderer a response containing the data file handle. No locking. | |
| 116 void SendCLDDataAvailable(const base::PlatformFile handle); | |
| 117 | |
| 118 // Necessary for binding the callback to HandleCLDDataRequest on the blocking | |
| 119 // pool. | |
| 120 base::WeakPtrFactory<TranslateTabHelper> weak_pointer_factory_; | |
| 121 | |
| 122 // The data file, cached as long as the process stays alive. | |
| 123 static base::PlatformFile s_cached_platform_file_; // guarded by file_lock_ | |
| 124 | |
| 125 // Guards s_cached_platform_file_ | |
| 126 static base::Lock s_file_lock_; | |
|
bulach
2014/03/14 15:30:58
statics can only be used for PODs, this need to be
Andrew Hayden (chromium.org)
2014/03/20 16:12:53
Done.
| |
| 127 #endif | |
| 128 | |
| 95 // Shows the translate bubble. | 129 // Shows the translate bubble. |
| 96 void ShowBubble(TranslateStep step, TranslateErrors::Type error_type); | 130 void ShowBubble(TranslateStep step, TranslateErrors::Type error_type); |
| 97 | 131 |
| 98 ContentTranslateDriver translate_driver_; | 132 ContentTranslateDriver translate_driver_; |
| 99 scoped_ptr<TranslateManager> translate_manager_; | 133 scoped_ptr<TranslateManager> translate_manager_; |
| 100 | 134 |
| 101 DISALLOW_COPY_AND_ASSIGN(TranslateTabHelper); | 135 DISALLOW_COPY_AND_ASSIGN(TranslateTabHelper); |
| 102 }; | 136 }; |
| 103 | 137 |
| 104 #endif // CHROME_BROWSER_TRANSLATE_TRANSLATE_TAB_HELPER_H_ | 138 #endif // CHROME_BROWSER_TRANSLATE_TRANSLATE_TAB_HELPER_H_ |
| OLD | NEW |