| 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/macros.h" |
| 12 #include "base/synchronization/lock.h" |
| 13 |
| 10 namespace translate { | 14 namespace translate { |
| 11 | 15 |
| 12 // Provides high-level functionality related to a CLD Data Source. | 16 // Provides high-level functionality related to a CLD Data Source. |
| 13 class CldDataSource { | 17 class CldDataSource { |
| 14 | 18 |
| 15 public: | 19 public: |
| 20 // Generally not used by Chromium code, but available for embedders to |
| 21 // configure additional data sources as subclasses. |
| 22 // Chromium code should use the getters instead (GetStaticDataSource(), |
| 23 // GetStandaloneDataSource(), and GetComponentDataSource()). |
| 24 CldDataSource(); |
| 25 virtual ~CldDataSource() {} |
| 16 | 26 |
| 17 // Returns the symbolic name of the data source. In the Chromium | 27 // Returns the symbolic name of the data source. In the Chromium |
| 18 // open-source tree, the following data sources exist: | 28 // open-source tree, the following data sources exist: |
| 19 // static uses the static_[browser|renderer]_cld_data_provider | 29 // static uses the static_[browser|renderer]_cld_data_provider |
| 20 // implementations. | 30 // implementations. |
| 21 // standalone uses the data_file_[browser|renderer]_cld_data_provider | 31 // standalone uses the data_file_[browser|renderer]_cld_data_provider |
| 22 // implementations. | 32 // implementations. |
| 23 // component also uses the data_file_[browser|renderer]_cld_data_provider | 33 // component also uses the data_file_[browser|renderer]_cld_data_provider |
| 24 // implementations. | 34 // implementations. |
| 25 // | 35 // |
| 26 // Other implementations based upon Chromium may provide CLD differently and | 36 // Other implementations based upon Chromium may provide CLD differently and |
| 27 // may have other names. This method is primarily provided for those | 37 // may have other names. |
| 28 // non-Chromium implementations; Chromium implementations should use the | 38 // This method is threadsafe. |
| 29 // boolean methods in this class instead: | 39 virtual std::string GetName(); |
| 30 // ShouldRegisterForComponentUpdates() | |
| 31 // ShouldUseStandaloneDataFile() | |
| 32 static std::string GetName(); | |
| 33 | 40 |
| 34 // Returns true if the data source needs to receive updates from the | 41 // For data sources that support a separate CLD data file, configures the path |
| 35 // Component Updater. | 42 // of that data file. |
| 36 // This is only true if the data source name is "component", but makes caller | 43 // |
| 37 // logic more generic. | 44 // The 'component' and 'standalone' data sources need this method to be called |
| 38 static bool ShouldRegisterForComponentUpdates(); | 45 // in order to locate the CLD data on disk. |
| 46 // If the data source doesn't need or doesn't support such configuration, this |
| 47 // function is a no-op. This is the case for, e.g., the static data source. |
| 48 // This method is threadsafe. |
| 49 void SetCldDataFilePath(const base::FilePath& path); |
| 39 | 50 |
| 40 // Returns true if the data source needs to have the path to the CLD | 51 // Returns the path most recently set by SetCldDataFilePath. The initial value |
| 41 // data file configured immediately because it is bundled with Chromium. | 52 // prior to any such call is the empty path. If the data source doesn't |
| 42 // This is only true if the data source name is "standalone", but makes | 53 // support a data file, returns the empty path. |
| 43 // caller logic more generic. | 54 // This method is threadsafe. |
| 44 static bool ShouldUseStandaloneDataFile(); | 55 base::FilePath GetCldDataFilePath(); |
| 56 |
| 57 // Sets the default data source for this process, i.e. the data source to be |
| 58 // used unless the embedder calls Set(CldDatasource*). This is the method |
| 59 // that normal (i.e., non-test) Chromium code should use; embedders can and |
| 60 // should use the unconditional Set(CldDataSource*) method instead. If a |
| 61 // default data source has already been set, this method does nothing. |
| 62 static void SetDefault(CldDataSource* data_source); |
| 63 |
| 64 // Unconditionally sets the data source for this process, overwriting any |
| 65 // previously-configured default. Normal Chromium code should never use this |
| 66 // method; it is provided for embedders to inject a data source from outside |
| 67 // of the Chromium code base. Test code can also use this method to force the |
| 68 // runtime to have a desired behavior. |
| 69 static void Set(CldDataSource* data_source); |
| 70 |
| 71 // Returns the data source for this process. Guaranteed to never be null. |
| 72 // If no instance has been set, this returns the same object obtained by |
| 73 // calling GetStaticDataSource(), which is always safe but may fail to |
| 74 // function if the CLD data is not *actually* statically linked. |
| 75 static CldDataSource* Get(); |
| 76 |
| 77 // Fetch the global instance of the "static" data source. |
| 78 static CldDataSource* GetStaticDataSource(); |
| 79 |
| 80 // Fetch the global instance of the "standalone" data source. |
| 81 static CldDataSource* GetStandaloneDataSource(); |
| 82 |
| 83 // Fetch the global instance of the "component" data source. |
| 84 static CldDataSource* GetComponentDataSource(); |
| 85 |
| 86 private: |
| 87 base::FilePath m_cached_filepath; // Guarded by m_file_lock |
| 88 base::Lock m_file_lock; // Guards m_cached_filepath |
| 89 |
| 90 DISALLOW_COPY_AND_ASSIGN(CldDataSource); |
| 45 }; | 91 }; |
| 46 | 92 |
| 47 } // namespace translate | 93 } // namespace translate |
| 48 #endif // COMPONENTS_TRANSLATE_CONTENT_COMMON_CLD_DATA_SOURCE_H_ | 94 #endif // COMPONENTS_TRANSLATE_CONTENT_COMMON_CLD_DATA_SOURCE_H_ |
| OLD | NEW |