Commit caca7b86 authored by Fabrice de Gans-Riberi's avatar Fabrice de Gans-Riberi Committed by Commit Bot

[fuchsia] Remove fuchsia sub-namespace from IntlProfileWatcher

This renames the class FuchsiaIntlProfileWatcher.

Bug: 1073821
Change-Id: I13a5eb3bd71de69b00e447742400d26f3877755d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2431732
Commit-Queue: Fabrice de Gans-Riberi <fdegans@chromium.org>
Reviewed-by: default avatardanakj <danakj@chromium.org>
Reviewed-by: default avatarDavid Dorwin <ddorwin@chromium.org>
Reviewed-by: default avatarKen Rockot <rockot@google.com>
Cr-Commit-Position: refs/heads/master@{#815850}
parent 2be063ba
......@@ -16,15 +16,16 @@
using ::fuchsia::intl::Profile;
namespace base {
namespace fuchsia {
IntlProfileWatcher::IntlProfileWatcher(ProfileChangeCallback on_profile_changed)
: IntlProfileWatcher(ComponentContextForProcess()
FuchsiaIntlProfileWatcher::FuchsiaIntlProfileWatcher(
ProfileChangeCallback on_profile_changed)
: FuchsiaIntlProfileWatcher(
ComponentContextForProcess()
->svc()
->Connect<::fuchsia::intl::PropertyProvider>(),
on_profile_changed) {}
IntlProfileWatcher::IntlProfileWatcher(
FuchsiaIntlProfileWatcher::FuchsiaIntlProfileWatcher(
::fuchsia::intl::PropertyProviderPtr property_provider,
ProfileChangeCallback on_profile_changed)
: property_provider_(std::move(property_provider)),
......@@ -43,10 +44,10 @@ IntlProfileWatcher::IntlProfileWatcher(
};
}
IntlProfileWatcher::~IntlProfileWatcher() = default;
FuchsiaIntlProfileWatcher::~FuchsiaIntlProfileWatcher() = default;
// static
std::string IntlProfileWatcher::GetPrimaryTimeZoneIdFromProfile(
std::string FuchsiaIntlProfileWatcher::GetPrimaryTimeZoneIdFromProfile(
const Profile& profile) {
if (!profile.has_time_zones()) {
DLOG(WARNING) << "Profile does not contain time zones.";
......@@ -64,14 +65,15 @@ std::string IntlProfileWatcher::GetPrimaryTimeZoneIdFromProfile(
}
// static
std::string IntlProfileWatcher::GetPrimaryTimeZoneIdForIcuInitialization() {
std::string
FuchsiaIntlProfileWatcher::GetPrimaryTimeZoneIdForIcuInitialization() {
::fuchsia::intl::PropertyProviderSyncPtr provider;
ComponentContextForProcess()->svc()->Connect(provider.NewRequest());
return GetPrimaryTimeZoneIdFromPropertyProvider(std::move(provider));
}
// static
std::string IntlProfileWatcher::GetPrimaryTimeZoneIdFromPropertyProvider(
std::string FuchsiaIntlProfileWatcher::GetPrimaryTimeZoneIdFromPropertyProvider(
::fuchsia::intl::PropertyProviderSyncPtr property_provider) {
DCHECK(property_provider.is_bound());
Profile profile;
......@@ -84,5 +86,4 @@ std::string IntlProfileWatcher::GetPrimaryTimeZoneIdFromPropertyProvider(
return GetPrimaryTimeZoneIdFromProfile(profile);
}
} // namespace fuchsia
} // namespace base
......@@ -13,22 +13,22 @@
#include "base/strings/string_piece_forward.h"
namespace base {
namespace fuchsia {
// Watches fuchsia.intl.PropertyProvider for change notifications and notifies
// the provided callback. If necessary, the caller is responsible for
// determining whether an actual change of interest has occurred.
class BASE_EXPORT IntlProfileWatcher {
class BASE_EXPORT FuchsiaIntlProfileWatcher {
public:
using ProfileChangeCallback =
base::RepeatingCallback<void(const ::fuchsia::intl::Profile&)>;
// |on_profile_changed| will be called each time the profile may have changed.
explicit IntlProfileWatcher(ProfileChangeCallback on_profile_changed);
explicit FuchsiaIntlProfileWatcher(ProfileChangeCallback on_profile_changed);
IntlProfileWatcher(const IntlProfileWatcher&) = delete;
IntlProfileWatcher& operator=(const IntlProfileWatcher&) = delete;
~IntlProfileWatcher();
FuchsiaIntlProfileWatcher(const FuchsiaIntlProfileWatcher&) = delete;
FuchsiaIntlProfileWatcher& operator=(const FuchsiaIntlProfileWatcher&) =
delete;
~FuchsiaIntlProfileWatcher();
// Returns the ID of the primary time zone in |profile|.
// Returns the empty string if the ID cannot be obtained.
......@@ -45,7 +45,8 @@ class BASE_EXPORT IntlProfileWatcher {
friend class GetPrimaryTimeZoneIdFromPropertyProviderTest;
friend class IntlProfileWatcherTest;
IntlProfileWatcher(::fuchsia::intl::PropertyProviderPtr property_provider,
FuchsiaIntlProfileWatcher(
::fuchsia::intl::PropertyProviderPtr property_provider,
ProfileChangeCallback on_profile_changed);
// Returns the ID of the primary time zone from the profile obtained from
......@@ -57,7 +58,14 @@ class BASE_EXPORT IntlProfileWatcher {
const ProfileChangeCallback on_profile_changed_;
};
// TODO(crbug.com/1073821): Remove this block when out-of-tree callers have been
// changed to use the non-fuchsia-sub-namespace version.
namespace fuchsia {
using IntlProfileWatcher = ::base::FuchsiaIntlProfileWatcher;
} // namespace fuchsia
} // namespace base
#endif // BASE_FUCHSIA_INTL_PROFILE_WATCHER_H_
......@@ -24,7 +24,6 @@
using ::fuchsia::intl::Profile;
namespace base {
namespace fuchsia {
namespace {
......@@ -135,7 +134,7 @@ class GetPrimaryTimeZoneIdFromPropertyProviderTest : public testing::Test {
protected:
static std::string GetPrimaryTimeZoneIdFromPropertyProvider(
::fuchsia::intl::PropertyProviderSyncPtr property_provider) {
return IntlProfileWatcher::GetPrimaryTimeZoneIdFromPropertyProvider(
return FuchsiaIntlProfileWatcher::GetPrimaryTimeZoneIdFromPropertyProvider(
std::move(property_provider));
}
......@@ -155,9 +154,9 @@ class IntlProfileWatcherTest : public testing::Test {
base::test::SingleThreadTaskEnvironment task_environment_{
base::test::SingleThreadTaskEnvironment::MainThreadType::IO};
std::unique_ptr<IntlProfileWatcher> CreateIntlProfileWatcher(
IntlProfileWatcher::ProfileChangeCallback on_profile_changed) {
return base::WrapUnique(new IntlProfileWatcher(
std::unique_ptr<FuchsiaIntlProfileWatcher> CreateIntlProfileWatcher(
FuchsiaIntlProfileWatcher::ProfileChangeCallback on_profile_changed) {
return base::WrapUnique(new FuchsiaIntlProfileWatcher(
std::move(property_provider_ptr_), std::move(on_profile_changed)));
}
......@@ -169,15 +168,16 @@ class IntlProfileWatcherTest : public testing::Test {
// Unit tests are run in an environment where intl is not provided.
// However, this is not exposed by the API.
TEST(IntlServiceNotAvailableTest, IntlProfileWatcher) {
TEST(IntlServiceNotAvailableTest, FuchsiaIntlProfileWatcher) {
base::test::SingleThreadTaskEnvironment task_environment_{
base::test::SingleThreadTaskEnvironment::MainThreadType::IO};
base::RunLoop run_loop;
base::MockCallback<IntlProfileWatcher::ProfileChangeCallback>
base::MockCallback<FuchsiaIntlProfileWatcher::ProfileChangeCallback>
on_profile_changed;
EXPECT_CALL(on_profile_changed, Run(testing::_)).Times(0);
auto watcher = std::make_unique<IntlProfileWatcher>(on_profile_changed.Get());
auto watcher =
std::make_unique<FuchsiaIntlProfileWatcher>(on_profile_changed.Get());
EXPECT_TRUE(watcher);
run_loop.RunUntilIdle();
......@@ -220,7 +220,7 @@ TEST_F(GetPrimaryTimeZoneIdFromPropertyProviderTest, MoreThanOneZone) {
}
TEST_F(IntlProfileWatcherTest, NoZones_NoNotification) {
base::MockCallback<IntlProfileWatcher::ProfileChangeCallback> callback;
base::MockCallback<FuchsiaIntlProfileWatcher::ProfileChangeCallback> callback;
EXPECT_CALL(callback, Run(testing::_)).Times(0);
auto watcher = CreateIntlProfileWatcher(callback.Get());
run_loop_.RunUntilIdle();
......@@ -230,7 +230,8 @@ TEST_F(IntlProfileWatcherTest, ChangeNotification_AfterInitialization) {
auto watcher = CreateIntlProfileWatcher(base::BindLambdaForTesting(
[quit_loop = run_loop_.QuitClosure()](const Profile& profile) {
EXPECT_EQ(kPrimaryTimeZoneName,
IntlProfileWatcher::GetPrimaryTimeZoneIdFromProfile(profile));
FuchsiaIntlProfileWatcher::GetPrimaryTimeZoneIdFromProfile(
profile));
quit_loop.Run();
}));
......@@ -247,7 +248,8 @@ TEST_F(IntlProfileWatcherTest, ChangeNotification_BeforeInitialization) {
auto watcher = CreateIntlProfileWatcher(base::BindLambdaForTesting(
[quit_loop = run_loop_.QuitClosure()](const Profile& profile) {
EXPECT_EQ(kPrimaryTimeZoneName,
IntlProfileWatcher::GetPrimaryTimeZoneIdFromProfile(profile));
FuchsiaIntlProfileWatcher::GetPrimaryTimeZoneIdFromProfile(
profile));
quit_loop.Run();
}));
......@@ -256,7 +258,7 @@ TEST_F(IntlProfileWatcherTest, ChangeNotification_BeforeInitialization) {
// Ensure no crash when the peer service cannot be reached during creation.
TEST_F(IntlProfileWatcherTest, ChannelClosedBeforeCreation) {
base::MockCallback<IntlProfileWatcher::ProfileChangeCallback> callback;
base::MockCallback<FuchsiaIntlProfileWatcher::ProfileChangeCallback> callback;
EXPECT_CALL(callback, Run(testing::_)).Times(0);
property_provider_.Close();
......@@ -269,7 +271,7 @@ TEST_F(IntlProfileWatcherTest, ChannelClosedBeforeCreation) {
// Ensure no crash when the channel is closed after creation.
TEST_F(IntlProfileWatcherTest, ChannelClosedAfterCreation) {
base::MockCallback<IntlProfileWatcher::ProfileChangeCallback> callback;
base::MockCallback<FuchsiaIntlProfileWatcher::ProfileChangeCallback> callback;
EXPECT_CALL(callback, Run(testing::_)).Times(0);
auto watcher = CreateIntlProfileWatcher(callback.Get());
......@@ -281,26 +283,26 @@ TEST_F(IntlProfileWatcherTest, ChannelClosedAfterCreation) {
}
TEST(IntlProfileWatcherGetPrimaryTimeZoneIdFromProfileTest, NoZones) {
EXPECT_EQ("", IntlProfileWatcher::GetPrimaryTimeZoneIdFromProfile(Profile()));
EXPECT_EQ("", FuchsiaIntlProfileWatcher::GetPrimaryTimeZoneIdFromProfile(
Profile()));
}
TEST(IntlProfileWatcherGetPrimaryTimeZoneIdFromProfileTest, EmptyZonesList) {
EXPECT_EQ("", IntlProfileWatcher::GetPrimaryTimeZoneIdFromProfile(
EXPECT_EQ("", FuchsiaIntlProfileWatcher::GetPrimaryTimeZoneIdFromProfile(
CreateProfileWithTimeZones({})));
}
TEST(IntlProfileWatcherGetPrimaryTimeZoneIdFromProfileTest, OneZone) {
EXPECT_EQ(kPrimaryTimeZoneName,
IntlProfileWatcher::GetPrimaryTimeZoneIdFromProfile(
FuchsiaIntlProfileWatcher::GetPrimaryTimeZoneIdFromProfile(
CreateProfileWithTimeZones({kPrimaryTimeZoneName})));
}
TEST(IntlProfileWatcherGetPrimaryTimeZoneIdFromProfileTest, TwoZones) {
EXPECT_EQ(kPrimaryTimeZoneName,
IntlProfileWatcher::GetPrimaryTimeZoneIdFromProfile(
FuchsiaIntlProfileWatcher::GetPrimaryTimeZoneIdFromProfile(
CreateProfileWithTimeZones(
{kPrimaryTimeZoneName, kSecondaryTimeZoneName})));
}
} // namespace fuchsia
} // namespace base
......@@ -338,7 +338,7 @@ void InitializeIcuTimeZone() {
// If the system time zone cannot be obtained or is not understood by ICU,
// the "unknown" time zone will be returned by createTimeZone() and used.
std::string zone_id =
fuchsia::IntlProfileWatcher::GetPrimaryTimeZoneIdForIcuInitialization();
FuchsiaIntlProfileWatcher::GetPrimaryTimeZoneIdForIcuInitialization();
icu::TimeZone::adoptDefault(
icu::TimeZone::createTimeZone(icu::UnicodeString::fromUTF8(zone_id)));
#elif (defined(OS_LINUX) || defined(OS_CHROMEOS)) && !BUILDFLAG(IS_CHROMECAST)
......
......@@ -48,7 +48,7 @@ class TimeZoneMonitorFuchsia : public TimeZoneMonitor {
UpdateIcuAndNotifyClients(std::move(new_zone));
}
base::fuchsia::IntlProfileWatcher watcher_;
base::FuchsiaIntlProfileWatcher watcher_;
};
} // namespace
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment