Skip to content

Commit

Permalink
Remove unused deviceInfo methods.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 688296309
  • Loading branch information
ftsui authored and copybara-github committed Oct 21, 2024
1 parent 042835c commit ff4cb86
Show file tree
Hide file tree
Showing 14 changed files with 0 additions and 235 deletions.
3 changes: 0 additions & 3 deletions internal/platform/device_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,7 @@ class DeviceInfo {
virtual std::string GetOsDeviceName() const = 0;
virtual api::DeviceInfo::DeviceType GetDeviceType() const = 0;
virtual api::DeviceInfo::OsType GetOsType() const = 0;
virtual std::optional<std::string> GetFullName() const = 0;
virtual std::optional<std::string> GetGivenName() const = 0;
virtual std::optional<std::string> GetLastName() const = 0;
virtual std::optional<std::string> GetProfileUserName() const = 0;

virtual std::filesystem::path GetDownloadPath() const = 0;
virtual std::filesystem::path GetAppDataPath() const = 0;
Expand Down
12 changes: 0 additions & 12 deletions internal/platform/device_info_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -43,22 +43,10 @@ api::DeviceInfo::OsType DeviceInfoImpl::GetOsType() const {
return device_info_impl_->GetOsType();
}

std::optional<std::string> DeviceInfoImpl::GetFullName() const {
return device_info_impl_->GetFullName();
}

std::optional<std::string> DeviceInfoImpl::GetGivenName() const {
return device_info_impl_->GetGivenName();
}

std::optional<std::string> DeviceInfoImpl::GetLastName() const {
return device_info_impl_->GetLastName();
}

std::optional<std::string> DeviceInfoImpl::GetProfileUserName() const {
return device_info_impl_->GetProfileUserName();
}

std::filesystem::path DeviceInfoImpl::GetDownloadPath() const {
std::optional<std::filesystem::path> path =
device_info_impl_->GetDownloadPath();
Expand Down
3 changes: 0 additions & 3 deletions internal/platform/device_info_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,7 @@ class DeviceInfoImpl : public DeviceInfo {
api::DeviceInfo::DeviceType GetDeviceType() const override;
api::DeviceInfo::OsType GetOsType() const override;

std::optional<std::string> GetFullName() const override;
std::optional<std::string> GetGivenName() const override;
std::optional<std::string> GetLastName() const override;
std::optional<std::string> GetProfileUserName() const override;

std::filesystem::path GetDownloadPath() const override;
std::filesystem::path GetAppDataPath() const override;
Expand Down
3 changes: 0 additions & 3 deletions internal/platform/implementation/apple/device_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,7 @@ class DeviceInfo : public api::DeviceInfo {

api::DeviceInfo::OsType GetOsType() const override;

std::optional<std::string> GetFullName() const override;
std::optional<std::string> GetGivenName() const override;
std::optional<std::string> GetLastName() const override;
std::optional<std::string> GetProfileUserName() const override;

std::optional<std::filesystem::path> GetDownloadPath() const override;

Expand Down
3 changes: 0 additions & 3 deletions internal/platform/implementation/apple/device_info.mm
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,7 @@
#endif
}

std::optional<std::string> DeviceInfo::GetFullName() const { return std::nullopt; }
std::optional<std::string> DeviceInfo::GetGivenName() const { return std::nullopt; }
std::optional<std::string> DeviceInfo::GetLastName() const { return std::nullopt; }
std::optional<std::string> DeviceInfo::GetProfileUserName() const { return std::nullopt; }

std::optional<std::filesystem::path> DeviceInfo::GetDownloadPath() const {
NSFileManager *manager = [NSFileManager defaultManager];
Expand Down
3 changes: 0 additions & 3 deletions internal/platform/implementation/device_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,7 @@ class DeviceInfo {
virtual OsType GetOsType() const = 0;

// Gets basic information of current user.
virtual std::optional<std::string> GetFullName() const = 0;
virtual std::optional<std::string> GetGivenName() const = 0;
virtual std::optional<std::string> GetLastName() const = 0;
virtual std::optional<std::string> GetProfileUserName() const = 0;

// Gets known paths of current user.
virtual std::optional<std::filesystem::path> GetDownloadPath() const = 0;
Expand Down
9 changes: 0 additions & 9 deletions internal/platform/implementation/g3/device_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,9 @@ class DeviceInfo : public api::DeviceInfo {
return api::DeviceInfo::OsType::kChromeOs;
}

std::optional<std::string> GetFullName() const override {
return "nearby";
}
std::optional<std::string> GetGivenName() const override {
return "nearby";
}
std::optional<std::string> GetLastName() const override {
return "nearby";
}
std::optional<std::string> GetProfileUserName() const override {
return "nearby";
}

std::optional<std::filesystem::path> GetDownloadPath() const override {
return std::filesystem::temp_directory_path();
Expand Down
126 changes: 0 additions & 126 deletions internal/platform/implementation/windows/device_info.cc
Original file line number Diff line number Diff line change
Expand Up @@ -84,48 +84,6 @@ api::DeviceInfo::OsType DeviceInfo::GetOsType() const {
return api::DeviceInfo::OsType::kWindows;
}

std::optional<std::string> DeviceInfo::GetFullName() const {
// FindAllAsync finds all users that are using this app. When we "Switch User"
// on Desktop,FindAllAsync() will still return the current user instead of all
// of them because the users who are switched out are not using the apps of
// the user who is switched in, so FindAllAsync() will not find them. (Under
// the UWP application model, each process runs under its own user account.
// That user account is different from the user account of the logged-in user.
// Processes aren't owned by the logged-in user for purposes of isolation.)
IVectorView<User> users =
User::FindAllAsync(UserType::LocalUser,
UserAuthenticationStatus::LocallyAuthenticated)
.get();
if (users == nullptr) {
LOG(ERROR) << __func__ << ": Error retrieving locally authenticated user.";
return std::nullopt;
}

// On Windows Desktop apps, the first Windows.System.User instance
// returned in the IVectorView is always the current user.
// https://github.com/microsoft/Windows-task-snippets/blob/master/tasks/User-info.md
User current_user = users.GetAt(0);

// Retrieve the human-readable properties for the current user
IAsyncOperation<IInspectable> full_name_obj_async =
current_user.GetPropertyAsync(KnownUserProperties::DisplayName());
IInspectable full_name_obj = full_name_obj_async.get();
if (full_name_obj == nullptr) {
LOG(ERROR) << __func__ << ": Error retrieving full name of user.";
return std::nullopt;
}
winrt::hstring full_name = full_name_obj.as<winrt::hstring>();
std::string full_name_str = winrt::to_string(full_name);

if (full_name_str.empty()) {
LOG(ERROR) << __func__
<< ": Error unboxing string value for full name of user.";
return std::nullopt;
}

return full_name_str;
}

std::optional<std::string> DeviceInfo::GetGivenName() const {
// FindAllAsync finds all users that are using this app. When we "Switch User"
// on Desktop,FindAllAsync() will still return the current user instead of all
Expand Down Expand Up @@ -168,90 +126,6 @@ std::optional<std::string> DeviceInfo::GetGivenName() const {
return given_name_str;
}

std::optional<std::string> DeviceInfo::GetLastName() const {
// FindAllAsync finds all users that are using this app. When we "Switch User"
// on Desktop,FindAllAsync() will still return the current user instead of all
// of them because the users who are switched out are not using the apps of
// the user who is switched in, so FindAllAsync() will not find them. (Under
// the UWP application model, each process runs under its own user account.
// That user account is different from the user account of the logged-in user.
// Processes aren't owned by the logged-in user for purposes of isolation.)
IVectorView<User> users =
User::FindAllAsync(UserType::LocalUser,
UserAuthenticationStatus::LocallyAuthenticated)
.get();
if (users == nullptr) {
LOG(ERROR) << __func__ << ": Error retrieving locally authenticated user.";
return std::nullopt;
}

// On Windows Desktop apps, the first Windows.System.User instance
// returned in the IVectorView is always the current user.
// https://github.com/microsoft/Windows-task-snippets/blob/master/tasks/User-info.md
User current_user = users.GetAt(0);

// Retrieve the human-readable properties for the current user
IAsyncOperation<IInspectable> last_name_obj_async =
current_user.GetPropertyAsync(KnownUserProperties::LastName());
IInspectable last_name_obj = last_name_obj_async.get();
if (last_name_obj == nullptr) {
LOG(ERROR) << __func__ << ": Error retrieving last name of user.";
return std::nullopt;
}
winrt::hstring last_name = last_name_obj.as<winrt::hstring>();
std::string last_name_str = winrt::to_string(last_name);

if (last_name_str.empty()) {
LOG(ERROR) << __func__
<< ": Error unboxing string value for last name of user.";
return std::nullopt;
}

return last_name_str;
}

std::optional<std::string> DeviceInfo::GetProfileUserName() const {
// FindAllAsync finds all users that are using this app. When we "Switch User"
// on Desktop,FindAllAsync() will still return the current user instead of all
// of them because the users who are switched out are not using the apps of
// the user who is switched in, so FindAllAsync() will not find them. (Under
// the UWP application model, each process runs under its own user account.
// That user account is different from the user account of the logged-in user.
// Processes aren't owned by the logged-in user for purposes of isolation.)
IVectorView<User> users =
User::FindAllAsync(UserType::LocalUser,
UserAuthenticationStatus::LocallyAuthenticated)
.get();
if (users == nullptr) {
LOG(ERROR) << __func__ << ": Error retrieving locally authenticated user.";
return std::nullopt;
}

// On Windows Desktop apps, the first Windows.System.User instance
// returned in the IVectorView is always the current user.
// https://github.com/microsoft/Windows-task-snippets/blob/master/tasks/User-info.md
User current_user = users.GetAt(0);

// Retrieve the human-readable properties for the current user
IAsyncOperation<IInspectable> account_name_obj_async =
current_user.GetPropertyAsync(KnownUserProperties::AccountName());
IInspectable account_name_obj = account_name_obj_async.get();
if (account_name_obj == nullptr) {
LOG(ERROR) << __func__ << ": Error retrieving account name of user.";
return std::nullopt;
}
winrt::hstring account_name = account_name_obj.as<winrt::hstring>();
std::string account_name_string = winrt::to_string(account_name);

if (account_name_string.empty()) {
LOG(ERROR) << __func__
<< ": Error unboxing string value for profile username of user.";
return std::nullopt;
}

return account_name_string;
}

std::optional<std::filesystem::path> DeviceInfo::GetDownloadPath() const {
PWSTR path;
HRESULT result =
Expand Down
3 changes: 0 additions & 3 deletions internal/platform/implementation/windows/device_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,7 @@ class DeviceInfo : public api::DeviceInfo {
std::optional<std::string> GetOsDeviceName() const override;
api::DeviceInfo::DeviceType GetDeviceType() const override;
api::DeviceInfo::OsType GetOsType() const override;
std::optional<std::string> GetFullName() const override;
std::optional<std::string> GetGivenName() const override;
std::optional<std::string> GetLastName() const override;
std::optional<std::string> GetProfileUserName() const override;

std::optional<std::filesystem::path> GetDownloadPath() const override;
std::optional<std::filesystem::path> GetLocalAppDataPath() const override;
Expand Down
36 changes: 0 additions & 36 deletions internal/test/fake_device_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,9 @@ class FakeDeviceInfo : public DeviceInfo {

api::DeviceInfo::OsType GetOsType() const override { return os_type_; }

std::optional<std::string> GetFullName() const override {
return full_name_;
}
std::optional<std::string> GetGivenName() const override {
return given_name_;
}
std::optional<std::string> GetLastName() const override {
return last_name_;
}
std::optional<std::string> GetProfileUserName() const override {
return profile_user_name_;
}

std::filesystem::path GetDownloadPath() const override {
return download_path_;
Expand Down Expand Up @@ -105,14 +96,6 @@ class FakeDeviceInfo : public DeviceInfo {

void SetOsType(api::DeviceInfo::OsType os_type) { os_type_ = os_type; }

void SetFullName(std::optional<std::string> full_name) {
if (full_name.has_value() && !full_name->empty()) {
full_name_ = full_name;
} else {
full_name_ = std::nullopt;
}
}

void SetGivenName(std::optional<std::string> given_name) {
if (given_name.has_value() && !given_name->empty()) {
given_name_ = given_name;
Expand All @@ -121,22 +104,6 @@ class FakeDeviceInfo : public DeviceInfo {
}
}

void SetLastName(std::optional<std::string> last_name) {
if (last_name.has_value() && !last_name->empty()) {
last_name_ = last_name;
} else {
last_name_ = std::nullopt;
}
}

void SetProfileUserName(std::optional<std::string> profile_user_name) {
if (profile_user_name.has_value() && !profile_user_name->empty()) {
profile_user_name_ = profile_user_name;
} else {
profile_user_name_ = std::nullopt;
}
}

void SetDownloadPath(std::filesystem::path path) { download_path_ = path; }

void SetAppDataPath(std::filesystem::path path) { app_data_path_ = path; }
Expand Down Expand Up @@ -166,10 +133,7 @@ class FakeDeviceInfo : public DeviceInfo {
api::DeviceInfo::DeviceType device_type_ =
api::DeviceInfo::DeviceType::kLaptop;
api::DeviceInfo::OsType os_type_ = api::DeviceInfo::OsType::kWindows;
std::optional<std::string> full_name_ = "Nearby";
std::optional<std::string> given_name_ = "Nearby";
std::optional<std::string> last_name_ = "Nearby";
std::optional<std::string> profile_user_name_ = "nearby";
std::filesystem::path download_path_ = std::filesystem::temp_directory_path();
std::filesystem::path app_data_path_ = std::filesystem::temp_directory_path();
std::filesystem::path temp_path_ = std::filesystem::temp_directory_path();
Expand Down
4 changes: 0 additions & 4 deletions sharing/common/nearby_share_profile_info_provider.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,6 @@ class NearbyShareProfileInfoProvider {
// Returns UTF-8 encoded given name of current account.
// Returns absl::nullopt if a valid given name cannot be returned.
virtual std::optional<std::string> GetGivenName() const = 0;

// Proxy for Profile::GetProfileUserName(). Returns absl::nullopt if a valid
// username cannot be returned.
virtual std::optional<std::string> GetProfileUserName() const = 0;
};
} // namespace sharing
} // namespace nearby
Expand Down
5 changes: 0 additions & 5 deletions sharing/nearby_share_profile_info_provider_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,5 @@ std::optional<std::string> NearbyShareProfileInfoProviderImpl::GetGivenName()
return device_info_.GetGivenName();
}

std::optional<std::string>
NearbyShareProfileInfoProviderImpl::GetProfileUserName() const {
return device_info_.GetProfileUserName();
}

} // namespace sharing
} // namespace nearby
1 change: 0 additions & 1 deletion sharing/nearby_share_profile_info_provider_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ class NearbyShareProfileInfoProviderImpl

// NearbyShareProfileInfoProvider:
std::optional<std::string> GetGivenName() const override;
std::optional<std::string> GetProfileUserName() const override;

private:
nearby::DeviceInfo& device_info_;
Expand Down
Loading

0 comments on commit ff4cb86

Please sign in to comment.