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

Unified Diff: components/translate/content/renderer/renderer_cld_data_provider.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: 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 side-by-side diff with in-line comments
Download patch
Index: components/translate/content/renderer/renderer_cld_data_provider.cc
diff --git a/components/translate/content/renderer/renderer_cld_data_provider.cc b/components/translate/content/renderer/renderer_cld_data_provider.cc
new file mode 100644
index 0000000000000000000000000000000000000000..d97f3bc61f83168d681f79947589f979c495ae8f
--- /dev/null
+++ b/components/translate/content/renderer/renderer_cld_data_provider.cc
@@ -0,0 +1,59 @@
+// 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 "base/lazy_instance.h"
+#include "components/translate/content/renderer/renderer_cld_data_provider.h"
+
+namespace {
+
+// Our global default instance, alive for the entire lifetime of the process.
+translate::RendererCldDataProvider* g_instance = NULL;
+
+// The default factory, which produces no-op instances of
+// RendererCldDataProvider suitable for use when CLD data is statically-linked.
+base::LazyInstance<translate::RendererCldDataProvider>::Leaky
+g_wrapped_default = LAZY_INSTANCE_INITIALIZER;
+
+} // namespace
+
+
+namespace translate {
+
+bool RendererCldDataProvider::IsCldDataAvailable() {
+ return true;
+}
+
+bool RendererCldDataProvider::OnMessageReceived(const IPC::Message& message) {
+ return false; // Message not handled
+}
+
+void RendererCldDataProvider::SetCldAvailableCallback
+(base::Callback<void(void)> callback) {
+ callback.Run();
+}
+
+// static
+void RendererCldDataProvider::SetDefault(
+ RendererCldDataProvider* instance) {
+ if (!IsInitialized()) Set(instance);
+}
+
+// static
+void RendererCldDataProvider::Set(
+ RendererCldDataProvider* instance) {
+ g_instance = instance;
+}
+
+// static
+bool RendererCldDataProvider::IsInitialized() {
+ return g_instance != NULL;
+}
+
+// static
+RendererCldDataProvider* RendererCldDataProvider::Get() {
+ if (IsInitialized()) return g_instance;
+ return &g_wrapped_default.Get();
+}
+
+} // namespace translate

Powered by Google App Engine
This is Rietveld 408576698