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 currently must be a separate class from WebViewTranslateService | |
sdefresne
2017/06/01 08:36:52
Can you create a bug to track fixing the destructo
michaeldo
2017/06/01 21:20:38
Done.
| |
34 // because the destructor of | |
35 // web_resource::ResourceRequestAllowedNotifier::Observer is not virtual. | |
36 class TranslateRequestsAllowedListener | |
37 : public web_resource::ResourceRequestAllowedNotifier::Observer { | |
38 public: | |
39 TranslateRequestsAllowedListener(); | |
40 ~TranslateRequestsAllowedListener(); | |
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/06/01 08:36:52
You don't need a std::unique_ptr<> here, you can j
michaeldo
2017/06/01 21:20:38
Thank you for the explanation. Done.
| |
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 |