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 #ifndef CHROME_BROWSER_TRANSLATE_CLD_DATA_HARNESS_FACTORY_H_ | |
6 #define CHROME_BROWSER_TRANSLATE_CLD_DATA_HARNESS_FACTORY_H_ | |
7 | |
8 #include <memory> | |
9 | |
10 #include "base/macros.h" | |
11 #include "chrome/browser/translate/cld_data_harness.h" | |
12 | |
13 namespace test { | |
14 | |
15 // Testing class that allows embedders to inject an arbitrary CldDataHarness | |
16 // implementation into the runtime by defining a subclass of | |
17 // CldDataHarnessFactory and setting the global instance of it with | |
18 // Set(CldDataHarnessFactory*). Chromium code should use the factory instance | |
19 // returned by Get() to obtain CldDataHarness instances. | |
20 // | |
21 // There is significant nuance to obtaining a CldDataHarness object at runtime. | |
22 // For each of the "stock" CldDataSource implementations ("standalone", | |
23 // "static" and "component"), a CldDataHarness implementation is available and | |
24 // the default implementation of the CldDataHarnessFactory class knows how to | |
25 // do the right thing; but embedders can provider entirely custom CldDataSource | |
26 // implementations, and browser tests need to be able to use those data sources | |
27 // correctly at test time. Embedders implement a subclass of | |
28 // CldDataHarnessFactory and set it using Set(), below, to enable browser tests | |
29 // to function as realistically as possible with the embedder's data source. | |
30 class CldDataHarnessFactory { | |
31 public: | |
32 CldDataHarnessFactory() {} | |
33 virtual ~CldDataHarnessFactory() {} | |
34 | |
35 // Create a new CldDataHarness. | |
36 // The default implementation returns a simple CldDataHarness, which is | |
37 // likely to be incorrect for most non-static CLD use cases. | |
38 virtual std::unique_ptr<CldDataHarness> CreateCldDataHarness(); | |
39 | |
40 // Unconditionally sets the factory for this process, overwriting any | |
41 // previously-configured value. Open-source Chromium test code should almost | |
42 // never use this method; it is provided for embedders to inject a factory | |
43 // from outside of the Chromium code base. By default, the choice of which | |
44 // factory to use is based on the currently-configured CldDataSource when | |
45 // calling Get() (see below). | |
46 static void Set(CldDataHarnessFactory* instance); | |
47 | |
48 // Returns the CldDataHarnessFactory instance previously set for the process, | |
49 // if one has been set; otherwise, if the currently configured CldDataSource | |
50 // is one of the available open-source types defined in CldDataSource, returns | |
51 // a compatible harness. Otherwise (e.g., no specific instance has been set | |
52 // and the CldDataSource is not one of the known open-source implementations), | |
53 // debug builds will crash while release builds will return a no-op harness. | |
54 static CldDataHarnessFactory* Get(); | |
55 | |
56 private: | |
57 DISALLOW_COPY_AND_ASSIGN(CldDataHarnessFactory); | |
58 | |
59 // Fetch the global instance of the "static" factory that produces a harness | |
60 // suitable for use with the "static" CLD data source. | |
61 // Only use to call Set(CldDataHarnessFactory*). | |
62 static CldDataHarnessFactory* GetStaticDataHarnessFactory(); | |
63 | |
64 // Fetch the global instance of the "standalone" factory that produces a | |
65 // harness suitable for use with the "standalone" CLD data source. | |
66 // Only use to call Set(CldDataHarnessFactory*). | |
67 static CldDataHarnessFactory* GetStandaloneDataHarnessFactory(); | |
68 | |
69 // Fetch the global instance of the "component" factory that produces a | |
70 // harness suitable for use with the "component" CLD data source. | |
71 // Only use to call Set(CldDataHarnessFactory*). | |
72 static CldDataHarnessFactory* GetComponentDataHarnessFactory(); | |
73 }; | |
74 } // namespace test | |
75 | |
76 #endif // CHROME_BROWSER_TRANSLATE_CLD_DATA_HARNESS_FACTORY_H_ | |
OLD | NEW |