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..6ef878fc35fd4cc8bb1a76d7db0d79dc74f44afe |
--- /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; |
+ |
picksi1
2014/09/29 15:59:08
Is this the preferred chromium way of implementing
Andrew Hayden (chromium.org)
2014/10/30 14:25:14
Yes. However, I am going to cheat heavily and work
|
+// Global instance wrappers |
+class ComponentCldDataHarnessFactory : public test::CldDataHarnessFactory { |
+ public: |
picksi1
2014/09/29 15:59:08
This looks like it is derived from a test class, w
Andrew Hayden (chromium.org)
2014/10/30 14:25:15
I think you'll like the new version much better.
|
+ virtual scoped_ptr<test::CldDataHarness> CreateCldDataHarness() OVERRIDE { |
+ return test::CldDataHarness::COMPONENT(); |
+ } |
+}; |
+struct WrappedComponent { |
+ WrappedComponent() { |
+ value = new ComponentCldDataHarnessFactory(); |
+ } |
+ test::CldDataHarnessFactory* value; |
picksi1
2014/09/29 15:59:08
Is the name 'value' correct here? Looks like it sh
Andrew Hayden (chromium.org)
2014/10/30 14:25:15
Idiomatic, but now deleted.
|
+}; |
+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() { |
+ 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 |