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/browser/browser_cld_data_provider_factory.h"
7 #include "base/lazy_instance.h"
8 #include "components/translate/content/browser/browser_cld_data_provider.h"
12 // The global instance, alive for the entire lifetime of the process.
13 translate::BrowserCldDataProviderFactory
* g_instance
= NULL
;
15 // The default factory, which produces no-op instances of BrowserCldDataProvider
16 // suitable for use when CLD data is statically-linked.
17 base::LazyInstance
<translate::BrowserCldDataProviderFactory
>::Leaky
18 g_wrapped_default
= LAZY_INSTANCE_INITIALIZER
;
25 scoped_ptr
<BrowserCldDataProvider
>
26 BrowserCldDataProviderFactory::CreateBrowserCldDataProvider(
27 content::WebContents
* web_contents
) {
28 return scoped_ptr
<BrowserCldDataProvider
>(new BrowserCldDataProvider());
32 bool BrowserCldDataProviderFactory::IsInitialized() {
33 return g_instance
!= NULL
;
37 void BrowserCldDataProviderFactory::SetDefault(
38 BrowserCldDataProviderFactory
* instance
) {
39 if (!IsInitialized()) Set(instance
);
43 void BrowserCldDataProviderFactory::Set(
44 BrowserCldDataProviderFactory
* instance
) {
45 g_instance
= instance
;
49 BrowserCldDataProviderFactory
* BrowserCldDataProviderFactory::Get() {
50 if (IsInitialized()) return g_instance
;
51 return &g_wrapped_default
.Get();
54 } // namespace translate