Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(246)

Side by Side Diff: chrome/browser/translate/translate_tab_helper.h

Issue 285293004: Allow browser tests to run with dynamic CLD data. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@cld_uma
Patch Set: Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 TranslateBrowserUtilsTest;
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
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::TranslateBrowserUtilsTest; // For cleaning up static state
Sorin Jianu 2014/05/15 17:16:13 Ends with .
Andrew Hayden (chromium.org) 2014/05/16 17:53:20 Done.
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 23 matching lines...) Expand all
136 static void HandleCLDDataRequest(); 141 static void HandleCLDDataRequest();
137 142
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
151 // For testing purposes only, clear the s_cached_* state. Leaks the open
Sorin Jianu 2014/05/15 17:16:13 clears
Sorin Jianu 2014/05/15 17:16:13 Since we already have test friendship, would it be
Andrew Hayden (chromium.org) 2014/05/16 17:53:20 Done.
152 // file handle, because renderer processes could be using it and there's no
153 // way to be sure that they aren't. This effectively allows a test harness
154 // to wipe any cached state.
155 static void ClearCLDDataForTest();
156
146 // The data file, cached as long as the process stays alive. 157 // 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. 158 // We also track the offset at which the data starts, and its length.
148 static base::File* s_cached_file_; // guarded by file_lock_ 159 static base::File* s_cached_file_; // guarded by file_lock_
149 static uint64 s_cached_data_offset_; // guarded by file_lock_ 160 static uint64 s_cached_data_offset_; // guarded by file_lock_
150 static uint64 s_cached_data_length_; // guarded by file_lock_ 161 static uint64 s_cached_data_length_; // guarded by file_lock_
151 162
152 // Guards s_cached_file_ 163 // Guards s_cached_file_
153 static base::LazyInstance<base::Lock> s_file_lock_; 164 static base::LazyInstance<base::Lock> s_file_lock_;
154 165
155 #endif 166 #endif
(...skipping 10 matching lines...) Expand all
166 177
167 // Necessary for binding the callback to HandleCLDDataRequest on the blocking 178 // Necessary for binding the callback to HandleCLDDataRequest on the blocking
168 // pool and for delaying translation initialization until the page has 179 // pool and for delaying translation initialization until the page has
169 // finished loading on a reload. 180 // finished loading on a reload.
170 base::WeakPtrFactory<TranslateTabHelper> weak_pointer_factory_; 181 base::WeakPtrFactory<TranslateTabHelper> weak_pointer_factory_;
171 182
172 DISALLOW_COPY_AND_ASSIGN(TranslateTabHelper); 183 DISALLOW_COPY_AND_ASSIGN(TranslateTabHelper);
173 }; 184 };
174 185
175 #endif // CHROME_BROWSER_TRANSLATE_TRANSLATE_TAB_HELPER_H_ 186 #endif // CHROME_BROWSER_TRANSLATE_TRANSLATE_TAB_HELPER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698