| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef COMPONENTS_TRANSLATE_CONTENT_COMMON_CLD_DATA_SOURCE_H_ | 5 #ifndef COMPONENTS_TRANSLATE_CONTENT_COMMON_CLD_DATA_SOURCE_H_ |
| 6 #define COMPONENTS_TRANSLATE_CONTENT_COMMON_CLD_DATA_SOURCE_H_ | 6 #define COMPONENTS_TRANSLATE_CONTENT_COMMON_CLD_DATA_SOURCE_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/files/file_path.h" |
| 11 #include "base/synchronization/lock.h" |
| 12 |
| 10 namespace translate { | 13 namespace translate { |
| 11 | 14 |
| 12 // Provides high-level functionality related to a CLD Data Source. | 15 // Provides high-level functionality related to a CLD Data Source. |
| 13 class CldDataSource { | 16 class CldDataSource { |
| 14 | 17 |
| 15 public: | 18 public: |
| 19 CldDataSource(std::string name, |
| 20 bool register_for_component_updates, |
| 21 bool use_standalone_data_file); |
| 22 virtual ~CldDataSource() {} |
| 16 | 23 |
| 17 // Returns the symbolic name of the data source. In the Chromium | 24 // Returns the symbolic name of the data source. In the Chromium |
| 18 // open-source tree, the following data sources exist: | 25 // open-source tree, the following data sources exist: |
| 19 // static uses the static_[browser|renderer]_cld_data_provider | 26 // static uses the static_[browser|renderer]_cld_data_provider |
| 20 // implementations. | 27 // implementations. |
| 21 // standalone uses the data_file_[browser|renderer]_cld_data_provider | 28 // standalone uses the data_file_[browser|renderer]_cld_data_provider |
| 22 // implementations. | 29 // implementations. |
| 23 // component also uses the data_file_[browser|renderer]_cld_data_provider | 30 // component also uses the data_file_[browser|renderer]_cld_data_provider |
| 24 // implementations. | 31 // implementations. |
| 25 // | 32 // |
| 26 // Other implementations based upon Chromium may provide CLD differently and | 33 // Other implementations based upon Chromium may provide CLD differently and |
| 27 // may have other names. This method is primarily provided for those | 34 // may have other names. This method is primarily provided for those |
| 28 // non-Chromium implementations; Chromium implementations should use the | 35 // non-Chromium implementations; Chromium implementations should use the |
| 29 // boolean methods in this class instead: | 36 // boolean methods in this class instead: |
| 30 // ShouldRegisterForComponentUpdates() | 37 // ShouldRegisterForComponentUpdates() |
| 31 // ShouldUseStandaloneDataFile() | 38 // ShouldUseStandaloneDataFile() |
| 32 static std::string GetName(); | 39 virtual std::string GetName(); |
| 33 | 40 |
| 34 // Returns true if the data source needs to receive updates from the | 41 // Returns true if the data source needs to receive updates from the |
| 35 // Component Updater. | 42 // Component Updater. |
| 36 // This is only true if the data source name is "component", but makes caller | 43 // This is only true if the data source name is "component", but makes caller |
| 37 // logic more generic. | 44 // logic more generic. |
| 38 static bool ShouldRegisterForComponentUpdates(); | 45 virtual bool ShouldRegisterForComponentUpdates(); |
| 39 | 46 |
| 40 // Returns true if the data source needs to have the path to the CLD | 47 // Returns true if the data source needs to have the path to the CLD |
| 41 // data file configured immediately because it is bundled with Chromium. | 48 // data file configured immediately because it is bundled with Chromium. |
| 42 // This is only true if the data source name is "standalone", but makes | 49 // This is only true if the data source name is "standalone", but makes |
| 43 // caller logic more generic. | 50 // caller logic more generic. |
| 44 static bool ShouldUseStandaloneDataFile(); | 51 virtual bool ShouldUseStandaloneDataFile(); |
| 52 |
| 53 // For data sources that support a separate CLD data file, configures the path |
| 54 // of that data file. |
| 55 // |
| 56 // The 'component' and 'standalone' data sources need this method to be called |
| 57 // in order to locate the CLD data on disk. |
| 58 // If the data source doesn't need or doesn't support such configuration, this |
| 59 // function is a no-op. This is the case for, e.g., the static data source. |
| 60 // This method is threadsafe. |
| 61 void SetCldDataFilePath(const base::FilePath& path); |
| 62 |
| 63 // Returns the path most recently set by SetCldDataFilePath. The initial value |
| 64 // prior to any such call is the empty path. If the data source doesn't |
| 65 // support a data file, returns the empty path. |
| 66 // This method is threadsafe. |
| 67 base::FilePath GetCldDataFilePath(); |
| 68 |
| 69 // Sets the data source for this process, optionally overwriting the previous |
| 70 // value. Embedders and narrow use-cases (such as shells and test code) should |
| 71 // use the overwrite capability, while generic code should not. |
| 72 static void Set(CldDataSource* data_source, bool overwrite); |
| 73 |
| 74 // Returns the data source for this process. |
| 75 static CldDataSource* Get(); |
| 76 |
| 77 // Fetch the global instance of the "NONE" data source, i.e. a data source |
| 78 // that gracefully does nothing. Callers should set this data source if it is |
| 79 // the intent that there truly be no source of CLD data; this will result in |
| 80 // language detection (and subsequently, translation) being unavailable. |
| 81 // This is provided for convenience, to avoid a bunch of trivial subclasses |
| 82 // whose only differences are in their unique combination of read-only values. |
| 83 static CldDataSource* NONE(); |
| 84 |
| 85 // Fetch the global instance of the "static" data source. |
| 86 // This is provided for convenience, to avoid a bunch of trivial subclasses |
| 87 // whose only differences are in their unique combination of read-only values. |
| 88 static CldDataSource* STATIC(); |
| 89 |
| 90 // Fetch the global instance of the "standalone" data source. |
| 91 // This is provided for convenience, to avoid a bunch of trivial subclasses |
| 92 // whose only differences are in their unique combination of read-only values. |
| 93 static CldDataSource* STANDALONE(); |
| 94 |
| 95 // Fetch the global instance of the "component" data source. |
| 96 // This is provided for convenience, to avoid a bunch of trivial subclasses |
| 97 // whose only differences are in their unique combination of read-only values. |
| 98 static CldDataSource* COMPONENT(); |
| 99 |
| 100 protected: |
| 101 const std::string m_name; |
| 102 const bool m_register_for_component_updates; |
| 103 const bool m_use_standalone_data_file; |
| 104 base::FilePath m_cached_filepath; // Guarded by m_file_lock |
| 105 base::Lock m_file_lock; // Guards m_cached_filepath |
| 106 |
| 45 }; | 107 }; |
| 46 | 108 |
| 47 } // namespace translate | 109 } // namespace translate |
| 48 #endif // COMPONENTS_TRANSLATE_CONTENT_COMMON_CLD_DATA_SOURCE_H_ | 110 #endif // COMPONENTS_TRANSLATE_CONTENT_COMMON_CLD_DATA_SOURCE_H_ |
| OLD | NEW |