Roll src/third_party/WebKit 605a979:06cb9e9 (svn 202556:202558)
[chromium-blink-merge.git] / components / translate / content / renderer / renderer_cld_data_provider_factory.cc
blob3b3dc36b13dcd795fbf0742f300e5505a0ba9ec2
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"
11 namespace {
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;
21 } // namespace
24 namespace translate {
26 scoped_ptr<RendererCldDataProvider>
27 RendererCldDataProviderFactory::CreateRendererCldDataProvider(
28 content::RenderViewObserver* render_view_observer) {
29 return scoped_ptr<RendererCldDataProvider>(
30 new RendererCldDataProvider());
33 // static
34 bool RendererCldDataProviderFactory::IsInitialized() {
35 return g_instance != NULL;
38 // static
39 void RendererCldDataProviderFactory::SetDefault(
40 RendererCldDataProviderFactory* instance) {
41 if (!IsInitialized()) Set(instance);
44 // static
45 void RendererCldDataProviderFactory::Set(
46 RendererCldDataProviderFactory* instance) {
47 g_instance = instance;
50 // static
51 RendererCldDataProviderFactory* RendererCldDataProviderFactory::Get() {
52 if (IsInitialized()) return g_instance;
53 return &g_wrapped_default.Get();
56 } // namespace translate