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

Unified Diff: chrome/browser/translate/cld_data_harness_factory.cc

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: Fix linux/mac/windows compile issues Created 6 years, 2 months 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 side-by-side diff with in-line comments
Download patch
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..d232a8be6aa0c106aa0a4ecb0c8b98bfd70e0f13
--- /dev/null
+++ b/chrome/browser/translate/cld_data_harness_factory.cc
@@ -0,0 +1,69 @@
+// 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;
+
+base::LazyInstance<test::CldDataHarnessFactory>::Leaky g_wrapped_component =
+ LAZY_INSTANCE_INITIALIZER;
+base::LazyInstance<test::CldDataHarnessFactory>::Leaky g_wrapped_standalone =
+ LAZY_INSTANCE_INITIALIZER;
+base::LazyInstance<test::CldDataHarnessFactory>::Leaky g_wrapped_static =
+ LAZY_INSTANCE_INITIALIZER;
+
+} // namespace
+
+namespace test {
+
+scoped_ptr<CldDataHarness> CldDataHarnessFactory::CreateCldDataHarness() {
Takashi Toyoshima 2014/11/06 14:34:28 I may miss something, but this design looks redund
Andrew Hayden (chromium.org) 2014/11/10 14:06:35 Tricky question. Each platform needs to be able to
Takashi Toyoshima 2014/11/11 07:16:36 Thank you for additional comments. So, now I under
+ if (this == GetStaticDataHarnessFactory()) {
+ return CldDataHarness::CreateStaticDataHarness();
+ }
+ if (this == GetStandaloneDataHarnessFactory()) {
+ return CldDataHarness::CreateStandaloneDataHarness();
+ }
+ if (this == GetComponentDataHarnessFactory()) {
+ return CldDataHarness::CreateComponentDataHarness();
+ }
+ NOTREACHED() << "Subclass failed to override CreateCldDataHarness()";
+ return CldDataHarness::CreateStaticDataHarness();
+}
+
+CldDataHarnessFactory* CldDataHarnessFactory::Get() {
+ DCHECK(g_instance != NULL) << "No CLD data harness factory was configured!";
+ if (g_instance != NULL) return g_instance;
+ return g_instance;
+}
+
+void CldDataHarnessFactory::Set(CldDataHarnessFactory* instance) {
+ g_instance = instance;
+}
+
+// static
+CldDataHarnessFactory*
+CldDataHarnessFactory::GetStaticDataHarnessFactory() {
+ return &g_wrapped_static.Get();
+}
+
+// static
+CldDataHarnessFactory*
+CldDataHarnessFactory::GetStandaloneDataHarnessFactory() {
+ return &g_wrapped_standalone.Get();
+}
+
+// static
+CldDataHarnessFactory*
+CldDataHarnessFactory::GetComponentDataHarnessFactory() {
+ return &g_wrapped_component.Get();
+}
+
+} // namespace test

Powered by Google App Engine
This is Rietveld 408576698