Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(57)

Side by Side Diff: components/translate/content/browser/browser_cld_data_provider.h

Issue 461633002: Refactor language detection logic to allow non-static CLD data sources. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Make some of the harness factory methods private Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef COMPONENTS_TRANSLATE_CONTENT_BROWSER_BROWSER_CLD_DATA_PROVIDER_H_ 5 #ifndef COMPONENTS_TRANSLATE_CONTENT_BROWSER_BROWSER_CLD_DATA_PROVIDER_H_
6 #define COMPONENTS_TRANSLATE_CONTENT_BROWSER_BROWSER_CLD_DATA_PROVIDER_H_ 6 #define COMPONENTS_TRANSLATE_CONTENT_BROWSER_BROWSER_CLD_DATA_PROVIDER_H_
7 7
8 #include <string> 8 #include <string>
9 9
10 #include "base/files/file_path.h" 10 #include "base/compiler_specific.h"
11 #include "base/macros.h"
11 #include "ipc/ipc_listener.h" 12 #include "ipc/ipc_listener.h"
12 13
13 namespace IPC { 14 namespace IPC {
14 class Message; 15 class Message;
15 } 16 }
16 17
17 namespace content {
18 class WebContents;
19 }
20
21 namespace translate { 18 namespace translate {
22 19
23 // Browser-side interface responsible for providing CLD data. 20 // Browser-side interface responsible for providing CLD data.
24 // The implementation must be paired with a renderer-side implementation of 21 // The implementation must be paired with a renderer-side implementation of
25 // the RendererCldDataProvider class: 22 // the RendererCldDataProvider class:
23 // ../renderer/renderer_cld_data_provider.h
26 // 24 //
27 // components/translate/content/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
28 // 28 //
29 // ... and the glue between them is typically a pair of request/response IPC 29 // In general, instances of this class should be obtained by using the
30 // messages using the CldDataProviderMsgStart IPCMessageStart enumerated 30 // BrowserCldDataProviderFactory::CreateBrowserCldProvider(...). For more
31 // constant from ipc_message_start.h 31 // information, see browser_cld_data_provider_factory.h.
32 class BrowserCldDataProvider : public IPC::Listener { 32 class BrowserCldDataProvider : public IPC::Listener {
33 public: 33 public:
34 BrowserCldDataProvider() {}
34 ~BrowserCldDataProvider() override {} 35 ~BrowserCldDataProvider() override {}
35 36
36 // IPC::Listener implementation: 37 // IPC::Listener implementation:
37 // If the specified message is a request for CLD data, invokes 38 // If the specified message is a request for CLD data, invokes
38 // OnCldDataRequest() and returns true. In all other cases, this method does 39 // OnCldDataRequest() and returns true. In all other cases, this method does
39 // nothing. This method is defined as virtual in order to force the 40 // nothing. This method is defined as virtual in order to force the
40 // implementation to define the specific IPC message(s) that it handles. 41 // implementation to define the specific IPC message(s) that it handles.
41 virtual bool OnMessageReceived(const IPC::Message&) override = 0; 42 // The default implementation does nothing and returns false.
43 bool OnMessageReceived(const IPC::Message&) override;
42 44
43 // Called when the browser process receives an appropriate message in 45 // Called when the browser process receives an appropriate message in
44 // OnMessageReceived, above. The implementation should attempt to locate 46 // OnMessageReceived, above. The implementation should attempt to locate
45 // the CLD data, cache any metadata required for accessing that data, and 47 // the CLD data, cache any metadata required for accessing that data, and
46 // ultimately trigger a response by invoking SendCldDataResponse. 48 // ultimately trigger a response by invoking SendCldDataResponse.
47 //
48 // The renderer process may poll for data, in which case this method may be 49 // The renderer process may poll for data, in which case this method may be
49 // repeatedly invoked. The implementation must be safe to call any number 50 // repeatedly invoked. The implementation must be safe to call any number
50 // of times. 51 // of times.
51 virtual void OnCldDataRequest() = 0; 52 // The default implementation does nothing.
53 virtual void OnCldDataRequest() {}
52 54
53 // Invoked when OnCldDataRequest, above, results in a successful lookup or 55 // Invoked when OnCldDataRequest, above, results in a successful lookup or
54 // the data is already cached and ready to respond to. The implementation 56 // the data is already cached and ready to respond to. The implementation
55 // should take whatever action is appropriate for responding to the paired 57 // should take whatever action is appropriate for responding to the paired
56 // RendererCldDataProvider, typically by sending an IPC response. 58 // RendererCldDataProvider, typically by sending an IPC response.
57 virtual void SendCldDataResponse() = 0; 59 // The default implementation does nothing.
60 virtual void SendCldDataResponse() {}
61
62 private:
63 DISALLOW_COPY_AND_ASSIGN(BrowserCldDataProvider);
58 }; 64 };
59 65
60 // Static factory function defined by the implementation that produces a new
61 // provider for the specified WebContents.
62 BrowserCldDataProvider* CreateBrowserCldDataProviderFor(
63 content::WebContents*);
64
65 // For data sources that support a separate CLD data file, configures the path
66 // of that data file.
67 //
68 // The 'component' and 'standalone' data sources need this method to be called
69 // in order to locate the CLD data on disk.
70 // If the data source doesn't need or doesn't support such configuration, this
71 // function should do nothing. This is the case for, e.g., the static data
72 // source.
73 void SetCldDataFilePath(const base::FilePath& path);
74
75 // Returns the path most recently set by SetCldDataFilePath. The initial value
76 // prior to any such call is the empty path. If the data source doesn't support
77 // a data file, returns the empty path.
78 base::FilePath GetCldDataFilePath();
79
80 } // namespace translate 66 } // namespace translate
81 67
82 #endif // COMPONENTS_TRANSLATE_CONTENT_BROWSER_BROWSER_CLD_DATA_PROVIDER_H_ 68 #endif // COMPONENTS_TRANSLATE_CONTENT_BROWSER_BROWSER_CLD_DATA_PROVIDER_H_
OLDNEW
« no previous file with comments | « components/translate/content/browser/BUILD.gn ('k') | components/translate/content/browser/browser_cld_data_provider.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698