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

Unified Diff: components/translate/content/common/cld_data_source.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: Fix merge error in chrome/browser/BUILD.gn 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: components/translate/content/common/cld_data_source.h
diff --git a/components/translate/content/common/cld_data_source.h b/components/translate/content/common/cld_data_source.h
index 07a56b0437a6894c0ff105608f86ff68a9126033..d8b1af9169a8b3424739061d55102f890954fee8 100644
--- a/components/translate/content/common/cld_data_source.h
+++ b/components/translate/content/common/cld_data_source.h
@@ -7,12 +7,19 @@
#include <string>
+#include "base/files/file_path.h"
+#include "base/synchronization/lock.h"
+
namespace translate {
// Provides high-level functionality related to a CLD Data Source.
class CldDataSource {
public:
+ CldDataSource(std::string name,
jochen (gone - plz use gerrit) 2014/10/23 13:57:39 consider using an enum instead of two bools, as on
Andrew Hayden (chromium.org) 2014/10/30 16:56:32 Totally rebuilt this, now using singletons with id
+ bool register_for_component_updates,
+ bool use_standalone_data_file);
+ virtual ~CldDataSource() {}
// Returns the symbolic name of the data source. In the Chromium
// open-source tree, the following data sources exist:
@@ -29,19 +36,76 @@ class CldDataSource {
// boolean methods in this class instead:
// ShouldRegisterForComponentUpdates()
// ShouldUseStandaloneDataFile()
- static std::string GetName();
+ virtual std::string GetName();
// Returns true if the data source needs to receive updates from the
// Component Updater.
// This is only true if the data source name is "component", but makes caller
// logic more generic.
- static bool ShouldRegisterForComponentUpdates();
+ virtual bool ShouldRegisterForComponentUpdates();
// Returns true if the data source needs to have the path to the CLD
// data file configured immediately because it is bundled with Chromium.
// This is only true if the data source name is "standalone", but makes
// caller logic more generic.
- static bool ShouldUseStandaloneDataFile();
+ virtual bool ShouldUseStandaloneDataFile();
+
+ // For data sources that support a separate CLD data file, configures the path
+ // of that data file.
+ //
+ // The 'component' and 'standalone' data sources need this method to be called
+ // in order to locate the CLD data on disk.
+ // If the data source doesn't need or doesn't support such configuration, this
+ // function is a no-op. This is the case for, e.g., the static data source.
+ // This method is threadsafe.
+ void SetCldDataFilePath(const base::FilePath& path);
+
+ // Returns the path most recently set by SetCldDataFilePath. The initial value
+ // prior to any such call is the empty path. If the data source doesn't
+ // support a data file, returns the empty path.
+ // This method is threadsafe.
+ base::FilePath GetCldDataFilePath();
+
+ // Sets the data source for this process, optionally overwriting the previous
+ // value. Embedders and narrow use-cases (such as shells and test code) should
+ // use the overwrite capability, while generic code should not.
+ static void Set(CldDataSource* data_source, bool overwrite);
+
+ // Returns the data source for this process. Guaranteed to never be null.
+ // If no instance has been set, this returns the same object obtained by
+ // calling NONE().
+ static CldDataSource* Get();
+
+ // Fetch the global instance of the "NONE" data source, i.e. a data source
+ // that gracefully does nothing. Callers should set this data source if it is
+ // the intent that there truly be no source of CLD data; this will result in
+ // language detection (and subsequently, translation) being unavailable.
+ // This is provided for convenience, to avoid a bunch of trivial subclasses
+ // whose only differences are in their unique combination of read-only values.
+ static CldDataSource* NONE();
+
+ // Fetch the global instance of the "static" data source.
+ // This is provided for convenience, to avoid a bunch of trivial subclasses
+ // whose only differences are in their unique combination of read-only values.
+ static CldDataSource* STATIC();
+
+ // Fetch the global instance of the "standalone" data source.
+ // This is provided for convenience, to avoid a bunch of trivial subclasses
+ // whose only differences are in their unique combination of read-only values.
+ static CldDataSource* STANDALONE();
+
+ // Fetch the global instance of the "component" data source.
+ // This is provided for convenience, to avoid a bunch of trivial subclasses
+ // whose only differences are in their unique combination of read-only values.
+ static CldDataSource* COMPONENT();
+
+ protected:
+ const std::string m_name;
+ const bool m_register_for_component_updates;
+ const bool m_use_standalone_data_file;
+ base::FilePath m_cached_filepath; // Guarded by m_file_lock
+ base::Lock m_file_lock; // Guards m_cached_filepath
+
};
jochen (gone - plz use gerrit) 2014/10/23 13:57:39 disallow copy/assign
Andrew Hayden (chromium.org) 2014/10/30 16:56:32 Acknowledged.
} // namespace translate

Powered by Google App Engine
This is Rietveld 408576698