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.
5 #ifndef COMPONENTS_TRANSLATE_CONTENT_BROWSER_BROWSER_CLD_DATA_PROVIDER_H_
6 #define COMPONENTS_TRANSLATE_CONTENT_BROWSER_BROWSER_CLD_DATA_PROVIDER_H_
10 #include "base/compiler_specific.h"
11 #include "base/macros.h"
12 #include "ipc/ipc_listener.h"
20 // Browser-side interface responsible for providing CLD data.
21 // The implementation must be paired with a renderer-side implementation of
22 // the RendererCldDataProvider class:
23 // ../renderer/renderer_cld_data_provider.h
25 // The glue between them is typically a pair of request/response IPC messages
26 // using the "CldDataProviderMsgStart" IPCMessageStart enumerated constant from
27 // ipc_message_start.h
29 // In general, instances of this class should be obtained by using the
30 // BrowserCldDataProviderFactory::CreateBrowserCldProvider(...). For more
31 // information, see browser_cld_data_provider_factory.h.
32 class BrowserCldDataProvider
: public IPC::Listener
{
34 BrowserCldDataProvider() {}
35 ~BrowserCldDataProvider() override
{}
37 // IPC::Listener implementation:
38 // If the specified message is a request for CLD data, invokes
39 // OnCldDataRequest() and returns true. In all other cases, this method does
40 // nothing. This method is defined as virtual in order to force the
41 // implementation to define the specific IPC message(s) that it handles.
42 // The default implementation does nothing and returns false.
43 bool OnMessageReceived(const IPC::Message
&) override
;
45 // Called when the browser process receives an appropriate message in
46 // OnMessageReceived, above. The implementation should attempt to locate
47 // the CLD data, cache any metadata required for accessing that data, and
48 // ultimately trigger a response by invoking SendCldDataResponse.
49 // The renderer process may poll for data, in which case this method may be
50 // repeatedly invoked. The implementation must be safe to call any number
52 // The default implementation does nothing.
53 virtual void OnCldDataRequest() {}
55 // Invoked when OnCldDataRequest, above, results in a successful lookup or
56 // the data is already cached and ready to respond to. The implementation
57 // should take whatever action is appropriate for responding to the paired
58 // RendererCldDataProvider, typically by sending an IPC response.
59 // The default implementation does nothing.
60 virtual void SendCldDataResponse() {}
63 DISALLOW_COPY_AND_ASSIGN(BrowserCldDataProvider
);
66 } // namespace translate
68 #endif // COMPONENTS_TRANSLATE_CONTENT_BROWSER_BROWSER_CLD_DATA_PROVIDER_H_