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

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: Rebase and merge Created 6 years, 2 months 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 "ipc/ipc_listener.h" 11 #include "ipc/ipc_listener.h"
12 12
13 namespace IPC { 13 namespace IPC {
14 class Message; 14 class Message;
15 } 15 }
16 16
17 namespace content {
18 class WebContents;
19 }
20
21 namespace translate { 17 namespace translate {
22 18
23 // Browser-side interface responsible for providing CLD data. 19 // Browser-side interface responsible for providing CLD data.
24 // The implementation must be paired with a renderer-side implementation of 20 // The implementation must be paired with a renderer-side implementation of
25 // the RendererCldDataProvider class: 21 // the RendererCldDataProvider class:
26 // 22 //
27 // components/translate/content/renderer/renderer_cld_data_provider.h 23 // components/translate/content/renderer/renderer_cld_data_provider.h
28 // 24 //
29 // ... and the glue between them is typically a pair of request/response IPC 25 // ... and the glue between them is typically a pair of request/response IPC
30 // messages using the CldDataProviderMsgStart IPCMessageStart enumerated 26 // messages using the CldDataProviderMsgStart IPCMessageStart enumerated
31 // constant from ipc_message_start.h 27 // constant from ipc_message_start.h
32 class BrowserCldDataProvider : public IPC::Listener { 28 class BrowserCldDataProvider : public IPC::Listener {
33 public: 29 public:
30 BrowserCldDataProvider();
34 virtual ~BrowserCldDataProvider() {} 31 virtual ~BrowserCldDataProvider() {}
35 32
36 // IPC::Listener implementation: 33 // IPC::Listener implementation:
37 // If the specified message is a request for CLD data, invokes 34 // If the specified message is a request for CLD data, invokes
38 // OnCldDataRequest() and returns true. In all other cases, this method does 35 // OnCldDataRequest() and returns true. In all other cases, this method does
39 // nothing. This method is defined as virtual in order to force the 36 // nothing. This method is defined as virtual in order to force the
40 // implementation to define the specific IPC message(s) that it handles. 37 // implementation to define the specific IPC message(s) that it handles.
41 virtual bool OnMessageReceived(const IPC::Message&) = 0; 38 virtual bool OnMessageReceived(const IPC::Message&) OVERRIDE;
42 39
43 // Called when the browser process receives an appropriate message in 40 // Called when the browser process receives an appropriate message in
44 // OnMessageReceived, above. The implementation should attempt to locate 41 // OnMessageReceived, above. The implementation should attempt to locate
45 // the CLD data, cache any metadata required for accessing that data, and 42 // the CLD data, cache any metadata required for accessing that data, and
46 // ultimately trigger a response by invoking SendCldDataResponse. 43 // ultimately trigger a response by invoking SendCldDataResponse.
47 // 44 //
48 // The renderer process may poll for data, in which case this method may be 45 // 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 46 // repeatedly invoked. The implementation must be safe to call any number
50 // of times. 47 // of times.
51 virtual void OnCldDataRequest() = 0; 48 virtual void OnCldDataRequest();
Andrew Hayden (chromium.org) 2014/09/26 10:22:49 Now that this isn't a pure virtual (same with Send
Andrew Hayden (chromium.org) 2014/10/28 15:18:39 Done.
52 49
53 // Invoked when OnCldDataRequest, above, results in a successful lookup or 50 // Invoked when OnCldDataRequest, above, results in a successful lookup or
54 // the data is already cached and ready to respond to. The implementation 51 // the data is already cached and ready to respond to. The implementation
55 // should take whatever action is appropriate for responding to the paired 52 // should take whatever action is appropriate for responding to the paired
56 // RendererCldDataProvider, typically by sending an IPC response. 53 // RendererCldDataProvider, typically by sending an IPC response.
57 virtual void SendCldDataResponse() = 0; 54 virtual void SendCldDataResponse();
58 }; 55 };
59 56
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 57 } // namespace translate
81 58
82 #endif // COMPONENTS_TRANSLATE_CONTENT_BROWSER_BROWSER_CLD_DATA_PROVIDER_H_ 59 #endif // COMPONENTS_TRANSLATE_CONTENT_BROWSER_BROWSER_CLD_DATA_PROVIDER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698