weave/settings: rename device_id to cloud_id Bug: 24485657 Change-Id: I72ad9c545ad8ed40e9b5a195c44674790b73f9fd Reviewed-on: https://weave-review.googlesource.com/1179 Reviewed-by: Vitaly Buka <vitalybuka@google.com>
diff --git a/libweave/include/weave/settings.h b/libweave/include/weave/settings.h index fa32b86..01f4c0d 100644 --- a/libweave/include/weave/settings.h +++ b/libweave/include/weave/settings.h
@@ -37,7 +37,7 @@ std::set<PairingType> pairing_modes; std::string embedded_code; - std::string device_id; + std::string cloud_id; std::string refresh_token; std::string robot_account; std::string last_configured_ssid;
diff --git a/libweave/src/config.cc b/libweave/src/config.cc index 55b0c7b..3aa57d5 100644 --- a/libweave/src/config.cc +++ b/libweave/src/config.cc
@@ -33,7 +33,7 @@ const char kLocalDiscoveryEnabled[] = "local_discovery_enabled"; const char kLocalPairingEnabled[] = "local_pairing_enabled"; const char kRefreshToken[] = "refresh_token"; -const char kDeviceId[] = "device_id"; +const char kCloudId[] = "cloud_id"; const char kRobotAccount[] = "robot_account"; const char kLastConfiguredSsid[] = "last_configured_ssid"; @@ -178,8 +178,8 @@ if (dict->GetString(config_keys::kLastConfiguredSsid, &tmp)) set_last_configured_ssid(tmp); - if (dict->GetString(config_keys::kDeviceId, &tmp)) - set_device_id(tmp); + if (dict->GetString(config_keys::kCloudId, &tmp)) + set_cloud_id(tmp); } void Config::Save() { @@ -193,7 +193,7 @@ dict.SetString(config_keys::kOAuthURL, settings_.oauth_url); dict.SetString(config_keys::kServiceURL, settings_.service_url); dict.SetString(config_keys::kRefreshToken, settings_.refresh_token); - dict.SetString(config_keys::kDeviceId, settings_.device_id); + dict.SetString(config_keys::kCloudId, settings_.cloud_id); dict.SetString(config_keys::kRobotAccount, settings_.robot_account); dict.SetString(config_keys::kLastConfiguredSsid, settings_.last_configured_ssid);
diff --git a/libweave/src/config.h b/libweave/src/config.h index c25ff6e..37b7cb6 100644 --- a/libweave/src/config.h +++ b/libweave/src/config.h
@@ -68,7 +68,7 @@ void set_local_pairing_enabled(bool enabled) { settings_->local_pairing_enabled = enabled; } - void set_device_id(const std::string& id) { settings_->device_id = id; } + void set_cloud_id(const std::string& id) { settings_->cloud_id = id; } void set_refresh_token(const std::string& token) { settings_->refresh_token = token; }
diff --git a/libweave/src/config_unittest.cc b/libweave/src/config_unittest.cc index 8968b50..2a81769 100644 --- a/libweave/src/config_unittest.cc +++ b/libweave/src/config_unittest.cc
@@ -71,7 +71,7 @@ EXPECT_EQ("viewer", GetSettings().local_anonymous_access_role); EXPECT_TRUE(GetSettings().local_pairing_enabled); EXPECT_TRUE(GetSettings().local_discovery_enabled); - EXPECT_EQ("", GetSettings().device_id); + EXPECT_EQ("", GetSettings().cloud_id); EXPECT_EQ("", GetSettings().refresh_token); EXPECT_EQ("", GetSettings().robot_account); EXPECT_EQ("", GetSettings().last_configured_ssid); @@ -83,7 +83,7 @@ "client_id": "state_client_id", "client_secret": "state_client_secret", "description": "state_description", - "device_id": "state_device_id", + "cloud_id": "state_cloud_id", "local_anonymous_access_role": "user", "local_discovery_enabled": false, "local_pairing_enabled": false, @@ -123,7 +123,7 @@ EXPECT_EQ("user", GetSettings().local_anonymous_access_role); EXPECT_FALSE(GetSettings().local_pairing_enabled); EXPECT_FALSE(GetSettings().local_discovery_enabled); - EXPECT_EQ("state_device_id", GetSettings().device_id); + EXPECT_EQ("state_cloud_id", GetSettings().cloud_id); EXPECT_EQ("state_refresh_token", GetSettings().refresh_token); EXPECT_EQ("state_robot_account", GetSettings().robot_account); EXPECT_EQ("state_last_configured_ssid", GetSettings().last_configured_ssid); @@ -177,8 +177,8 @@ change.set_local_pairing_enabled(true); EXPECT_TRUE(GetSettings().local_pairing_enabled); - change.set_device_id("set_id"); - EXPECT_EQ("set_id", GetSettings().device_id); + change.set_cloud_id("set_cloud_id"); + EXPECT_EQ("set_cloud_id", GetSettings().cloud_id); change.set_refresh_token("set_token"); EXPECT_EQ("set_token", GetSettings().refresh_token); @@ -198,7 +198,7 @@ 'client_id': 'set_client_id', 'client_secret': 'set_client_secret', 'description': 'set_description', - 'device_id': 'set_id', + 'cloud_id': 'set_cloud_id', 'local_anonymous_access_role': 'user', 'local_discovery_enabled': true, 'local_pairing_enabled': true,
diff --git a/libweave/src/device_registration_info.cc b/libweave/src/device_registration_info.cc index 66fe25f..ec23829 100644 --- a/libweave/src/device_registration_info.cc +++ b/libweave/src/device_registration_info.cc
@@ -257,9 +257,9 @@ std::string DeviceRegistrationInfo::GetDeviceURL( const std::string& subpath, const WebParamList& params) const { - CHECK(!GetSettings().device_id.empty()) << "Must have a valid device ID"; + CHECK(!GetSettings().cloud_id.empty()) << "Must have a valid device ID"; return BuildURL(GetSettings().service_url, - "devices/" + GetSettings().device_id + "/" + subpath, params); + "devices/" + GetSettings().cloud_id + "/" + subpath, params); } std::string DeviceRegistrationInfo::GetOAuthURL( @@ -293,7 +293,7 @@ bool DeviceRegistrationInfo::HaveRegistrationCredentials() const { return !GetSettings().refresh_token.empty() && - !GetSettings().device_id.empty() && + !GetSettings().cloud_id.empty() && !GetSettings().robot_account.empty(); } @@ -499,8 +499,8 @@ CHECK(state); std::unique_ptr<base::DictionaryValue> resource{new base::DictionaryValue}; - if (!GetSettings().device_id.empty()) - resource->SetString("id", GetSettings().device_id); + if (!GetSettings().cloud_id.empty()) + resource->SetString("id", GetSettings().cloud_id); resource->SetString("name", GetSettings().name); if (!GetSettings().description.empty()) resource->SetString("description", GetSettings().description); @@ -578,13 +578,13 @@ } std::string auth_code; - std::string device_id; + std::string cloud_id; std::string robot_account; const base::DictionaryValue* device_draft_response = nullptr; if (!json_resp->GetString("robotAccountEmail", &robot_account) || !json_resp->GetString("robotAccountAuthorizationCode", &auth_code) || !json_resp->GetDictionary("deviceDraft", &device_draft_response) || - !device_draft_response->GetString("id", &device_id)) { + !device_draft_response->GetString("id", &cloud_id)) { Error::AddTo(error, FROM_HERE, kErrorDomainGCD, "unexpected_response", "Device account missing in response"); return std::string(); @@ -622,7 +622,7 @@ base::Time::Now() + base::TimeDelta::FromSeconds(expires_in); Config::Transaction change{config_.get()}; - change.set_device_id(device_id); + change.set_cloud_id(cloud_id); change.set_robot_account(robot_account); change.set_refresh_token(refresh_token); change.Commit(); @@ -632,7 +632,7 @@ // We're going to respond with our success immediately and we'll connect to // cloud shortly after. ScheduleCloudConnection(base::TimeDelta::FromSeconds(0)); - return device_id; + return cloud_id; } void DeviceRegistrationInfo::DoCloudRequest( @@ -1043,7 +1043,7 @@ fetch_commands_request_queued_ = false; DoCloudRequest( http::kGet, - GetServiceURL("commands/queue", {{"deviceId", GetSettings().device_id}}), + GetServiceURL("commands/queue", {{"deviceId", GetSettings().cloud_id}}), nullptr, base::Bind(&DeviceRegistrationInfo::OnFetchCommandsSuccess, AsWeakPtr(), on_success), base::Bind(&DeviceRegistrationInfo::OnFetchCommandsError, AsWeakPtr(), @@ -1286,10 +1286,10 @@ FetchAndPublishCommands(); } -void DeviceRegistrationInfo::OnDeviceDeleted(const std::string& device_id) { - if (device_id != GetSettings().device_id) { - LOG(WARNING) << "Unexpected device deletion notification for device ID '" - << device_id << "'"; +void DeviceRegistrationInfo::OnDeviceDeleted(const std::string& cloud_id) { + if (cloud_id != GetSettings().cloud_id) { + LOG(WARNING) << "Unexpected device deletion notification for cloud ID '" + << cloud_id << "'"; return; } MarkDeviceUnregistered(); @@ -1303,7 +1303,7 @@ LOG(INFO) << "Device is unregistered from the cloud. Deleting credentials"; Config::Transaction change{config_.get()}; - change.set_device_id(""); + change.set_cloud_id(""); change.set_robot_account(""); change.set_refresh_token(""); change.Commit();
diff --git a/libweave/src/device_registration_info.h b/libweave/src/device_registration_info.h index 9cc1a51..8a6a157 100644 --- a/libweave/src/device_registration_info.h +++ b/libweave/src/device_registration_info.h
@@ -106,7 +106,7 @@ // Returns a service URL to access the registered device on GCD server. // The base URL used to construct the full URL looks like this: - // https://www.googleapis.com/clouddevices/v1/devices/<device_id>/ + // https://www.googleapis.com/clouddevices/v1/devices/<cloud_id>/ std::string GetDeviceURL(const std::string& subpath = {}, const WebParamList& params = {}) const; @@ -269,7 +269,7 @@ std::unique_ptr<base::DictionaryValue> BuildDeviceResource(ErrorPtr* error); void SetRegistrationStatus(RegistrationStatus new_status); - void SetDeviceId(const std::string& device_id); + void SetDeviceId(const std::string& cloud_id); // Callback called when command definitions are changed to re-publish new CDD. void OnCommandDefsChanged(); @@ -280,7 +280,7 @@ void OnDisconnected() override; void OnPermanentFailure() override; void OnCommandCreated(const base::DictionaryValue& command) override; - void OnDeviceDeleted(const std::string& device_id) override; + void OnDeviceDeleted(const std::string& cloud_id) override; // Wipes out the device registration information and stops server connections. void MarkDeviceUnregistered();
diff --git a/libweave/src/device_registration_info_unittest.cc b/libweave/src/device_registration_info_unittest.cc index f2fec8d..9e53155 100644 --- a/libweave/src/device_registration_info_unittest.cc +++ b/libweave/src/device_registration_info_unittest.cc
@@ -151,7 +151,7 @@ void ReloadSettings() { base::DictionaryValue dict; dict.SetString("refresh_token", test_data::kRefreshToken); - dict.SetString("device_id", test_data::kDeviceId); + dict.SetString("cloud_id", test_data::kDeviceId); dict.SetString("robot_account", test_data::kRobotAccountEmail); std::string json_string; base::JSONWriter::WriteWithOptions( @@ -485,14 +485,14 @@ .Times(AtLeast(1)) .WillRepeatedly(SaveArg<0>(&saved_settings)); - std::string device_id = + std::string cloud_id = dev_reg_->RegisterDevice(test_data::kClaimTicketId, nullptr); - EXPECT_EQ(test_data::kDeviceId, device_id); + EXPECT_EQ(test_data::kDeviceId, cloud_id); EXPECT_EQ(RegistrationStatus::kConnecting, GetRegistrationStatus()); // Validate the device info saved to storage... - EXPECT_EQ(test_data::kDeviceId, saved_settings.device_id); + EXPECT_EQ(test_data::kDeviceId, saved_settings.cloud_id); EXPECT_EQ(test_data::kRefreshToken, saved_settings.refresh_token); EXPECT_EQ(test_data::kRobotAccountEmail, saved_settings.robot_account); }
diff --git a/libweave/src/notification/notification_delegate.h b/libweave/src/notification/notification_delegate.h index a7df13b..ad49ab8 100644 --- a/libweave/src/notification/notification_delegate.h +++ b/libweave/src/notification/notification_delegate.h
@@ -20,7 +20,7 @@ // Called when a new command is sent via the notification channel. virtual void OnCommandCreated(const base::DictionaryValue& command) = 0; // Called when DEVICE_DELETED notification is received. - virtual void OnDeviceDeleted(const std::string& device_id) = 0; + virtual void OnDeviceDeleted(const std::string& cloud_id) = 0; protected: virtual ~NotificationDelegate() = default;
diff --git a/libweave/src/notification/notification_parser.cc b/libweave/src/notification/notification_parser.cc index 1e70feb..e0816e3 100644 --- a/libweave/src/notification/notification_parser.cc +++ b/libweave/src/notification/notification_parser.cc
@@ -26,13 +26,13 @@ // Processes DEVICE_DELETED notifications. bool ParseDeviceDeleted(const base::DictionaryValue& notification, NotificationDelegate* delegate) { - std::string device_id; - if (!notification.GetString("deviceId", &device_id)) { + std::string cloud_id; + if (!notification.GetString("deviceId", &cloud_id)) { LOG(ERROR) << "DEVICE_DELETED notification is missing 'deviceId' property"; return false; } - delegate->OnDeviceDeleted(device_id); + delegate->OnDeviceDeleted(cloud_id); return true; }
diff --git a/libweave/src/privet/cloud_delegate.cc b/libweave/src/privet/cloud_delegate.cc index 7d4a5f0..b1e7c16 100644 --- a/libweave/src/privet/cloud_delegate.cc +++ b/libweave/src/privet/cloud_delegate.cc
@@ -148,7 +148,7 @@ } std::string GetCloudId() const override { - return device_->GetSettings().device_id; + return device_->GetSettings().cloud_id; } const base::DictionaryValue& GetState() const override { return state_; } @@ -276,8 +276,8 @@ NotifyOnCommandDefsChanged(); } - void OnRegisterSuccess(const std::string& device_id) { - VLOG(1) << "Device registered: " << device_id; + void OnRegisterSuccess(const std::string& cloud_id) { + VLOG(1) << "Device registered: " << cloud_id; setup_state_ = SetupState(SetupState::kSuccess); }