Chromium Code Reviews| Index: chrome/browser/translate/cld_data_harness_factory.cc |
| diff --git a/chrome/browser/translate/cld_data_harness_factory.cc b/chrome/browser/translate/cld_data_harness_factory.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..664fe16b32aba1acff39d2857373923e2b34ab88 |
| --- /dev/null |
| +++ b/chrome/browser/translate/cld_data_harness_factory.cc |
| @@ -0,0 +1,121 @@ |
| +// Copyright 2014 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "chrome/browser/translate/cld_data_harness_factory.h" |
| + |
| +#include "base/lazy_instance.h" |
| +#include "chrome/browser/translate/component_cld_data_harness.h" |
| +#include "chrome/browser/translate/standalone_cld_data_harness.h" |
| + |
| +namespace { |
| + |
| +// This is the global instance managed by Get/Set |
| +test::CldDataHarnessFactory* g_instance = NULL; |
| + |
| +// Global instance wrappers |
| +class ComponentCldDataHarnessFactory : public test::CldDataHarnessFactory { |
| + public: |
| + virtual scoped_ptr<test::CldDataHarness> CreateCldDataHarness() override { |
| + return test::CldDataHarness::COMPONENT(); |
| + } |
|
jochen (gone - plz use gerrit)
2014/10/23 13:57:39
nit. disallow copy & assign, please also add virtu
Andrew Hayden (chromium.org)
2014/10/30 16:56:31
These classes have been purged. With fire.
|
| +}; |
|
jochen (gone - plz use gerrit)
2014/10/23 13:57:39
nit space after this line (and everywhere)
Andrew Hayden (chromium.org)
2014/10/30 16:56:32
Done.
|
| +struct WrappedComponent { |
| + WrappedComponent() { |
| + value = new ComponentCldDataHarnessFactory(); |
| + } |
| + test::CldDataHarnessFactory* value; |
|
jochen (gone - plz use gerrit)
2014/10/23 13:57:39
i don't understand why you need this pattern. Just
Andrew Hayden (chromium.org)
2014/10/30 16:56:31
Yep!
|
| +}; |
| +base::LazyInstance<WrappedComponent>::Leaky g_wrapped_component = |
| + LAZY_INSTANCE_INITIALIZER; |
| + |
| +class StandaloneCldDataHarnessFactory : public test::CldDataHarnessFactory { |
| + public: |
| + virtual scoped_ptr<test::CldDataHarness> CreateCldDataHarness() override { |
| + return test::CldDataHarness::STANDALONE(); |
| + } |
| +}; |
| +struct WrappedStandalone { |
| + WrappedStandalone() { |
| + value = new StandaloneCldDataHarnessFactory(); |
| + } |
| + test::CldDataHarnessFactory* value; |
| +}; |
| +base::LazyInstance<WrappedStandalone>::Leaky g_wrapped_standalone = |
| + LAZY_INSTANCE_INITIALIZER; |
| + |
| +class StaticCldDataHarnessFactory : public test::CldDataHarnessFactory { |
| + public: |
| + virtual scoped_ptr<test::CldDataHarness> CreateCldDataHarness() override { |
| + return test::CldDataHarness::STATIC(); |
| + } |
| +}; |
| +struct WrappedStatic { |
| + WrappedStatic() { |
| + value = new StaticCldDataHarnessFactory(); |
| + } |
| + test::CldDataHarnessFactory* value; |
| +}; |
| +base::LazyInstance<WrappedStatic>::Leaky g_wrapped_static = |
| + LAZY_INSTANCE_INITIALIZER; |
| + |
| +class NoneCldDataHarnessFactory : public test::CldDataHarnessFactory { |
| + public: |
| + virtual scoped_ptr<test::CldDataHarness> CreateCldDataHarness() override { |
| + return test::CldDataHarness::NONE(); |
| + } |
| +}; |
| +struct WrappedNone { |
| + WrappedNone() { |
| + value = new NoneCldDataHarnessFactory(); |
| + } |
| + test::CldDataHarnessFactory* value; |
| +}; |
| +base::LazyInstance<WrappedNone>::Leaky g_wrapped_none = |
| + LAZY_INSTANCE_INITIALIZER; |
| + |
| +} // namespace |
| + |
| +namespace test { |
| + |
| +CldDataHarnessFactory::CldDataHarnessFactory() { |
| + // Nothing |
| +} |
| + |
| +CldDataHarnessFactory::~CldDataHarnessFactory() { |
| + // Nothing |
| +} |
| + |
| +scoped_ptr<CldDataHarness> CldDataHarnessFactory::CreateCldDataHarness() { |
| + scoped_ptr<CldDataHarness> result(new CldDataHarness()); |
| + return result.Pass(); |
| +} |
| + |
| +CldDataHarnessFactory* CldDataHarnessFactory::Get() { |
| + if (g_instance == NULL) { |
| + return NONE(); |
| + } |
| + return g_instance; |
| +} |
| + |
| +void CldDataHarnessFactory::Set(CldDataHarnessFactory* instance) { |
| + g_instance = instance; |
| +} |
| + |
| +/* static */ CldDataHarnessFactory* CldDataHarnessFactory::NONE() { |
|
Takashi Toyoshima
2014/10/15 08:45:07
// static
CldDataHarnessFactory* CldDataHarnessFac
Andrew Hayden (chromium.org)
2014/10/30 16:56:31
Done everywhere
|
| + return g_wrapped_none.Get().value; |
| +} |
| + |
| +/* static */ CldDataHarnessFactory* CldDataHarnessFactory::STATIC() { |
| + return g_wrapped_static.Get().value; |
| +} |
| + |
| +/* static */ CldDataHarnessFactory* CldDataHarnessFactory::STANDALONE() { |
| + return g_wrapped_standalone.Get().value; |
| +} |
| + |
| +/* static */ CldDataHarnessFactory* CldDataHarnessFactory::COMPONENT() { |
| + return g_wrapped_component.Get().value; |
| +} |
| + |
| +} // namespace test |