Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2017 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 IOS_WEB_VIEW_INTERNAL_TRANSLATE_WEB_VIEW_TRANSLATE_SERVICE_H_ | |
| 6 #define IOS_WEB_VIEW_INTERNAL_TRANSLATE_WEB_VIEW_TRANSLATE_SERVICE_H_ | |
| 7 | |
| 8 #include "base/macros.h" | |
| 9 #include "base/memory/ptr_util.h" | |
| 10 #include "components/web_resource/resource_request_allowed_notifier.h" | |
| 11 | |
| 12 namespace base { | |
| 13 template <typename T> | |
| 14 struct DefaultSingletonTraits; | |
| 15 } | |
| 16 | |
| 17 namespace ios_web_view { | |
| 18 | |
| 19 // Singleton managing the resources required for Translate. | |
| 20 class WebViewTranslateService { | |
| 21 public: | |
| 22 static WebViewTranslateService* GetInstance(); | |
| 23 | |
| 24 // Must be called before the Translate feature can be used. | |
| 25 void Initialize(); | |
| 26 | |
| 27 // Must be called to shut down the Translate feature. | |
| 28 void Shutdown(); | |
| 29 | |
| 30 private: | |
| 31 // Manages enabling translate requests only when resource requests are | |
| 32 // allowed. | |
| 33 // NOTE: This must be a separate class from WebViewTranslateService becuase | |
|
sdefresne
2017/05/31 08:52:46
becuase -> because
michaeldo
2017/05/31 21:03:43
Done.
| |
| 34 // base/memory/singleton.h won't see that the OnResourceRequestsAllowed | |
|
sdefresne
2017/05/31 08:52:46
I don't understand this comment at all. Is this be
michaeldo
2017/05/31 21:03:43
I updated the comment. IIUC then we need to fix th
sdefresne
2017/06/01 08:36:52
If a class is written to be sub-classed and it is
| |
| 35 // virtual method has been implemented otherwise. | |
| 36 class TranslateRequestsAllowedListener | |
| 37 : public web_resource::ResourceRequestAllowedNotifier::Observer { | |
| 38 public: | |
| 39 TranslateRequestsAllowedListener(); | |
| 40 ~TranslateRequestsAllowedListener(); | |
|
sdefresne
2017/05/31 08:52:46
This destructor should be virtual in the base clas
michaeldo
2017/05/31 21:03:43
Acknowledged.
| |
| 41 | |
| 42 // ResourceRequestAllowedNotifier::Observer methods. | |
| 43 void OnResourceRequestsAllowed() override; | |
| 44 | |
| 45 private: | |
| 46 // Notifier class to know if it's allowed to make network resource requests. | |
| 47 web_resource::ResourceRequestAllowedNotifier | |
| 48 resource_request_allowed_notifier_; | |
| 49 | |
| 50 DISALLOW_COPY_AND_ASSIGN(TranslateRequestsAllowedListener); | |
| 51 }; | |
| 52 | |
| 53 WebViewTranslateService(); | |
| 54 ~WebViewTranslateService(); | |
| 55 | |
| 56 friend struct base::DefaultSingletonTraits<WebViewTranslateService>; | |
| 57 | |
| 58 // Listener which manages when translate requests can occur. | |
| 59 std::unique_ptr<TranslateRequestsAllowedListener> | |
|
sdefresne
2017/05/31 08:52:46
You can change this to "std::unique_ptr<web_resour
michaeldo
2017/05/31 21:03:43
I used your second suggestion.
| |
| 60 translate_requests_allowed_listener_; | |
| 61 | |
| 62 DISALLOW_COPY_AND_ASSIGN(WebViewTranslateService); | |
| 63 }; | |
| 64 | |
| 65 } // namespace ios_web_view | |
| 66 | |
| 67 #endif // IOS_WEB_VIEW_INTERNAL_TRANSLATE_WEB_VIEW_TRANSLATE_SERVICE_H_ | |
| OLD | NEW |