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 #include "components/translate/content/renderer/renderer_cld_data_provider_factory.h"
7 #include "base/lazy_instance.h"
8 #include "components/translate/content/renderer/renderer_cld_data_provider.h"
9 #include "content/public/renderer/render_view_observer.h"
13 // The global instance, alive for the entire lifetime of the process.
14 translate::RendererCldDataProviderFactory
* g_instance
= NULL
;
16 // The default factory, which produces no-op instances of
17 // RendererCldDataProvider suitable for use when CLD data is statically-linked.
18 base::LazyInstance
<translate::RendererCldDataProviderFactory
>::Leaky
19 g_wrapped_default
= LAZY_INSTANCE_INITIALIZER
;
26 scoped_ptr
<RendererCldDataProvider
>
27 RendererCldDataProviderFactory::CreateRendererCldDataProvider(
28 content::RenderViewObserver
* render_view_observer
) {
29 return scoped_ptr
<RendererCldDataProvider
>(
30 new RendererCldDataProvider());
34 bool RendererCldDataProviderFactory::IsInitialized() {
35 return g_instance
!= NULL
;
39 void RendererCldDataProviderFactory::SetDefault(
40 RendererCldDataProviderFactory
* instance
) {
41 if (!IsInitialized()) Set(instance
);
45 void RendererCldDataProviderFactory::Set(
46 RendererCldDataProviderFactory
* instance
) {
47 g_instance
= instance
;
51 RendererCldDataProviderFactory
* RendererCldDataProviderFactory::Get() {
52 if (IsInitialized()) return g_instance
;
53 return &g_wrapped_default
.Get();
56 } // namespace translate