Commit df3e781f authored by James Vecore's avatar James Vecore Committed by Commit Bot

[Nearby] Filter to PrimaryProfile only on CrOS

This change makes the Nearby Share keyed service only start for
'PrimaryProfiles' on chromeos and adds some additional profile oriented
logging for debugging process manager profile issues.

Change-Id: If239b038627c343bbf5848e9a4ab1f5aed498f3f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2391905Reviewed-by: default avatarRyan Hansberry <hansberry@chromium.org>
Commit-Queue: James Vecore <vecore@google.com>
Cr-Commit-Position: refs/heads/master@{#804148}
parent 8ecd46b9
......@@ -25,6 +25,10 @@
#include "components/prefs/pref_service.h"
#include "content/public/browser/browser_context.h"
#if defined(OS_CHROMEOS)
#include "chrome/browser/chromeos/profiles/profile_helper.h"
#endif
namespace {
constexpr char kServiceName[] = "NearbySharingService";
......@@ -61,8 +65,25 @@ KeyedService* NearbySharingServiceFactory::BuildServiceInstanceFor(
return nullptr;
}
NearbyProcessManager& process_manager = NearbyProcessManager::GetInstance();
Profile* profile = Profile::FromBrowserContext(context);
NearbyProcessManager& process_manager = NearbyProcessManager::GetInstance();
#if defined(OS_CHROMEOS)
// On ChromeOS we will only support the active profile.
if (!chromeos::ProfileHelper::IsPrimaryProfile(profile)) {
NS_LOG(VERBOSE)
<< __func__
<< ": Nearby Sharing service is skipping non-primary profile: "
<< profile->GetProfileUserName();
return nullptr;
}
NS_LOG(VERBOSE) << __func__
<< "Nearby Sharing service is forcing active profile: "
<< profile->GetProfileUserName();
// Force active profile for ChromeOS for now.
process_manager.SetActiveProfile(profile);
#endif
PrefService* pref_service = profile->GetPrefs();
NotificationDisplayService* notification_display_service =
NotificationDisplayServiceFactory::GetForProfile(profile);
......@@ -70,7 +91,9 @@ KeyedService* NearbySharingServiceFactory::BuildServiceInstanceFor(
auto nearby_connections_manager =
std::make_unique<NearbyConnectionsManagerImpl>(&process_manager, profile);
NS_LOG(VERBOSE) << __func__ << ": creating NearbySharingService.";
NS_LOG(VERBOSE) << __func__ << ": creating NearbySharingService for profile: "
<< profile->GetProfileUserName();
return new NearbySharingServiceImpl(
pref_service, notification_display_service, profile,
std::move(nearby_connections_manager), &process_manager);
......
......@@ -519,20 +519,22 @@ NearbyShareSettings* NearbySharingServiceImpl::GetSettings() {
void NearbySharingServiceImpl::OnNearbyProfileChanged(Profile* profile) {
// TODO(crbug.com/1084576): Notify UI about the new active profile.
NS_LOG(VERBOSE) << __func__ << ": Nearby profile changed to "
<< process_manager_->IsActiveProfile(profile_);
NS_LOG(VERBOSE) << __func__ << ": Active Nearby profile changed to: "
<< profile_->GetProfileUserName();
InvalidateSurfaceState();
}
void NearbySharingServiceImpl::OnNearbyProcessStarted() {
if (process_manager_->IsActiveProfile(profile_))
NS_LOG(VERBOSE) << __func__ << ": Nearby process started!";
NS_LOG(VERBOSE) << __func__ << ": Nearby process started for profile: "
<< profile_->GetProfileUserName();
}
void NearbySharingServiceImpl::OnNearbyProcessStopped() {
InvalidateSurfaceState();
if (process_manager_->IsActiveProfile(profile_))
NS_LOG(VERBOSE) << __func__ << ": Nearby process stopped!";
NS_LOG(VERBOSE) << __func__ << ": Nearby process stopped for profile: "
<< profile_->GetProfileUserName();
}
void NearbySharingServiceImpl::OnIncomingConnection(
......@@ -961,7 +963,8 @@ void NearbySharingServiceImpl::InvalidateReceiveSurfaceState() {
void NearbySharingServiceImpl::InvalidateAdvertisingState() {
if (!process_manager_->IsActiveProfile(profile_)) {
NS_LOG(VERBOSE) << __func__
<< ": Stopping advertising because profile not active";
<< ": Stopping advertising because profile was not active: "
<< profile_->GetProfileUserName();
StopAdvertising();
return;
}
......@@ -1112,7 +1115,8 @@ void NearbySharingServiceImpl::InvalidateSendSurfaceState() {
void NearbySharingServiceImpl::InvalidateScanningState() {
if (!process_manager_->IsActiveProfile(profile_)) {
NS_LOG(VERBOSE) << __func__
<< ": Stopping discovery because profile not active";
<< ": Stopping discovery because profile was not active: "
<< profile_->GetProfileUserName();
StopScanning();
return;
}
......
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