diff --git a/src/config/BUILD.bazel b/src/config/BUILD.bazel index 1bbd02049..2b8c3df59 100644 --- a/src/config/BUILD.bazel +++ b/src/config/BUILD.bazel @@ -98,9 +98,7 @@ mozc_cc_library( visibility = [ "//:__subpackages__", ], - deps = [ - "//base:singleton", - ] + mozc_select( + deps = mozc_select( android = [ ":config_handler", "//protocol:config_cc_proto", @@ -152,13 +150,6 @@ mozc_cc_test( ), ) -mozc_cc_library( - name = "stats_config_util_mock", - testonly = True, - hdrs = ["stats_config_util_mock.h"], - deps = [":stats_config_util"], -) - mozc_cc_library( name = "character_form_manager", srcs = ["character_form_manager.cc"], diff --git a/src/config/stats_config_util.cc b/src/config/stats_config_util.cc index 6c6af9f5d..e977ea94a 100644 --- a/src/config/stats_config_util.cc +++ b/src/config/stats_config_util.cc @@ -29,8 +29,6 @@ #include "config/stats_config_util.h" -#include "base/singleton.h" - #ifdef _WIN32 #include #include @@ -80,10 +78,10 @@ constexpr wchar_t kOmahaUsageKeyForEveryone[] = constexpr wchar_t kSendStatsName[] = L"usagestats"; -class WinStatsConfigUtilImpl : public StatsConfigUtilInterface { +class WinStatsConfigUtilImpl { public: - bool IsEnabled() override; - bool SetEnabled(bool val) override; + static bool IsEnabled(); + static bool SetEnabled(bool val); }; bool WinStatsConfigUtilImpl::IsEnabled() { @@ -156,10 +154,10 @@ std::string GetConfigFilePath() { "/.usagestats.db"); // hidden file } -class MacStatsConfigUtilImpl : public StatsConfigUtilInterface { +class MacStatsConfigUtilImpl { public: - bool IsEnabled() override; - bool SetEnabled(bool val) override; + static bool IsEnabled(); + static bool SetEnabled(bool val); }; bool MacStatsConfigUtilImpl::IsEnabled() { @@ -216,12 +214,12 @@ bool MacStatsConfigUtilImpl::SetEnabled(bool val) { #endif // MACOSX #ifdef __ANDROID__ -class AndroidStatsConfigUtilImpl : public StatsConfigUtilInterface { +class AndroidStatsConfigUtilImpl { public: - bool IsEnabled() override { + static bool IsEnabled() { return ConfigHandler::GetSharedConfig()->upload_usage_stats(); } - bool SetEnabled(bool val) override { + static bool SetEnabled(bool val) { // TODO(horo): Implement this. return false; } @@ -230,16 +228,12 @@ class AndroidStatsConfigUtilImpl : public StatsConfigUtilInterface { #endif // GOOGLE_JAPANESE_INPUT_BUILD -class NullStatsConfigUtilImpl : public StatsConfigUtilInterface { +class NullStatsConfigUtilImpl { public: - bool IsEnabled() override { return false; } - bool SetEnabled(bool val) override { return true; } + static bool IsEnabled() { return false; } + static bool SetEnabled(bool val) { return true; } }; -StatsConfigUtilInterface* g_stats_config_util_handler = nullptr; - -// GetStatsConfigUtil and SetHandler are not thread safe. - #if !defined(GOOGLE_JAPANESE_INPUT_BUILD) // For non-official build, use null implementation. typedef NullStatsConfigUtilImpl DefaultConfigUtilImpl; @@ -254,23 +248,14 @@ typedef AndroidStatsConfigUtilImpl DefaultConfigUtilImpl; typedef NullStatsConfigUtilImpl DefaultConfigUtilImpl; #endif // Platforms -StatsConfigUtilInterface& GetStatsConfigUtil() { - if (g_stats_config_util_handler == nullptr) { - return *(Singleton::get()); - } else { - return *g_stats_config_util_handler; - } -} } // namespace -void StatsConfigUtil::SetHandler(StatsConfigUtilInterface* handler) { - g_stats_config_util_handler = handler; +bool StatsConfigUtil::IsEnabled() { + return DefaultConfigUtilImpl::IsEnabled(); } -bool StatsConfigUtil::IsEnabled() { return GetStatsConfigUtil().IsEnabled(); } - bool StatsConfigUtil::SetEnabled(bool val) { - return GetStatsConfigUtil().SetEnabled(val); + return DefaultConfigUtilImpl::SetEnabled(val); } } // namespace config diff --git a/src/config/stats_config_util.h b/src/config/stats_config_util.h index 2bd1a64f6..d8400922a 100644 --- a/src/config/stats_config_util.h +++ b/src/config/stats_config_util.h @@ -33,18 +33,6 @@ namespace mozc { namespace config { -// Interface class -class StatsConfigUtilInterface { - public: - StatsConfigUtilInterface() = default; - StatsConfigUtilInterface(const StatsConfigUtilInterface&) = delete; - StatsConfigUtilInterface& operator=(const StatsConfigUtilInterface&) = delete; - virtual ~StatsConfigUtilInterface() = default; - - virtual bool IsEnabled() = 0; - virtual bool SetEnabled(bool val) = 0; -}; - class StatsConfigUtil { public: StatsConfigUtil() = delete; @@ -62,11 +50,6 @@ class StatsConfigUtil { // Note: Administrative privilege is required in Windows. // Returns true if succeeded. static bool SetEnabled(bool val); - - // Inject a dependency - static void SetHandler(StatsConfigUtilInterface* handler); - - // Should never be allocated. }; } // namespace config diff --git a/src/config/stats_config_util_mock.h b/src/config/stats_config_util_mock.h deleted file mode 100644 index b3622dd3c..000000000 --- a/src/config/stats_config_util_mock.h +++ /dev/null @@ -1,56 +0,0 @@ -// Copyright 2010-2021, Google Inc. -// All rights reserved. -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -#ifndef MOZC_CONFIG_STATS_CONFIG_UTIL_MOCK_H_ -#define MOZC_CONFIG_STATS_CONFIG_UTIL_MOCK_H_ - -#include "config/stats_config_util.h" - -namespace mozc { -namespace config { - -class StatsConfigUtilMock : public StatsConfigUtilInterface { - public: - StatsConfigUtilMock() : is_enabled_(true) {} - - bool IsEnabled() override { return is_enabled_; } - - bool SetEnabled(bool val) override { - is_enabled_ = val; - return true; - } - - private: - bool is_enabled_; -}; - -} // namespace config -} // namespace mozc - -#endif // MOZC_CONFIG_STATS_CONFIG_UTIL_MOCK_H_