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

Side by Side Diff: components/translate/content/renderer/renderer_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: Fix merge error in chrome/browser/BUILD.gn 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_RENDERER_RENDERER_CLD_DATA_PROVIDER_H_ 5 #ifndef COMPONENTS_TRANSLATE_CONTENT_RENDERER_RENDERER_CLD_DATA_PROVIDER_H_
6 #define COMPONENTS_TRANSLATE_CONTENT_RENDERER_RENDERER_CLD_DATA_PROVIDER_H_ 6 #define COMPONENTS_TRANSLATE_CONTENT_RENDERER_RENDERER_CLD_DATA_PROVIDER_H_
7 7
8 #include "base/callback.h" 8 #include "base/callback.h"
9 #include "ipc/ipc_listener.h" 9 #include "ipc/ipc_listener.h"
10 10
11 namespace IPC { 11 namespace IPC {
12 class Message; 12 class Message;
13 } 13 }
14 14
15 namespace content {
16 class RenderViewObserver;
17 }
18
19 namespace translate { 15 namespace translate {
20 16
21 // Renderer-side interface responsible for providing CLD data. 17 // Renderer-side interface responsible for providing CLD data.
22 // The implementation must be paired with a browser-side implementation of 18 // The implementation must be paired with a browser-side implementation of
23 // the BrowserCldDataProvider class: 19 // the BrowserCldDataProvider class:
24 // 20 //
25 // components/translate/content/browser/browser_cld_data_provider.h 21 // components/translate/content/browser/browser_cld_data_provider.h
26 // 22 //
27 // ... and the glue between them is typically a pair of request/response IPC 23 // ... and the glue between them is typically a pair of request/response IPC
28 // messages using the CldDataProviderMsgStart IPCMessageStart enumerated 24 // messages using the CldDataProviderMsgStart IPCMessageStart enumerated
29 // constant from ipc_message_start.h 25 // constant from ipc_message_start.h
30 class RendererCldDataProvider : public IPC::Listener { 26 class RendererCldDataProvider : public IPC::Listener {
31 public: 27 public:
28 RendererCldDataProvider();
32 virtual ~RendererCldDataProvider() {} 29 virtual ~RendererCldDataProvider() {}
33 30
34 // (Inherited from IPC::Listener) 31 // (Inherited from IPC::Listener)
35 // If the specified message is a response for CLD data, attempts to 32 // If the specified message is a response for CLD data, attempts to
36 // initialize CLD2 and returns true in all cases. If initialization is 33 // initialize CLD2 and returns true in all cases. If initialization is
37 // successful and a callback has been configured via 34 // successful and a callback has been configured via
38 // SetCldAvailableCallback(...), that callback is invoked from the message 35 // SetCldAvailableCallback(...), that callback is invoked from the message
39 // loop thread. 36 // loop thread.
40 // This method is defined as virtual in order to force the implementation to 37 // This method is defined as virtual in order to force the implementation to
41 // define the specific IPC message(s) that it handles. 38 // define the specific IPC message(s) that it handles.
42 virtual bool OnMessageReceived(const IPC::Message&) = 0; 39 // The default implementation does nothing and returns false.
40 virtual bool OnMessageReceived(const IPC::Message&) override;
43 41
44 // Invoked by the renderer process to request that CLD data be obtained and 42 // Invoked by the renderer process to request that CLD data be obtained and
45 // that CLD be initialized with it. The implementation is expected to 43 // that CLD be initialized with it. The implementation is expected to
46 // communicate with the paired BrowserCldDataProvider implementation on the 44 // communicate with the paired BrowserCldDataProvider implementation on the
47 // browser side. 45 // browser side.
48 // This method must be invoked on the message loop thread. 46 // This method must be invoked on the message loop thread.
49 virtual void SendCldDataRequest() = 0; 47 // The default implementation does nothing.
48 virtual void SendCldDataRequest();
50 49
51 // Convenience method that tracks whether or not CLD data is available. 50 // Convenience method that tracks whether or not CLD data is available.
52 // This method can be used in the absence of a callback (i.e., if the caller 51 // This method can be used in the absence of a callback (i.e., if the caller
53 // wants a simple way to check the state of CLD data availability without 52 // wants a simple way to check the state of CLD data availability without
54 // keeping a separate boolean flag tripped by a callback). 53 // keeping a separate boolean flag tripped by a callback).
55 virtual bool IsCldDataAvailable() = 0; 54 // The default implementation always returns true.
55 virtual bool IsCldDataAvailable();
56 56
57 // Sets a callback that will be invoked when CLD data is successfully 57 // Sets a callback that will be invoked when CLD data is successfully
58 // obtained from the paired BrowserCldDataProvider implementation on the 58 // obtained from the paired BrowserCldDataProvider implementation on the
59 // browser side, after CLD has been successfully initialized. 59 // browser side, after CLD has been successfully initialized.
60 // Both the initialization of CLD2 as well as the invocation of the callback 60 // Both the initialization of CLD2 as well as the invocation of the callback
61 // must happen on the message loop thread. 61 // must happen on the message loop thread.
62 virtual void SetCldAvailableCallback(base::Callback<void(void)>) = 0; 62 // The default implementation immediately invokes the callback.
63 virtual void SetCldAvailableCallback(base::Callback<void(void)>);
64
65 // Sets the instance of the provider used by this process, optionally
66 // overwriting the previous value. Embedders and narrow use-cases (such as
67 // shells and test code) should use the overwrite capability, while generic
68 // code should not.
69 // If another instance is already set, it is immediately destroyed prior to
70 // updating the global pointer to point to the specified instance.
71 static void Set(RendererCldDataProvider* instance, bool overwrite);
72
73 // Returns true if and only if the current instance for this process is not
74 // NULL.
75 static bool IsInitialized();
76
77 // Returns the instance of the provider previously set by Set(...).
78 // If no instance has been set, a default no-op provider will be returned.
79 static RendererCldDataProvider* Get();
63 }; 80 };
jochen (gone - plz use gerrit) 2014/10/23 13:57:39 disallow copy/assign
Andrew Hayden (chromium.org) 2014/10/30 16:56:32 Done.
64 81
65 // Static factory function defined by the implementation that produces a new
66 // provider for the specified render view host.
67 RendererCldDataProvider* CreateRendererCldDataProviderFor(
68 content::RenderViewObserver*);
69
70 } // namespace translate 82 } // namespace translate
71 83
72 #endif // COMPONENTS_TRANSLATE_CONTENT_RENDERER_RENDERER_CLD_DATAP_PROVIDER_H_ 84 #endif // COMPONENTS_TRANSLATE_CONTENT_RENDERER_RENDERER_CLD_DATAP_PROVIDER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698