Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(99)

Side by Side Diff: chrome/browser/translate/cld_data_harness_factory.h

Issue 461633002: Refactor language detection logic to allow non-static CLD data sources. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Make some of the harness factory methods private Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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 "base/macros.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "chrome/browser/translate/cld_data_harness.h"
11
12 namespace test {
13
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.
19 //
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() {}
33
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();
38
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);
46
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();
54
55 private:
56 DISALLOW_COPY_AND_ASSIGN(CldDataHarnessFactory);
57
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();
62
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();
67
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();
72 };
73 } // namespace test
74
75 #endif // CHROME_BROWSER_TRANSLATE_CLD_DATA_HARNESS_FACTORY_H_
OLDNEW
« no previous file with comments | « chrome/browser/translate/cld_data_harness.cc ('k') | chrome/browser/translate/cld_data_harness_factory.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698