1116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch// Copyright 2014 The Chromium Authors. All rights reserved. 2116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch// Use of this source code is governed by a BSD-style license that can be 3116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch// found in the LICENSE file. 4116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch 5116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch#ifndef COMPONENTS_TRANSLATE_CONTENT_BROWSER_BROWSER_CLD_DATA_PROVIDER_H_ 6116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch#define COMPONENTS_TRANSLATE_CONTENT_BROWSER_BROWSER_CLD_DATA_PROVIDER_H_ 7116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch 85f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)#include <string> 95f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 105f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)#include "base/files/file_path.h" 11116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch#include "ipc/ipc_listener.h" 12116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch 13116680a4aac90f2aa7413d9095a592090648e557Ben Murdochnamespace IPC { 14116680a4aac90f2aa7413d9095a592090648e557Ben Murdochclass Message; 15116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch} 16116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch 17116680a4aac90f2aa7413d9095a592090648e557Ben Murdochnamespace content { 18116680a4aac90f2aa7413d9095a592090648e557Ben Murdochclass WebContents; 19116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch} 20116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch 21116680a4aac90f2aa7413d9095a592090648e557Ben Murdochnamespace translate { 22116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch 23116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch// Browser-side interface responsible for providing CLD data. 24116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch// The implementation must be paired with a renderer-side implementation of 25116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch// the RendererCldDataProvider class: 26116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch// 27116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch// components/translate/content/renderer/renderer_cld_data_provider.h 28116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch// 29116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch// ... and the glue between them is typically a pair of request/response IPC 30116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch// messages using the CldDataProviderMsgStart IPCMessageStart enumerated 31116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch// constant from ipc_message_start.h 32116680a4aac90f2aa7413d9095a592090648e557Ben Murdochclass BrowserCldDataProvider : public IPC::Listener { 33116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch public: 34116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch virtual ~BrowserCldDataProvider() {} 35116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch 36116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch // IPC::Listener implementation: 37116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch // If the specified message is a request for CLD data, invokes 38116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch // OnCldDataRequest() and returns true. In all other cases, this method does 39116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch // nothing. This method is defined as virtual in order to force the 40116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch // implementation to define the specific IPC message(s) that it handles. 41116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch virtual bool OnMessageReceived(const IPC::Message&) = 0; 42116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch 43116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch // Called when the browser process receives an appropriate message in 44116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch // OnMessageReceived, above. The implementation should attempt to locate 45116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch // the CLD data, cache any metadata required for accessing that data, and 46116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch // ultimately trigger a response by invoking SendCldDataResponse. 47116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch // 48116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch // The renderer process may poll for data, in which case this method may be 49116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch // repeatedly invoked. The implementation must be safe to call any number 50116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch // of times. 51116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch virtual void OnCldDataRequest() = 0; 52116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch 53116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch // Invoked when OnCldDataRequest, above, results in a successful lookup or 54116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch // the data is already cached and ready to respond to. The implementation 55116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch // should take whatever action is appropriate for responding to the paired 56116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch // RendererCldDataProvider, typically by sending an IPC response. 57116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch virtual void SendCldDataResponse() = 0; 58116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch}; 59116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch 60116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch// Static factory function defined by the implementation that produces a new 61116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch// provider for the specified WebContents. 62116680a4aac90f2aa7413d9095a592090648e557Ben MurdochBrowserCldDataProvider* CreateBrowserCldDataProviderFor( 63116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch content::WebContents*); 64116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch 655f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)// For data sources that support a separate CLD data file, configures the path 665f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)// of that data file. 675f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)// 685f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)// The 'component' and 'standalone' data sources need this method to be called 695f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)// in order to locate the CLD data on disk. 705f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)// If the data source doesn't need or doesn't support such configuration, this 715f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)// function should do nothing. This is the case for, e.g., the static data 725f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)// source. 735f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)void SetCldDataFilePath(const base::FilePath& path); 745f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 755f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)// Returns the path most recently set by SetCldDataFilePath. The initial value 765f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)// prior to any such call is the empty path. If the data source doesn't support 775f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)// a data file, returns the empty path. 785f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)base::FilePath GetCldDataFilePath(); 795f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 80116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch} // namespace translate 81116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch 825f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)#endif // COMPONENTS_TRANSLATE_CONTENT_BROWSER_BROWSER_CLD_DATA_PROVIDER_H_ 83