Only show Usb sharing notifications when Crostini is enabled.

If other guest OSes are supported in future, we will refine this rule.

Bug: 948913
Change-Id: I2fb3db1a6cb690237a2c6896826311e895862531
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1559412
Commit-Queue: Nicholas Verne <nverne@chromium.org>
Auto-Submit: Nicholas Verne <nverne@chromium.org>
Reviewed-by: Timothy Loh <timloh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#649359}
diff --git a/chrome/browser/chromeos/usb/cros_usb_detector.cc b/chrome/browser/chromeos/usb/cros_usb_detector.cc
index 549f741..9b7a91d9 100644
--- a/chrome/browser/chromeos/usb/cros_usb_detector.cc
+++ b/chrome/browser/chromeos/usb/cros_usb_detector.cc
@@ -105,8 +105,7 @@
 
   void HandleShowSettings() {
     chrome::ShowSettingsSubPageForProfile(
-        ProfileManager::GetActiveUserProfile(),
-        chrome::kCrostiniSharedUsbDevicesSubPage);
+        profile(), chrome::kCrostiniSharedUsbDevicesSubPage);
     Close(false);
   }
 
@@ -279,6 +278,9 @@
 
 bool CrosUsbDetector::ShouldShowNotification(
     const device::mojom::UsbDeviceInfo& device_info) {
+  if (!crostini::IsCrostiniEnabled(profile())) {
+    return false;
+  }
   if (device::UsbDeviceFilterMatches(*adb_device_filter_, device_info)) {
     return true;
   }
diff --git a/chrome/browser/chromeos/usb/cros_usb_detector_unittest.cc b/chrome/browser/chromeos/usb/cros_usb_detector_unittest.cc
index 5cd2051f..1907ca7 100644
--- a/chrome/browser/chromeos/usb/cros_usb_detector_unittest.cc
+++ b/chrome/browser/chromeos/usb/cros_usb_detector_unittest.cc
@@ -11,6 +11,8 @@
 #include "base/strings/utf_string_conversions.h"
 #include "base/test/scoped_feature_list.h"
 #include "chrome/browser/chromeos/crostini/crostini_manager.h"
+#include "chrome/browser/chromeos/crostini/crostini_pref_names.h"
+#include "chrome/browser/chromeos/crostini/crostini_test_helper.h"
 #include "chrome/browser/chromeos/profiles/profile_helper.h"
 #include "chrome/browser/chromeos/usb/cros_usb_detector.h"
 #include "chrome/browser/notifications/notification_display_service.h"
@@ -129,12 +131,14 @@
 
   void SetUp() override {
     BrowserWithTestWindowTest::SetUp();
+    crostini_test_helper_.reset(new crostini::CrostiniTestHelper(profile()));
     scoped_feature_list_.InitWithFeatures(
         {chromeos::features::kCrostiniUsbSupport,
          chromeos::features::kCrostiniUsbAllowUnsupported},
         {});
     profile_manager()->SetLoggedIn(true);
     chromeos::ProfileHelper::Get()->SetActiveUserIdForTesting(kProfileName);
+
     TestingBrowserProcess::GetGlobal()->SetSystemNotificationHelper(
         std::make_unique<SystemNotificationHelper>());
     display_service_ = std::make_unique<NotificationDisplayServiceTester>(
@@ -148,6 +152,7 @@
   }
 
   void TearDown() override {
+    crostini_test_helper_.reset();
     BrowserWithTestWindowTest::TearDown();
   }
 
@@ -176,6 +181,8 @@
 
   base::test::ScopedFeatureList scoped_feature_list_;
 
+  std::unique_ptr<crostini::CrostiniTestHelper> crostini_test_helper_;
+
  private:
   DISALLOW_COPY_AND_ASSIGN(CrosUsbDetectorTest);
 };