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

Side by Side Diff: components/translate/content/browser/content_translate_driver_impl.h

Issue 2066483004: [Wait to be closed] [Translate] Migrate IPCs to Mojo interfaces. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Ensure TranslateCallback get run Created 4 years, 5 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 COMPONENTS_TRANSLATE_CONTENT_BROWSER_CONTENT_TRANSLATE_DRIVER_H_ 5 #ifndef COMPONENTS_TRANSLATE_CONTENT_BROWSER_CONTENT_TRANSLATE_DRIVER_IMPL_H_
6 #define COMPONENTS_TRANSLATE_CONTENT_BROWSER_CONTENT_TRANSLATE_DRIVER_H_ 6 #define COMPONENTS_TRANSLATE_CONTENT_BROWSER_CONTENT_TRANSLATE_DRIVER_IMPL_H_
7
8 #include <map>
7 9
8 #include "base/macros.h" 10 #include "base/macros.h"
9 #include "base/memory/weak_ptr.h" 11 #include "base/memory/weak_ptr.h"
10 #include "base/observer_list.h" 12 #include "base/observer_list.h"
13 #include "components/translate/content/public/interfaces/translate.mojom.h"
11 #include "components/translate/core/browser/translate_driver.h" 14 #include "components/translate/core/browser/translate_driver.h"
12 #include "components/translate/core/common/translate_errors.h" 15 #include "components/translate/core/common/translate_errors.h"
13 #include "content/public/browser/web_contents_observer.h" 16 #include "content/public/browser/web_contents_observer.h"
17 #include "mojo/public/cpp/bindings/binding_set.h"
14 18
15 namespace content { 19 namespace content {
16 class NavigationController; 20 class NavigationController;
17 class WebContents; 21 class WebContents;
18 } 22 }
19 23
20 namespace translate { 24 namespace translate {
21 25
22 struct LanguageDetectionDetails; 26 struct LanguageDetectionDetails;
23 class TranslateManager; 27 class TranslateManager;
24 28
25
26 // Content implementation of TranslateDriver. 29 // Content implementation of TranslateDriver.
27 class ContentTranslateDriver : public TranslateDriver, 30 class ContentTranslateDriverImpl : public TranslateDriver,
28 public content::WebContentsObserver { 31 public content::WebContentsObserver,
32 public mojom::ContentTranslateDriver {
29 public: 33 public:
30 34 // The observer for the ContentTranslateDriverImpl.
31 // The observer for the ContentTranslateDriver.
32 class Observer { 35 class Observer {
33 public: 36 public:
34 // Handles when the value of IsPageTranslated is changed. 37 // Handles when the value of IsPageTranslated is changed.
35 virtual void OnIsPageTranslatedChanged(content::WebContents* source) {}; 38 virtual void OnIsPageTranslatedChanged(content::WebContents* source){};
Anand Mistry (off Chromium) 2016/07/12 07:17:09 I believe the chromium style is to always have a s
leonhsl(Using Gerrit) 2016/07/12 10:15:10 Acknowledged.
leonhsl(Using Gerrit) 2016/07/13 09:56:18 Done.
36 39
37 // Handles when the value of translate_enabled is changed. 40 // Handles when the value of translate_enabled is changed.
38 virtual void OnTranslateEnabledChanged(content::WebContents* source) {}; 41 virtual void OnTranslateEnabledChanged(content::WebContents* source){};
39 42
40 // Called when the page language has been determined. 43 // Called when the page language has been determined.
41 virtual void OnLanguageDetermined( 44 virtual void OnLanguageDetermined(
42 const translate::LanguageDetectionDetails& details) {}; 45 const translate::LanguageDetectionDetails& details){};
43 46
44 // Called when the page has been translated. 47 // Called when the page has been translated.
45 virtual void OnPageTranslated( 48 virtual void OnPageTranslated(
46 const std::string& original_lang, 49 const std::string& original_lang,
47 const std::string& translated_lang, 50 const std::string& translated_lang,
48 translate::TranslateErrors::Type error_type) {}; 51 translate::TranslateErrors::Type error_type){};
49 52
50 protected: 53 protected:
51 virtual ~Observer() {} 54 virtual ~Observer() {}
52 }; 55 };
53 56
54 ContentTranslateDriver(content::NavigationController* nav_controller); 57 ContentTranslateDriverImpl(content::NavigationController* nav_controller);
Anand Mistry (off Chromium) 2016/07/12 07:17:09 explicit on single-arg constructors.
leonhsl(Using Gerrit) 2016/07/12 10:15:09 Acknowledged.
leonhsl(Using Gerrit) 2016/07/13 09:56:18 Done.
55 ~ContentTranslateDriver() override; 58 ~ContentTranslateDriverImpl() override;
59
60 void BindRequest(mojom::ContentTranslateDriverRequest request);
56 61
57 // Adds or Removes observers. 62 // Adds or Removes observers.
58 void AddObserver(Observer* observer); 63 void AddObserver(Observer* observer);
59 void RemoveObserver(Observer* observer); 64 void RemoveObserver(Observer* observer);
60 65
61 // Number of attempts before waiting for a page to be fully reloaded. 66 // Number of attempts before waiting for a page to be fully reloaded.
62 void set_translate_max_reload_attempts(int attempts) { 67 void set_translate_max_reload_attempts(int attempts) {
63 max_reload_check_attempts_ = attempts; 68 max_reload_check_attempts_ = attempts;
64 } 69 }
65 70
(...skipping 20 matching lines...) Expand all
86 const GURL& GetVisibleURL() override; 91 const GURL& GetVisibleURL() override;
87 bool HasCurrentPage() override; 92 bool HasCurrentPage() override;
88 void OpenUrlInNewTab(const GURL& url) override; 93 void OpenUrlInNewTab(const GURL& url) override;
89 94
90 // content::WebContentsObserver implementation. 95 // content::WebContentsObserver implementation.
91 void NavigationEntryCommitted( 96 void NavigationEntryCommitted(
92 const content::LoadCommittedDetails& load_details) override; 97 const content::LoadCommittedDetails& load_details) override;
93 void DidNavigateAnyFrame(content::RenderFrameHost* render_frame_host, 98 void DidNavigateAnyFrame(content::RenderFrameHost* render_frame_host,
94 const content::LoadCommittedDetails& details, 99 const content::LoadCommittedDetails& details,
95 const content::FrameNavigateParams& params) override; 100 const content::FrameNavigateParams& params) override;
96 bool OnMessageReceived(const IPC::Message& message,
97 content::RenderFrameHost* render_frame_host) override;
98 101
99 // IPC handlers. 102 void OnPageTranslated(bool cancelled,
100 void OnTranslateAssignedSequenceNumber(int page_seq_no); 103 mojo::String original_lang,
101 void OnLanguageDetermined(const LanguageDetectionDetails& details, 104 mojo::String translated_lang,
102 bool page_needs_translation);
103 void OnPageTranslated(const std::string& original_lang,
104 const std::string& translated_lang,
105 TranslateErrors::Type error_type); 105 TranslateErrors::Type error_type);
106 106
107 // mojom::ContentTranslateDriver implementation.
108 void NewPage(mojom::PagePtr page,
109 const LanguageDetectionDetails& details,
110 bool page_needs_translation) override;
111
107 private: 112 private:
113 void OnPageAway(int page_seq_no);
114
108 // The navigation controller of the tab we are associated with. 115 // The navigation controller of the tab we are associated with.
109 content::NavigationController* navigation_controller_; 116 content::NavigationController* navigation_controller_;
110 117
111 TranslateManager* translate_manager_; 118 TranslateManager* translate_manager_;
112 119
113 base::ObserverList<Observer, true> observer_list_; 120 base::ObserverList<Observer, true> observer_list_;
114 121
115 // Max number of attempts before checking if a page has been reloaded. 122 // Max number of attempts before checking if a page has been reloaded.
116 int max_reload_check_attempts_; 123 int max_reload_check_attempts_;
117 124
118 base::WeakPtrFactory<ContentTranslateDriver> weak_pointer_factory_; 125 // Records mojo connections with all current alive pages.
groby-ooo-7-16 2016/07/11 22:34:43 Previously, we only kept the last connection alive
leonhsl(Using Gerrit) 2016/07/12 02:48:17 From my understanding, one WebContents : one Conte
Anand Mistry (off Chromium) 2016/07/12 07:17:09 I don't really understand the translate parts, but
leonhsl(Using Gerrit) 2016/07/12 10:15:09 Oh,, yes we can keep only one PagePtr for the late
126 int next_page_seq_no_;
127 std::map<int, mojom::PagePtr> mojo_pages_;
119 128
120 DISALLOW_COPY_AND_ASSIGN(ContentTranslateDriver); 129 // ContentTranslateDriverImpl is singleton per web contents ,
130 // serve for multiple render frames.
131 mojo::BindingSet<mojom::ContentTranslateDriver> bindings_;
132
133 base::WeakPtrFactory<ContentTranslateDriverImpl> weak_pointer_factory_;
134
135 DISALLOW_COPY_AND_ASSIGN(ContentTranslateDriverImpl);
121 }; 136 };
122 137
123 } // namespace translate 138 } // namespace translate
124 139
125 #endif // COMPONENTS_TRANSLATE_CONTENT_BROWSER_CONTENT_TRANSLATE_DRIVER_H_ 140 #endif // COMPONENTS_TRANSLATE_CONTENT_BROWSER_CONTENT_TRANSLATE_DRIVER_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698