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