Commit e549558a authored by Kyle Horimoto's avatar Kyle Horimoto Committed by Commit Bot

[CrOS PhoneHub] Add phone name to PhoneModel

Bug: 1106937
Change-Id: I46b2a08379bb3996de0cc61b909d3e7abe64f7af
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2405904
Commit-Queue: Kyle Horimoto <khorimoto@chromium.org>
Commit-Queue: Regan Hsu <hsuregan@chromium.org>
Reviewed-by: default avatarRegan Hsu <hsuregan@chromium.org>
Auto-Submit: Kyle Horimoto <khorimoto@chromium.org>
Cr-Commit-Position: refs/heads/master@{#806276}
parent 9b19829c
...@@ -11,6 +11,15 @@ MutablePhoneModel::MutablePhoneModel() = default; ...@@ -11,6 +11,15 @@ MutablePhoneModel::MutablePhoneModel() = default;
MutablePhoneModel::~MutablePhoneModel() = default; MutablePhoneModel::~MutablePhoneModel() = default;
void MutablePhoneModel::SetPhoneName(
const base::Optional<base::string16>& phone_name) {
if (phone_name_ == phone_name)
return;
phone_name_ = phone_name;
NotifyModelChanged();
}
void MutablePhoneModel::SetPhoneStatusModel( void MutablePhoneModel::SetPhoneStatusModel(
const base::Optional<PhoneStatusModel>& phone_status_model) { const base::Optional<PhoneStatusModel>& phone_status_model) {
if (phone_status_model_ == phone_status_model) if (phone_status_model_ == phone_status_model)
......
...@@ -17,6 +17,7 @@ class MutablePhoneModel : public PhoneModel { ...@@ -17,6 +17,7 @@ class MutablePhoneModel : public PhoneModel {
MutablePhoneModel(); MutablePhoneModel();
~MutablePhoneModel() override; ~MutablePhoneModel() override;
void SetPhoneName(const base::Optional<base::string16>& phone_name);
void SetPhoneStatusModel( void SetPhoneStatusModel(
const base::Optional<PhoneStatusModel>& phone_status_model); const base::Optional<PhoneStatusModel>& phone_status_model);
void SetBrowserTabsModel( void SetBrowserTabsModel(
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include "chromeos/components/phonehub/mutable_phone_model.h" #include "chromeos/components/phonehub/mutable_phone_model.h"
#include "base/strings/utf_string_conversions.h"
#include "chromeos/components/phonehub/phone_model_test_util.h" #include "chromeos/components/phonehub/phone_model_test_util.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
...@@ -48,6 +49,31 @@ class MutablePhoneModelTest : public testing::Test { ...@@ -48,6 +49,31 @@ class MutablePhoneModelTest : public testing::Test {
FakeObserver fake_observer_; FakeObserver fake_observer_;
}; };
TEST_F(MutablePhoneModelTest, PhoneName) {
const base::string16 fake_phone_name = base::UTF8ToUTF16("Phone name");
// Set the phone name to be null (the default value); observers should
// not be notified, since this is not a change.
model_.SetPhoneName(/*phone_name=*/base::nullopt);
EXPECT_FALSE(model_.phone_name().has_value());
EXPECT_EQ(0u, GetNumObserverCalls());
// Set the phone name; observers should be notified.
model_.SetPhoneName(fake_phone_name);
EXPECT_EQ(fake_phone_name, model_.phone_name());
EXPECT_EQ(1u, GetNumObserverCalls());
// Set the same phone name; observers should not be notified.
model_.SetPhoneName(fake_phone_name);
EXPECT_EQ(fake_phone_name, model_.phone_name());
EXPECT_EQ(1u, GetNumObserverCalls());
// Set the phone name back to null; observers should be notified.
model_.SetPhoneName(/*phone_name=*/base::nullopt);
EXPECT_FALSE(model_.phone_name().has_value());
EXPECT_EQ(2u, GetNumObserverCalls());
}
TEST_F(MutablePhoneModelTest, PhoneStatusModel) { TEST_F(MutablePhoneModelTest, PhoneStatusModel) {
// Set the PhoneStatusModel to be null (the default value); observers should // Set the PhoneStatusModel to be null (the default value); observers should
// not be notified, since this is not a change. // not be notified, since this is not a change.
......
...@@ -32,6 +32,10 @@ class PhoneModel { ...@@ -32,6 +32,10 @@ class PhoneModel {
PhoneModel& operator=(const PhoneModel&) = delete; PhoneModel& operator=(const PhoneModel&) = delete;
virtual ~PhoneModel(); virtual ~PhoneModel();
const base::Optional<base::string16>& phone_name() const {
return phone_name_;
}
const base::Optional<PhoneStatusModel>& phone_status_model() const { const base::Optional<PhoneStatusModel>& phone_status_model() const {
return phone_status_model_; return phone_status_model_;
} }
...@@ -48,6 +52,7 @@ class PhoneModel { ...@@ -48,6 +52,7 @@ class PhoneModel {
void NotifyModelChanged(); void NotifyModelChanged();
base::Optional<base::string16> phone_name_;
base::Optional<PhoneStatusModel> phone_status_model_; base::Optional<PhoneStatusModel> phone_status_model_;
base::Optional<BrowserTabsModel> browser_tabs_model_; base::Optional<BrowserTabsModel> browser_tabs_model_;
......
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