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_FACTORY_H_
6 #define COMPONENTS_TRANSLATE_CONTENT_BROWSER_BROWSER_CLD_DATA_PROVIDER_FACTORY_H_
8 #include "base/macros.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "components/translate/content/browser/browser_cld_data_provider.h"
18 // A factory for the Browser side of CLD Data Providers. The embedder should
19 // set an instance as soon as feasible during startup. The browser process will
20 // use this factory to create the one BrowserCldDataProvider for each render
21 // view host in order to communicate with a RendererCldDataProvider in the
22 // renderer process. For more information on the RendererCldDataProvider, see:
23 // ../renderer/renderer_cld_data_provider.h
24 class BrowserCldDataProviderFactory
{
26 BrowserCldDataProviderFactory() {}
27 virtual ~BrowserCldDataProviderFactory() {}
29 // Create and return a new instance of a BrowserCldDataProvider. The default
30 // implementation of this method produces a no-op BrowserCldDataProvider that
31 // is suitable only when CLD data has been statically linked.
32 // Every invocation creates a new provider; the caller is responsible for
33 // deleting the object when it is no longer needed.
34 virtual scoped_ptr
<BrowserCldDataProvider
> CreateBrowserCldDataProvider(
35 content::WebContents
* web_contents
);
37 // Returns true if and only if the current instance for this process is not
39 static bool IsInitialized();
41 // Sets the default factory for this process, i.e. the factory to be used
42 // unless the embedder calls Set(BrowserCldDataProviderFactory*). This is the
43 // method that normal (i.e., non-test) Chromium code should use; embedders can
44 // and should use the unconditional Set(BrowserCldDataProviderFactory*) method
45 // instead. If a default factory has already been set, this method does
47 static void SetDefault(BrowserCldDataProviderFactory
* instance
);
49 // Unconditionally sets the factory for this process, overwriting any
50 // previously-configured default. Normal Chromium code should never use this
51 // method; it is provided for embedders to inject a factory from outside of
52 // the Chromium code base. Test code can also use this method to force the
53 // runtime to have a desired behavior.
54 static void Set(BrowserCldDataProviderFactory
* instance
);
56 // Returns the instance of the factory previously set by Set()/SetDefault().
57 // If no instance has been set, a default factory will be returned that
58 // produces no-op BrowserCldDataProviders as described by
59 // CreateBrowserCldDataProvider(...) above.
60 static BrowserCldDataProviderFactory
* Get();
63 DISALLOW_COPY_AND_ASSIGN(BrowserCldDataProviderFactory
);
66 } // namespace translate
68 #endif // COMPONENTS_TRANSLATE_CONTENT_BROWSER_BROWSER_CLD_DATA_PROVIDER_FACTORY_H_