OLD | NEW |
---|---|
(Empty) | |
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. | |
4 | |
5 #include "chrome/browser/translate/cld_data_harness_factory.h" | |
6 | |
7 #include "base/lazy_instance.h" | |
8 #include "chrome/browser/translate/component_cld_data_harness.h" | |
9 #include "chrome/browser/translate/standalone_cld_data_harness.h" | |
10 | |
11 namespace { | |
12 | |
13 // This is the global instance managed by Get/Set | |
14 test::CldDataHarnessFactory* g_instance = NULL; | |
15 | |
16 // Global instance wrappers | |
17 class ComponentCldDataHarnessFactory : public test::CldDataHarnessFactory { | |
18 public: | |
19 virtual scoped_ptr<test::CldDataHarness> CreateCldDataHarness() override { | |
20 return test::CldDataHarness::COMPONENT(); | |
21 } | |
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.
| |
22 }; | |
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.
| |
23 struct WrappedComponent { | |
24 WrappedComponent() { | |
25 value = new ComponentCldDataHarnessFactory(); | |
26 } | |
27 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!
| |
28 }; | |
29 base::LazyInstance<WrappedComponent>::Leaky g_wrapped_component = | |
30 LAZY_INSTANCE_INITIALIZER; | |
31 | |
32 class StandaloneCldDataHarnessFactory : public test::CldDataHarnessFactory { | |
33 public: | |
34 virtual scoped_ptr<test::CldDataHarness> CreateCldDataHarness() override { | |
35 return test::CldDataHarness::STANDALONE(); | |
36 } | |
37 }; | |
38 struct WrappedStandalone { | |
39 WrappedStandalone() { | |
40 value = new StandaloneCldDataHarnessFactory(); | |
41 } | |
42 test::CldDataHarnessFactory* value; | |
43 }; | |
44 base::LazyInstance<WrappedStandalone>::Leaky g_wrapped_standalone = | |
45 LAZY_INSTANCE_INITIALIZER; | |
46 | |
47 class StaticCldDataHarnessFactory : public test::CldDataHarnessFactory { | |
48 public: | |
49 virtual scoped_ptr<test::CldDataHarness> CreateCldDataHarness() override { | |
50 return test::CldDataHarness::STATIC(); | |
51 } | |
52 }; | |
53 struct WrappedStatic { | |
54 WrappedStatic() { | |
55 value = new StaticCldDataHarnessFactory(); | |
56 } | |
57 test::CldDataHarnessFactory* value; | |
58 }; | |
59 base::LazyInstance<WrappedStatic>::Leaky g_wrapped_static = | |
60 LAZY_INSTANCE_INITIALIZER; | |
61 | |
62 class NoneCldDataHarnessFactory : public test::CldDataHarnessFactory { | |
63 public: | |
64 virtual scoped_ptr<test::CldDataHarness> CreateCldDataHarness() override { | |
65 return test::CldDataHarness::NONE(); | |
66 } | |
67 }; | |
68 struct WrappedNone { | |
69 WrappedNone() { | |
70 value = new NoneCldDataHarnessFactory(); | |
71 } | |
72 test::CldDataHarnessFactory* value; | |
73 }; | |
74 base::LazyInstance<WrappedNone>::Leaky g_wrapped_none = | |
75 LAZY_INSTANCE_INITIALIZER; | |
76 | |
77 } // namespace | |
78 | |
79 namespace test { | |
80 | |
81 CldDataHarnessFactory::CldDataHarnessFactory() { | |
82 // Nothing | |
83 } | |
84 | |
85 CldDataHarnessFactory::~CldDataHarnessFactory() { | |
86 // Nothing | |
87 } | |
88 | |
89 scoped_ptr<CldDataHarness> CldDataHarnessFactory::CreateCldDataHarness() { | |
90 scoped_ptr<CldDataHarness> result(new CldDataHarness()); | |
91 return result.Pass(); | |
92 } | |
93 | |
94 CldDataHarnessFactory* CldDataHarnessFactory::Get() { | |
95 if (g_instance == NULL) { | |
96 return NONE(); | |
97 } | |
98 return g_instance; | |
99 } | |
100 | |
101 void CldDataHarnessFactory::Set(CldDataHarnessFactory* instance) { | |
102 g_instance = instance; | |
103 } | |
104 | |
105 /* 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
| |
106 return g_wrapped_none.Get().value; | |
107 } | |
108 | |
109 /* static */ CldDataHarnessFactory* CldDataHarnessFactory::STATIC() { | |
110 return g_wrapped_static.Get().value; | |
111 } | |
112 | |
113 /* static */ CldDataHarnessFactory* CldDataHarnessFactory::STANDALONE() { | |
114 return g_wrapped_standalone.Get().value; | |
115 } | |
116 | |
117 /* static */ CldDataHarnessFactory* CldDataHarnessFactory::COMPONENT() { | |
118 return g_wrapped_component.Get().value; | |
119 } | |
120 | |
121 } // namespace test | |
OLD | NEW |