Commit a8130f20 authored by Juliet Levesque's avatar Juliet Levesque Committed by Commit Bot

[Nearby] Replace logging instances with NS_LOG macro.

Allows logging instances used for Nearby Share to show up on
chrome://nearby-internals logging tab.

Bug: 1093634
Change-Id: Ic6d4efb6cc46badd16cd516fa0333dbe73683ed8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2298184Reviewed-by: default avatarJosh Nohle <nohle@chromium.org>
Commit-Queue: Juliet Levesque <julietlevesque@google.com>
Cr-Commit-Position: refs/heads/master@{#790033}
parent 7de17a2d
......@@ -22,6 +22,7 @@ source_set("certificates") {
deps = [
"//base",
"//base/util/values:values_util",
"//chrome/browser/nearby_sharing/logging",
"//chrome/browser/nearby_sharing/proto",
"//crypto",
]
......
......@@ -6,9 +6,9 @@
#include <utility>
#include "base/logging.h"
#include "chrome/browser/nearby_sharing/certificates/common.h"
#include "chrome/browser/nearby_sharing/certificates/constants.h"
#include "chrome/browser/nearby_sharing/logging/logging.h"
#include "chrome/browser/nearby_sharing/proto/timestamp.pb.h"
#include "crypto/aead.h"
#include "crypto/encryptor.h"
......@@ -41,7 +41,7 @@ base::Optional<std::vector<uint8_t>> DecryptMetadataKey(
std::unique_ptr<crypto::Encryptor> encryptor =
CreateNearbyShareCtrEncryptor(secret_key, encrypted_metadata_key.salt());
if (!encryptor) {
LOG(ERROR)
NS_LOG(ERROR)
<< "Cannot decrypt metadata key: Could not create CTR encryptor.";
return base::nullopt;
}
......@@ -139,8 +139,8 @@ NearbyShareDecryptedPublicCertificate::DecryptPublicCertificate(
// Confirm that the decrypted metadata key agrees with key commitment tag.
if (!VerifyMetadataEncryptionKeyTag(*decrypted_metadata_key,
metadata_encryption_key_tag)) {
LOG(ERROR) << "Metadata decryption failed: Failed to verify metadata "
<< "encryption key tag.";
NS_LOG(ERROR) << "Metadata decryption failed: Failed to verify metadata "
<< "encryption key tag.";
return base::nullopt;
}
......@@ -150,16 +150,16 @@ NearbyShareDecryptedPublicCertificate::DecryptPublicCertificate(
DecryptMetadataPayload(encrypted_metadata, *decrypted_metadata_key,
secret_key.get());
if (!decrypted_metadata_bytes) {
LOG(ERROR) << "Metadata decryption failed: Failed to decrypt metadata "
<< "payload.";
NS_LOG(ERROR) << "Metadata decryption failed: Failed to decrypt metadata "
<< "payload.";
return base::nullopt;
}
nearbyshare::proto::EncryptedMetadata unencrypted_metadata;
if (!unencrypted_metadata.ParseFromArray(decrypted_metadata_bytes->data(),
decrypted_metadata_bytes->size())) {
LOG(ERROR) << "Metadata decryption failed: Failed to parse decrypted "
<< "metadata payload.";
NS_LOG(ERROR) << "Metadata decryption failed: Failed to parse decrypted "
<< "metadata payload.";
return base::nullopt;
}
......@@ -192,7 +192,7 @@ bool NearbyShareDecryptedPublicCertificate::VerifySignature(
crypto::SignatureVerifier verifier;
if (!verifier.VerifyInit(crypto::SignatureVerifier::ECDSA_SHA256, signature,
public_key_)) {
LOG(ERROR) << "Verification failed: Initialization unsuccessful.";
NS_LOG(ERROR) << "Verification failed: Initialization unsuccessful.";
return false;
}
......
......@@ -7,13 +7,13 @@
#include <utility>
#include "base/base64url.h"
#include "base/logging.h"
#include "base/rand_util.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_piece.h"
#include "base/util/values/values_util.h"
#include "chrome/browser/nearby_sharing/certificates/common.h"
#include "chrome/browser/nearby_sharing/certificates/constants.h"
#include "chrome/browser/nearby_sharing/logging/logging.h"
#include "chrome/browser/nearby_sharing/proto/timestamp.pb.h"
#include "crypto/aead.h"
#include "crypto/ec_private_key.h"
......@@ -184,14 +184,14 @@ base::Optional<NearbyShareEncryptedMetadataKey>
NearbySharePrivateCertificate::EncryptMetadataKey() {
base::Optional<std::vector<uint8_t>> salt = GenerateUnusedSalt();
if (!salt) {
LOG(ERROR) << "Encryption failed: Salt generation unsuccessful.";
NS_LOG(ERROR) << "Encryption failed: Salt generation unsuccessful.";
return base::nullopt;
}
std::unique_ptr<crypto::Encryptor> encryptor =
CreateNearbyShareCtrEncryptor(secret_key_.get(), *salt);
if (!encryptor) {
LOG(ERROR) << "Encryption failed: Could not create CTR encryptor.";
NS_LOG(ERROR) << "Encryption failed: Could not create CTR encryptor.";
return base::nullopt;
}
......@@ -199,7 +199,7 @@ NearbySharePrivateCertificate::EncryptMetadataKey() {
metadata_encryption_key_.size());
std::vector<uint8_t> encrypted_metadata_key;
if (!encryptor->Encrypt(metadata_encryption_key_, &encrypted_metadata_key)) {
LOG(ERROR) << "Encryption failed: Could not encrypt metadata key.";
NS_LOG(ERROR) << "Encryption failed: Could not encrypt metadata key.";
return base::nullopt;
}
......@@ -213,7 +213,7 @@ base::Optional<std::vector<uint8_t>> NearbySharePrivateCertificate::Sign(
std::vector<uint8_t> signature;
if (!signer->Sign(payload.data(), payload.size(), &signature)) {
LOG(ERROR) << "Signing failed.";
NS_LOG(ERROR) << "Signing failed.";
return base::nullopt;
}
......@@ -224,21 +224,21 @@ base::Optional<nearbyshare::proto::PublicCertificate>
NearbySharePrivateCertificate::ToPublicCertificate() {
std::vector<uint8_t> public_key;
if (!key_pair_->ExportPublicKey(&public_key)) {
LOG(ERROR) << "Failed to export public key.";
NS_LOG(ERROR) << "Failed to export public key.";
return base::nullopt;
}
base::Optional<std::vector<uint8_t>> encrypted_metadata_bytes =
EncryptMetadata();
if (!encrypted_metadata_bytes) {
LOG(ERROR) << "Failed to encrypt metadata.";
NS_LOG(ERROR) << "Failed to encrypt metadata.";
return base::nullopt;
}
base::Optional<std::vector<uint8_t>> metadata_encryption_key_tag =
CreateMetadataEncryptionKeyTag(metadata_encryption_key_);
if (!metadata_encryption_key_tag) {
LOG(ERROR) << "Failed to compute metadata encryption key tag.";
NS_LOG(ERROR) << "Failed to compute metadata encryption key tag.";
return base::nullopt;
}
......@@ -368,7 +368,7 @@ NearbySharePrivateCertificate::FromDictionary(const base::Value& dict) {
base::Optional<std::vector<uint8_t>>
NearbySharePrivateCertificate::GenerateUnusedSalt() {
if (consumed_salts_.size() >= kNearbyShareMaxNumMetadataEncryptionKeySalts) {
LOG(ERROR) << "All salts exhausted for certificate.";
NS_LOG(ERROR) << "All salts exhausted for certificate.";
return base::nullopt;
}
......@@ -390,8 +390,8 @@ NearbySharePrivateCertificate::GenerateUnusedSalt() {
}
}
LOG(ERROR) << "Salt generation exceeded max number of retries. This is "
"highly improbable.";
NS_LOG(ERROR) << "Salt generation exceeded max number of retries. This is "
"highly improbable.";
return base::nullopt;
}
......
......@@ -135,7 +135,8 @@ void FastInitiationManager::OnSetAdvertisingInterval(
void FastInitiationManager::OnSetAdvertisingIntervalError(
FastInitiationManager::FastInitType type,
device::BluetoothAdvertisement::ErrorCode code) {
LOG(WARNING) << "SetAdvertisingInterval() failed with error code = " << code;
NS_LOG(WARNING) << "SetAdvertisingInterval() failed with error code = "
<< code;
RegisterAdvertisement(type);
}
......@@ -190,7 +191,8 @@ void FastInitiationManager::OnRestoreAdvertisingInterval() {
void FastInitiationManager::OnRestoreAdvertisingIntervalError(
device::BluetoothAdvertisement::ErrorCode code) {
LOG(WARNING) << "SetAdvertisingInterval() failed with error code = " << code;
NS_LOG(WARNING) << "SetAdvertisingInterval() failed with error code = "
<< code;
UnregisterAdvertisement();
}
......
......@@ -174,8 +174,8 @@ NearbySharingServiceImpl::RegisterReceiveSurface(
DCHECK_NE(state, ReceiveSurfaceState::kUnknown);
if (foreground_receive_callbacks_.HasObserver(transfer_callback) ||
background_receive_callbacks_.HasObserver(transfer_callback)) {
VLOG(1) << __func__
<< ": registerReceiveSurface failed. Already registered.";
NS_LOG(VERBOSE) << __func__
<< ": registerReceiveSurface failed. Already registered.";
return StatusCodes::kError;
}
......@@ -192,8 +192,9 @@ NearbySharingServiceImpl::RegisterReceiveSurface(
background_receive_callbacks_.AddObserver(transfer_callback);
}
VLOG(1) << __func__ << ": A ReceiveSurface("
<< ReceiveSurfaceStateToString(state) << ") has been registered";
NS_LOG(VERBOSE) << __func__ << ": A ReceiveSurface("
<< ReceiveSurfaceStateToString(state)
<< ") has been registered";
InvalidateReceiveSurfaceState();
return StatusCodes::kOk;
}
......@@ -207,7 +208,7 @@ NearbySharingServiceImpl::UnregisterReceiveSurface(
bool is_background =
background_receive_callbacks_.HasObserver(transfer_callback);
if (!is_foreground && !is_background) {
VLOG(1)
NS_LOG(VERBOSE)
<< __func__
<< ": unregisterReceiveSurface failed. Unknown TransferUpdateCallback.";
return StatusCodes::kError;
......@@ -239,9 +240,9 @@ NearbySharingServiceImpl::UnregisterReceiveSurface(
}
}
VLOG(1) << __func__ << ": A ReceiveSurface("
<< (is_foreground ? "foreground" : "background")
<< ") has been unregistered";
NS_LOG(VERBOSE) << __func__ << ": A ReceiveSurface("
<< (is_foreground ? "foreground" : "background")
<< ") has been unregistered";
InvalidateReceiveSurfaceState();
return StatusCodes::kOk;
......@@ -341,13 +342,14 @@ Visibility NearbySharingServiceImpl::GetVisibilityPref() {
void NearbySharingServiceImpl::OnVisibilityPrefChanged() {
Visibility new_visibility = GetVisibilityPref();
if (advertising_visibilty_preference_ == new_visibility) {
VLOG(1) << __func__ << ": Nearby sharing visibility pref is unchanged";
NS_LOG(VERBOSE) << __func__
<< ": Nearby sharing visibility pref is unchanged";
return;
}
advertising_visibilty_preference_ = new_visibility;
VLOG(1) << __func__ << ": Nearby sharing visibility changed to "
<< VisibilityToString(advertising_visibilty_preference_);
NS_LOG(VERBOSE) << __func__ << ": Nearby sharing visibility changed to "
<< VisibilityToString(advertising_visibilty_preference_);
if (advertising_power_level_ != PowerLevel::kUnknown) {
StopAdvertising();
......@@ -367,11 +369,12 @@ DataUsage NearbySharingServiceImpl::GetDataUsagePref() {
void NearbySharingServiceImpl::OnDataUsagePrefChanged() {
DataUsage new_data_usage = GetDataUsagePref();
if (advertising_data_usage_preference_ == new_data_usage) {
VLOG(1) << __func__ << ": Nearby sharing data usage pref is unchanged";
NS_LOG(VERBOSE) << __func__
<< ": Nearby sharing data usage pref is unchanged";
return;
}
VLOG(1) << __func__ << ": Nearby sharing data usage changed.";
NS_LOG(VERBOSE) << __func__ << ": Nearby sharing data usage changed.";
if (advertising_power_level_ != PowerLevel::kUnknown) {
StopAdvertising();
}
......@@ -496,8 +499,8 @@ void NearbySharingServiceImpl::InvalidateAdvertisingState() {
// Screen is off. Do no work.
if (ui::CheckIdleStateIsLocked()) {
StopAdvertising();
VLOG(1) << __func__
<< ": Stopping advertising because the screen is locked.";
NS_LOG(VERBOSE) << __func__
<< ": Stopping advertising because the screen is locked.";
return;
}
......@@ -512,24 +515,26 @@ void NearbySharingServiceImpl::InvalidateAdvertisingState() {
connection_type ==
net::NetworkChangeNotifier::ConnectionType::CONNECTION_ETHERNET)) {
StopAdvertising();
VLOG(1) << __func__
<< ": Stopping advertising because both bluetooth and wifi LAN are "
"disabled.";
NS_LOG(VERBOSE)
<< __func__
<< ": Stopping advertising because both bluetooth and wifi LAN are "
"disabled.";
return;
}
// Nearby Sharing is disabled. Don't advertise.
if (!IsEnabled()) {
StopAdvertising();
VLOG(1) << __func__
<< ": Stopping advertising because Nearby Sharing is disabled.";
NS_LOG(VERBOSE)
<< __func__
<< ": Stopping advertising because Nearby Sharing is disabled.";
return;
}
// We're scanning for other nearby devices. Don't advertise.
if (is_scanning_) {
StopAdvertising();
VLOG(1)
NS_LOG(VERBOSE)
<< __func__
<< ": Stopping advertising because we're scanning for other devices.";
return;
......@@ -537,16 +542,17 @@ void NearbySharingServiceImpl::InvalidateAdvertisingState() {
if (is_transferring_files_) {
StopAdvertising();
VLOG(1) << __func__
<< ": Stopping advertising because we're currently in the midst of "
"a transfer.";
NS_LOG(VERBOSE)
<< __func__
<< ": Stopping advertising because we're currently in the midst of "
"a transfer.";
return;
}
if (!foreground_receive_callbacks_.might_have_observers() &&
!background_receive_callbacks_.might_have_observers()) {
StopAdvertising();
VLOG(1)
NS_LOG(VERBOSE)
<< __func__
<< ": Stopping advertising because no receive surface is registered.";
return;
......@@ -555,9 +561,10 @@ void NearbySharingServiceImpl::InvalidateAdvertisingState() {
if (!IsVisibleInBackground(advertising_visibilty_preference_) &&
!foreground_receive_callbacks_.might_have_observers()) {
StopAdvertising();
VLOG(1) << __func__
<< ": Stopping advertising because no high power receive surface "
"is registered and device is visible to NO_ONE.";
NS_LOG(VERBOSE)
<< __func__
<< ": Stopping advertising because no high power receive surface "
"is registered and device is visible to NO_ONE.";
return;
}
......@@ -575,19 +582,21 @@ void NearbySharingServiceImpl::InvalidateAdvertisingState() {
if (advertising_power_level_ != PowerLevel::kUnknown) {
if (power_level == advertising_power_level_ &&
data_usage == advertising_data_usage_preference_) {
VLOG(1) << __func__
<< "Failed to advertise because we're already advertising with "
"power level "
<< PowerLevelToString(advertising_power_level_)
<< " and data usage preference "
<< DataUsageToString(advertising_data_usage_preference_);
NS_LOG(VERBOSE)
<< __func__
<< "Failed to advertise because we're already advertising with "
"power level "
<< PowerLevelToString(advertising_power_level_)
<< " and data usage preference "
<< DataUsageToString(advertising_data_usage_preference_);
return;
}
StopAdvertising();
VLOG(1) << __func__ << ": Restart advertising with power level "
<< PowerLevelToString(power_level) << " and data usage preference "
<< DataUsageToString(data_usage);
NS_LOG(VERBOSE) << __func__ << ": Restart advertising with power level "
<< PowerLevelToString(power_level)
<< " and data usage preference "
<< DataUsageToString(data_usage);
}
// Starts advertising through Nearby Connections. Caller is expected to ensure
......@@ -609,7 +618,7 @@ void NearbySharingServiceImpl::InvalidateAdvertisingState() {
std::move(endpoint_info),
/* listener= */ this, power_level, data_usage,
base::BindOnce([](NearbyConnectionsManager::ConnectionsStatus status) {
VLOG(1)
NS_LOG(VERBOSE)
<< __func__
<< ": Advertising attempted over Nearby Connections with result "
<< ConnectionsStatusToString(status);
......@@ -617,18 +626,20 @@ void NearbySharingServiceImpl::InvalidateAdvertisingState() {
advertising_power_level_ = power_level;
advertising_data_usage_preference_ = data_usage;
VLOG(1) << __func__ << ": Advertising has started over Nearby Connections: "
<< " power level " << PowerLevelToString(power_level)
<< " visibility "
<< VisibilityToString(advertising_visibilty_preference_)
<< " data usage " << DataUsageToString(data_usage);
NS_LOG(VERBOSE) << __func__
<< ": Advertising has started over Nearby Connections: "
<< " power level " << PowerLevelToString(power_level)
<< " visibility "
<< VisibilityToString(advertising_visibilty_preference_)
<< " data usage " << DataUsageToString(data_usage);
return;
}
void NearbySharingServiceImpl::StopAdvertising() {
if (advertising_power_level_ == PowerLevel::kUnknown) {
VLOG(1) << __func__
<< ": Failed to stop advertising because we weren't advertising";
NS_LOG(VERBOSE)
<< __func__
<< ": Failed to stop advertising because we weren't advertising";
return;
}
......@@ -636,5 +647,5 @@ void NearbySharingServiceImpl::StopAdvertising() {
advertising_data_usage_preference_ = DataUsage::kUnknown;
advertising_power_level_ = PowerLevel::kUnknown;
VLOG(1) << __func__ << ": Advertising has stopped";
NS_LOG(VERBOSE) << __func__ << ": Advertising has stopped";
}
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