Deprecate |ConfigHandler::GetConfig()|
Returning an object reference to a global object is considered harmful.
Suppose the following code:
const auto &config = ConfigHandler::GetConfig();
// Observe the contents of |config| here (*1)
ConfigHandler::SetConfig(new_config);
// Observe the contents of |config| here (*2)
Since const reference does not necessary mean that the object is
immutable, you can observe that the contents of |config| was changed
between (*1) and (*2).
We really should use |ConfigHandler::GetConfig(Config *config)| instead
to avoid this kind of troubles.
BUG=
TEST=
REF_BUG=19188911,27179403
REF_CL=114656064
REF_TIME=2016-02-14T17:36:30-08:00
REF_TIME_RAW=1455500190 -0800
Yohei Yukawa
8 years ago
585 | 585 | } |
586 | 586 | |
587 | 587 | CharacterFormManager::CharacterFormManager() : data_(new Data) { |
588 | ReloadConfig(ConfigHandler::GetConfig()); | |
588 | Config config; | |
589 | ConfigHandler::GetConfig(&config); | |
590 | ReloadConfig(config); | |
589 | 591 | } |
590 | 592 | |
591 | 593 | CharacterFormManager::~CharacterFormManager() { |
84 | 84 | ConfigHandler::GetDefaultConfig(&default_config_); |
85 | 85 | } |
86 | 86 | virtual ~ConfigHandlerImpl() {} |
87 | const Config &GetConfig() const; | |
88 | 87 | bool GetConfig(Config *config) const; |
89 | 88 | const Config &DefaultConfig() const; |
90 | 89 | bool GetStoredConfig(Config *config) const; |
112 | 111 | return Singleton<ConfigHandlerImpl>::get(); |
113 | 112 | } |
114 | 113 | |
115 | const Config &ConfigHandlerImpl::GetConfig() const { | |
116 | return merged_config_; | |
117 | } | |
118 | ||
119 | 114 | // return current Config |
120 | 115 | bool ConfigHandlerImpl::GetConfig(Config *config) const { |
121 | 116 | config->CopyFrom(merged_config_); |
237 | 232 | return filename_; |
238 | 233 | } |
239 | 234 | } // namespace |
240 | ||
241 | const Config &ConfigHandler::GetConfig() { | |
242 | return GetConfigHandlerImpl()->GetConfig(); | |
243 | } | |
244 | 235 | |
245 | 236 | // Returns current Config |
246 | 237 | bool ConfigHandler::GetConfig(Config *config) { |
47 | 47 | class ConfigHandler { |
48 | 48 | public: |
49 | 49 | // Returns current config. |
50 | static const Config &GetConfig(); | |
51 | ||
52 | // Returns current config. | |
53 | 50 | static bool GetConfig(Config *config); |
54 | 51 | |
55 | 52 | // Returns stored config. |
77 | 74 | |
78 | 75 | // Gets default config value. |
79 | 76 | // |
80 | // Using this function is safer than | |
81 | // using an uninitialized config value. | |
77 | // Using these functions are safer than using an uninitialized config value. | |
78 | // These functions are also thread-safe. | |
82 | 79 | static void GetDefaultConfig(Config *config); |
83 | 80 | static const Config &DefaultConfig(); |
84 | 81 |
189 | 189 | output.Clear(); |
190 | 190 | EXPECT_TRUE(config::ConfigHandler::GetConfig(&output)); |
191 | 191 | EXPECT_EQ(expected, output.incognito_mode()); |
192 | output = config::ConfigHandler::GetConfig(); | |
192 | config::ConfigHandler::GetConfig(&output); | |
193 | 193 | EXPECT_EQ(expected, output.incognito_mode()); |
194 | 194 | config::ConfigHandler::GetStoredConfig(&output); |
195 | 195 | EXPECT_EQ(stored_config_value, output.incognito_mode()); |
200 | 200 | output.Clear(); |
201 | 201 | EXPECT_TRUE(config::ConfigHandler::GetConfig(&output)); |
202 | 202 | EXPECT_EQ(expected, output.incognito_mode()); |
203 | output = config::ConfigHandler::GetConfig(); | |
203 | config::ConfigHandler::GetConfig(&output); | |
204 | 204 | EXPECT_EQ(expected, output.incognito_mode()); |
205 | 205 | config::ConfigHandler::GetStoredConfig(&output); |
206 | 206 | EXPECT_EQ(stored_config_value, output.incognito_mode()); |
212 | 212 | output.Clear(); |
213 | 213 | EXPECT_TRUE(config::ConfigHandler::GetConfig(&output)); |
214 | 214 | EXPECT_EQ(stored_config_value, output.incognito_mode()); |
215 | output = config::ConfigHandler::GetConfig(); | |
215 | config::ConfigHandler::GetConfig(&output); | |
216 | 216 | EXPECT_EQ(stored_config_value, output.incognito_mode()); |
217 | 217 | config::ConfigHandler::GetStoredConfig(&output); |
218 | 218 | EXPECT_EQ(stored_config_value, output.incognito_mode()); |
239 | 239 | ScopedSetConfigFileName scoped_config_file_name( |
240 | 240 | "memory://set_config_file_name_test.db"); |
241 | 241 | // After SetConfigFileName called, settings are set as default. |
242 | EXPECT_EQ(default_incognito_mode, | |
243 | config::ConfigHandler::GetConfig().incognito_mode()); | |
242 | config::Config updated_config; | |
243 | config::ConfigHandler::GetConfig(&updated_config); | |
244 | EXPECT_EQ(default_incognito_mode, updated_config.incognito_mode()); | |
244 | 245 | } |
245 | 246 | |
246 | 247 | #if !defined(OS_ANDROID) && !defined(OS_NACL) |
233 | 233 | virtual ~AndroidStatsConfigUtilImpl() { |
234 | 234 | } |
235 | 235 | virtual bool IsEnabled() { |
236 | return ConfigHandler::GetConfig().general_config().upload_usage_stats(); | |
236 | Config config; | |
237 | ConfigHandler::GetConfig(&config); | |
238 | return config.general_config().upload_usage_stats(); | |
237 | 239 | } |
238 | 240 | virtual bool SetEnabled(bool val) { |
239 | 241 | // TODO(horo): Implement this. |
253 | 255 | virtual ~NaclStatsConfigUtilImpl() { |
254 | 256 | } |
255 | 257 | virtual bool IsEnabled() { |
256 | return ConfigHandler::GetConfig().general_config().upload_usage_stats(); | |
258 | Config config; | |
259 | ConfigHandler::GetConfig(&config); | |
260 | return config.general_config().upload_usage_stats(); | |
257 | 261 | } |
258 | 262 | virtual bool SetEnabled(bool val) { |
259 | 263 | return false; |
0 | 0 | MAJOR=2 |
1 | 1 | MINOR=17 |
2 | BUILD=2482 | |
2 | BUILD=2483 | |
3 | 3 | REVISION=102 |
4 | 4 | # NACL_DICTIONARY_VERSION is the target version of the system dictionary to be |
5 | 5 | # downloaded by NaCl Mozc. |
181 | 181 | VLOG(2) << "timeout is set to be : " << timeout_; |
182 | 182 | |
183 | 183 | #ifndef NO_LOGGING |
184 | const config::Config &config = config::ConfigHandler::GetConfig(); | |
184 | config::Config config; | |
185 | config::ConfigHandler::GetConfig(&config); | |
185 | 186 | Logging::SetConfigVerboseLevel(config.verbose_level()); |
186 | 187 | #endif // NO_LOGGING |
187 | 188 | } |
46 | 46 | class ImeSwitchUtilImpl { |
47 | 47 | public: |
48 | 48 | ImeSwitchUtilImpl() { |
49 | ReloadConfig(config::ConfigHandler::GetConfig()); | |
49 | config::Config config; | |
50 | config::ConfigHandler::GetConfig(&config); | |
51 | ReloadConfig(config); | |
50 | 52 | } |
51 | 53 | |
52 | 54 | bool IsDirectModeCommand(const commands::KeyEvent &key) const { |
257 | 257 | |
258 | 258 | bool SessionHandler::Reload(commands::Command *command) { |
259 | 259 | VLOG(1) << "Reloading server"; |
260 | SetConfig(config::ConfigHandler::GetConfig()); | |
260 | { | |
261 | config::Config config; | |
262 | config::ConfigHandler::GetConfig(&config); | |
263 | SetConfig(config); | |
264 | } | |
261 | 265 | engine_->Reload(); |
262 | 266 | return true; |
263 | 267 | } |
655 | 659 | |
656 | 660 | // Ensure the onmemory config is same as the locally stored one |
657 | 661 | // because the local data could be changed by sync. |
658 | SetConfig(config::ConfigHandler::GetConfig()); | |
662 | { | |
663 | config::Config config; | |
664 | config::ConfigHandler::GetConfig(&config); | |
665 | SetConfig(config); | |
666 | } | |
659 | 667 | |
660 | 668 | // session is not empty. |
661 | 669 | last_session_empty_time_ = 0; |
49 | 49 | |
50 | 50 | // Prints a greeting message when a process starts. |
51 | 51 | void PrintGreetingMessage() { |
52 | const mozc::config::Config &config = mozc::config::ConfigHandler::GetConfig(); | |
52 | mozc::config::Config config; | |
53 | mozc::config::ConfigHandler::GetConfig(&config); | |
53 | 54 | const char *preedit_method = "unknown"; |
54 | 55 | switch (config.preedit_method()) { |
55 | 56 | case mozc::config::Config::ROMAN: |
356 | 356 | AndroidUtil::kSystemPropertyModel, "Unknown"))); |
357 | 357 | #endif // OS_ANDROID |
358 | 358 | |
359 | UsageStatsUpdater::UpdateStats(config::ConfigHandler::GetConfig()); | |
359 | { | |
360 | config::Config config; | |
361 | config::ConfigHandler::GetConfig(&config); | |
362 | UsageStatsUpdater::UpdateStats(config); | |
363 | } | |
360 | 364 | |
361 | 365 | UploadUtil uploader; |
362 | 366 | uploader.SetHeader("Daily", elapsed_sec, params); |
73 | 73 | StaticConfigSnapshot GetConfigSnapshotForNonSandboxedProcess() { |
74 | 74 | Config config; |
75 | 75 | // config1.db should be readable in this case. |
76 | config.CopyFrom(config::ConfigHandler::GetConfig()); | |
76 | config::ConfigHandler::GetConfig(&config); | |
77 | 77 | |
78 | 78 | StaticConfigSnapshot snapshot = {}; |
79 | 79 | snapshot.use_kana_input = (config.preedit_method() == Config::KANA); |
97 | 97 | static once_t g_launch_set_default_dialog = MOZC_ONCE_INIT; |
98 | 98 | |
99 | 99 | void LaunchSetDefaultDialog() { |
100 | const config::Config &config = config::ConfigHandler::GetConfig(); | |
100 | config::Config config; | |
101 | config::ConfigHandler::GetConfig(&config); | |
101 | 102 | if (config.has_check_default() && !config.check_default()) { |
102 | 103 | // User opted out the default IME checking. Do nothing. |
103 | 104 | return; |