Chromium Code Reviews| Index: ios/web_view/internal/translate/web_view_translate_service.h |
| diff --git a/ios/web_view/internal/translate/web_view_translate_service.h b/ios/web_view/internal/translate/web_view_translate_service.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..b0b515a95f75f6e102e299898dce9318aac51459 |
| --- /dev/null |
| +++ b/ios/web_view/internal/translate/web_view_translate_service.h |
| @@ -0,0 +1,67 @@ |
| +// Copyright 2017 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef IOS_WEB_VIEW_INTERNAL_TRANSLATE_WEB_VIEW_TRANSLATE_SERVICE_H_ |
| +#define IOS_WEB_VIEW_INTERNAL_TRANSLATE_WEB_VIEW_TRANSLATE_SERVICE_H_ |
| + |
| +#include "base/macros.h" |
| +#include "base/memory/ptr_util.h" |
| +#include "components/web_resource/resource_request_allowed_notifier.h" |
| + |
| +namespace base { |
| +template <typename T> |
| +struct DefaultSingletonTraits; |
| +} |
| + |
| +namespace ios_web_view { |
| + |
| +// Singleton managing the resources required for Translate. |
| +class WebViewTranslateService { |
| + public: |
| + static WebViewTranslateService* GetInstance(); |
| + |
| + // Must be called before the Translate feature can be used. |
| + void Initialize(); |
| + |
| + // Must be called to shut down the Translate feature. |
| + void Shutdown(); |
| + |
| + private: |
| + // Manages enabling translate requests only when resource requests are |
| + // allowed. |
| + // 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.
|
| + // 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
|
| + // virtual method has been implemented otherwise. |
| + class TranslateRequestsAllowedListener |
| + : public web_resource::ResourceRequestAllowedNotifier::Observer { |
| + public: |
| + TranslateRequestsAllowedListener(); |
| + ~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.
|
| + |
| + // ResourceRequestAllowedNotifier::Observer methods. |
| + void OnResourceRequestsAllowed() override; |
| + |
| + private: |
| + // Notifier class to know if it's allowed to make network resource requests. |
| + web_resource::ResourceRequestAllowedNotifier |
| + resource_request_allowed_notifier_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(TranslateRequestsAllowedListener); |
| + }; |
| + |
| + WebViewTranslateService(); |
| + ~WebViewTranslateService(); |
| + |
| + friend struct base::DefaultSingletonTraits<WebViewTranslateService>; |
| + |
| + // Listener which manages when translate requests can occur. |
| + 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.
|
| + translate_requests_allowed_listener_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(WebViewTranslateService); |
| +}; |
| + |
| +} // namespace ios_web_view |
| + |
| +#endif // IOS_WEB_VIEW_INTERNAL_TRANSLATE_WEB_VIEW_TRANSLATE_SERVICE_H_ |