OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 // NOT DEAD CODE! | |
6 // This code isn't dead, even if it isn't currently being used. Please refer to: | |
7 // https://www.chromium.org/developers/how-tos/compact-language-detector-cld-dat
a-source-configuration | |
8 | |
9 #ifndef COMPONENTS_TRANSLATE_CONTENT_RENDERER_RENDERER_CLD_DATA_PROVIDER_H_ | |
10 #define COMPONENTS_TRANSLATE_CONTENT_RENDERER_RENDERER_CLD_DATA_PROVIDER_H_ | |
11 | |
12 #include "base/callback.h" | |
13 #include "base/macros.h" | |
14 #include "ipc/ipc_listener.h" | |
15 | |
16 namespace IPC { | |
17 class Message; | |
18 } | |
19 | |
20 namespace translate { | |
21 | |
22 // Renderer-side interface responsible for providing CLD data. | |
23 // The embedder should set an instance as soon as feasible during startup. | |
24 // The implementation must be paired with a browser-side implementation of | |
25 // the BrowserCldDataProvider class, typically created by a | |
26 // BrowserCldDataProviderFactory: | |
27 // ../browser/browser_cld_data_provider_factory.h | |
28 // ../browser/browser_cld_data_provider.h | |
29 // | |
30 // The glue between the browser and renderer processes is typically a pair of | |
31 // request/response IPC messages using the CldDataProviderMsgStart | |
32 // "IPCMessageStart" enumerated constant from ipc_message_start.h. | |
33 class RendererCldDataProvider : public IPC::Listener { | |
34 public: | |
35 RendererCldDataProvider(); | |
36 ~RendererCldDataProvider() override {} | |
37 | |
38 // (Inherited from IPC::Listener) | |
39 // If the specified message is a response for CLD data, attempts to | |
40 // initialize CLD2 and returns true in all cases. If initialization is | |
41 // successful and a callback has been configured via | |
42 // SetCldAvailableCallback(...), that callback is invoked from the message | |
43 // loop thread. | |
44 // This method is defined as virtual in order to force the implementation to | |
45 // define the specific IPC message(s) that it handles. | |
46 // The default implementation does nothing and returns false. | |
47 bool OnMessageReceived(const IPC::Message& message) override; | |
48 | |
49 // Invoked by the renderer process to request that CLD data be obtained and | |
50 // that CLD be initialized with it. The implementation is expected to | |
51 // communicate with the paired BrowserCldDataProvider implementation on the | |
52 // browser side. | |
53 // This method must be invoked on the message loop thread. | |
54 // The default implementation does nothing. | |
55 virtual void SendCldDataRequest() {} | |
56 | |
57 // Convenience method that tracks whether or not CLD data is available. | |
58 // This method can be used in the absence of a callback (i.e., if the caller | |
59 // wants a simple way to check the state of CLD data availability without | |
60 // keeping a separate boolean flag tripped by a callback). | |
61 // The default implementation always returns true. | |
62 virtual bool IsCldDataAvailable(); | |
63 | |
64 // Sets a callback that will be invoked when CLD data is successfully | |
65 // obtained from the paired BrowserCldDataProvider implementation on the | |
66 // browser side, after CLD has been successfully initialized. | |
67 // Both the initialization of CLD2 as well as the invocation of the callback | |
68 // must happen on the message loop thread. | |
69 // The default implementation immediately invokes the callback. | |
70 virtual void SetCldAvailableCallback(base::Callback<void(void)> callback); | |
71 | |
72 private: | |
73 DISALLOW_COPY_AND_ASSIGN(RendererCldDataProvider); | |
74 }; | |
75 | |
76 } // namespace translate | |
77 | |
78 #endif // COMPONENTS_TRANSLATE_CONTENT_RENDERER_RENDERER_CLD_DATAP_PROVIDER_H_ | |
OLD | NEW |