Commit ea750d09 authored by Ana Salazar's avatar Ana Salazar Committed by Commit Bot

Add Nearby Shared files into the holding space model

We want to give users a quick shortcut to access recent nearby shared
files within Tote. As user receives a file via nearby share, we should
be able to add them to the holding space model in a similar way we add
downloads as they are completed.

Bug: 1130625
Change-Id: Iba7ab69e7f8d9b7c05e740e8e4331b85a890b423
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2463584Reviewed-by: default avatarToni Baržić <tbarzic@chromium.org>
Reviewed-by: default avatarJosh Nohle <nohle@chromium.org>
Commit-Queue: Ana Salazar <anasalazar@chromium.org>
Cr-Commit-Position: refs/heads/master@{#822896}
parent ecf20847
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include "chrome/browser/nearby_sharing/nearby_notification_manager.h" #include "chrome/browser/nearby_sharing/nearby_notification_manager.h"
#include "ash/public/cpp/ash_features.h"
#include "base/files/file_util.h" #include "base/files/file_util.h"
#include "base/notreached.h" #include "base/notreached.h"
#include "base/strings/strcat.h" #include "base/strings/strcat.h"
...@@ -22,6 +23,8 @@ ...@@ -22,6 +23,8 @@
#include "chrome/browser/notifications/notification_display_service.h" #include "chrome/browser/notifications/notification_display_service.h"
#include "chrome/browser/platform_util.h" #include "chrome/browser/platform_util.h"
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/ash/holding_space/holding_space_keyed_service.h"
#include "chrome/browser/ui/ash/holding_space/holding_space_keyed_service_factory.h"
#include "chrome/grit/generated_resources.h" #include "chrome/grit/generated_resources.h"
#include "components/prefs/pref_service.h" #include "components/prefs/pref_service.h"
#include "content/public/browser/browser_thread.h" #include "content/public/browser/browser_thread.h"
...@@ -725,6 +728,18 @@ void NearbyNotificationManager::ShowIncomingSuccess( ...@@ -725,6 +728,18 @@ void NearbyNotificationManager::ShowIncomingSuccess(
notification_display_service_->Display( notification_display_service_->Display(
NotificationHandler::Type::NEARBY_SHARE, notification, NotificationHandler::Type::NEARBY_SHARE, notification,
/*metadata=*/nullptr); /*metadata=*/nullptr);
if (ash::features::IsTemporaryHoldingSpaceEnabled()) {
ash::HoldingSpaceKeyedService* holding_space_keyed_service =
ash::HoldingSpaceKeyedServiceFactory::GetInstance()->GetService(
profile_);
if (holding_space_keyed_service) {
for (const auto& file : share_target.file_attachments) {
if (file.file_path().has_value())
holding_space_keyed_service->AddNearbyShare(file.file_path().value());
}
}
}
} }
void NearbyNotificationManager::ShowFailure(const ShareTarget& share_target) { void NearbyNotificationManager::ShowFailure(const ShareTarget& share_target) {
......
...@@ -7,6 +7,10 @@ ...@@ -7,6 +7,10 @@
#include <memory> #include <memory>
#include <vector> #include <vector>
#include "ash/public/cpp/ash_features.h"
#include "ash/public/cpp/holding_space/holding_space_controller.h"
#include "ash/public/cpp/holding_space/holding_space_item.h"
#include "ash/public/cpp/holding_space/holding_space_model.h"
#include "base/files/file_util.h" #include "base/files/file_util.h"
#include "base/files/scoped_temp_dir.h" #include "base/files/scoped_temp_dir.h"
#include "base/strings/strcat.h" #include "base/strings/strcat.h"
...@@ -19,6 +23,7 @@ ...@@ -19,6 +23,7 @@
#include "base/threading/thread_restrictions.h" #include "base/threading/thread_restrictions.h"
#include "chrome/app/vector_icons/vector_icons.h" #include "chrome/app/vector_icons/vector_icons.h"
#include "chrome/browser/browser_features.h" #include "chrome/browser/browser_features.h"
#include "chrome/browser/chromeos/login/users/fake_chrome_user_manager.h"
#include "chrome/browser/download/chrome_download_manager_delegate.h" #include "chrome/browser/download/chrome_download_manager_delegate.h"
#include "chrome/browser/download/download_core_service_factory.h" #include "chrome/browser/download/download_core_service_factory.h"
#include "chrome/browser/download/download_core_service_impl.h" #include "chrome/browser/download/download_core_service_impl.h"
...@@ -32,11 +37,21 @@ ...@@ -32,11 +37,21 @@
#include "chrome/browser/nearby_sharing/transfer_metadata_builder.h" #include "chrome/browser/nearby_sharing/transfer_metadata_builder.h"
#include "chrome/browser/notifications/notification_display_service_factory.h" #include "chrome/browser/notifications/notification_display_service_factory.h"
#include "chrome/browser/notifications/notification_display_service_tester.h" #include "chrome/browser/notifications/notification_display_service_tester.h"
#include "chrome/browser/ui/ash/holding_space/fake_holding_space_color_provider.h"
#include "chrome/browser/ui/ash/holding_space/holding_space_keyed_service_factory.h"
#include "chrome/browser/ui/ash/holding_space/scoped_test_downloads_mount_point.h"
#include "chrome/browser/ui/ash/test_session_controller.h"
#include "chrome/grit/generated_resources.h" #include "chrome/grit/generated_resources.h"
#include "chrome/test/base/testing_browser_process.h"
#include "chrome/test/base/testing_profile.h" #include "chrome/test/base/testing_profile.h"
#include "chrome/test/base/testing_profile_manager.h"
#include "components/account_id/account_id.h"
#include "components/prefs/testing_pref_service.h" #include "components/prefs/testing_pref_service.h"
#include "components/sync_preferences/testing_pref_service_syncable.h"
#include "content/public/test/browser_task_environment.h" #include "content/public/test/browser_task_environment.h"
#include "services/data_decoder/public/cpp/test_support/in_process_data_decoder.h" #include "services/data_decoder/public/cpp/test_support/in_process_data_decoder.h"
#include "storage/browser/file_system/external_mount_points.h"
#include "storage/browser/file_system/file_system_context.h"
#include "testing/gmock/include/gmock/gmock.h" #include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
#include "third_party/skia/include/core/SkBitmap.h" #include "third_party/skia/include/core/SkBitmap.h"
...@@ -96,6 +111,13 @@ SkBitmap CreateTestSkBitmap() { ...@@ -96,6 +111,13 @@ SkBitmap CreateTestSkBitmap() {
return bitmap; return bitmap;
} }
std::unique_ptr<TestingProfileManager> CreateTestingProfileManager() {
std::unique_ptr<TestingProfileManager> profile_manager(
new TestingProfileManager(TestingBrowserProcess::GetGlobal()));
EXPECT_TRUE(profile_manager->SetUp());
return profile_manager;
}
class NearbyNotificationManagerTest : public testing::Test { class NearbyNotificationManagerTest : public testing::Test {
public: public:
NearbyNotificationManagerTest() { NearbyNotificationManagerTest() {
...@@ -1118,3 +1140,96 @@ TEST_F(NearbyNotificationManagerTest, ...@@ -1118,3 +1140,96 @@ TEST_F(NearbyNotificationManagerTest,
// Notification should be closed. // Notification should be closed.
EXPECT_EQ(0u, GetDisplayedNotifications().size()); EXPECT_EQ(0u, GetDisplayedNotifications().size());
} }
class NearbyFilesHoldingSpaceTest : public testing::Test {
public:
NearbyFilesHoldingSpaceTest()
: session_controller_(std::make_unique<TestSessionController>()),
user_manager_(new chromeos::FakeChromeUserManager) {
scoped_feature_list_.InitWithFeatures(
{features::kNearbySharing, ash::features::kTemporaryHoldingSpace}, {});
holding_space_controller_ = std::make_unique<ash::HoldingSpaceController>(
std::make_unique<ash::holding_space::FakeHoldingSpaceColorProvider>());
profile_manager_ = CreateTestingProfileManager();
const AccountId account_id(AccountId::FromUserEmail(""));
user_manager_->AddUser(account_id);
user_manager_->LoginUser(account_id);
profile_ = profile_manager_->CreateTestingProfile("");
}
~NearbyFilesHoldingSpaceTest() override = default;
// testing::Test:
void SetUp() override {
manager_ = std::make_unique<NearbyNotificationManager>(
NotificationDisplayServiceFactory::GetForProfile(profile_),
CreateAndUseMockNearbySharingService(profile_), profile_->GetPrefs(),
profile_);
}
NearbyNotificationManager* manager() { return manager_.get(); }
ash::HoldingSpaceModel* GetHoldingSpaceModel() const {
return holding_space_controller_ ? holding_space_controller_->model()
: nullptr;
}
protected:
base::test::ScopedFeatureList scoped_feature_list_;
content::BrowserTaskEnvironment task_environment_{
base::test::TaskEnvironment::TimeSource::MOCK_TIME};
std::unique_ptr<TestingProfileManager> profile_manager_;
TestingProfile* profile_;
std::unique_ptr<NearbyNotificationManager> manager_;
std::unique_ptr<TestSessionController> session_controller_;
std::unique_ptr<ash::HoldingSpaceController> holding_space_controller_;
chromeos::FakeChromeUserManager* user_manager_;
};
TEST_F(NearbyFilesHoldingSpaceTest, ShowSuccess_Files) {
ash::holding_space::ScopedTestDownloadsMountPoint downloads_mount(profile_);
ASSERT_TRUE(downloads_mount.IsValid());
ShareTarget share_target;
share_target.is_incoming = true;
const base::FilePath file_virtual_path("Sample.txt");
base::FilePath file_path =
downloads_mount.CreateFile(file_virtual_path, "Sample Text");
FileAttachment attachment(file_path);
share_target.file_attachments.push_back(std::move(attachment));
manager()->ShowSuccess(share_target);
ash::HoldingSpaceModel* holding_space_model = GetHoldingSpaceModel();
ASSERT_TRUE(holding_space_model);
ASSERT_EQ(share_target.file_attachments.size(),
holding_space_model->items().size());
for (int i = 0; i < share_target.file_attachments.size(); ++i) {
ash::HoldingSpaceItem* holding_space_item =
holding_space_model->items()[i].get();
EXPECT_EQ(ash::HoldingSpaceItem::Type::kNearbyShare,
holding_space_item->type());
EXPECT_EQ(share_target.file_attachments[i].file_path(),
holding_space_item->file_path());
}
}
TEST_F(NearbyFilesHoldingSpaceTest, ShowSuccess_Text) {
ShareTarget share_target;
share_target.is_incoming = true;
TextAttachment attachment(TextAttachment::Type::kText, "Sample Text");
share_target.text_attachments.push_back(std::move(attachment));
manager()->ShowSuccess(share_target);
ash::HoldingSpaceModel* holding_space_model = GetHoldingSpaceModel();
ASSERT_TRUE(holding_space_model);
EXPECT_TRUE(holding_space_model->items().empty());
}
...@@ -36,8 +36,12 @@ source_set("test_support") { ...@@ -36,8 +36,12 @@ source_set("test_support") {
testonly = true testonly = true
sources = [ sources = [
"//chrome/browser/ui/ash/holding_space/fake_holding_space_color_provider.cc",
"//chrome/browser/ui/ash/holding_space/fake_holding_space_color_provider.h",
"//chrome/browser/ui/ash/holding_space/holding_space_browsertest_base.cc", "//chrome/browser/ui/ash/holding_space/holding_space_browsertest_base.cc",
"//chrome/browser/ui/ash/holding_space/holding_space_browsertest_base.h", "//chrome/browser/ui/ash/holding_space/holding_space_browsertest_base.h",
"//chrome/browser/ui/ash/holding_space/scoped_test_downloads_mount_point.cc",
"//chrome/browser/ui/ash/holding_space/scoped_test_downloads_mount_point.h",
] ]
deps = [ deps = [
......
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/ui/ash/holding_space/fake_holding_space_color_provider.h"
#include "base/files/file_util.h"
#include "chrome/browser/chromeos/file_manager/app_id.h"
#include "chrome/browser/chromeos/file_manager/fileapi_util.h"
#include "chrome/browser/chromeos/file_manager/path_util.h"
#include "storage/browser/file_system/external_mount_points.h"
#include "storage/browser/file_system/file_system_context.h"
namespace ash {
namespace holding_space {
SkColor FakeHoldingSpaceColorProvider::GetBackgroundColor() const {
return SkColor();
}
SkColor FakeHoldingSpaceColorProvider::GetFileIconColor() const {
return SkColor();
}
} // namespace holding_space
} // namespace ash
\ No newline at end of file
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_UI_ASH_HOLDING_SPACE_FAKE_HOLDING_SPACE_COLOR_PROVIDER_H_
#define CHROME_BROWSER_UI_ASH_HOLDING_SPACE_FAKE_HOLDING_SPACE_COLOR_PROVIDER_H_
#include "ash/public/cpp/holding_space/holding_space_color_provider.h"
namespace ash {
namespace holding_space {
class FakeHoldingSpaceColorProvider : public ash::HoldingSpaceColorProvider {
public:
FakeHoldingSpaceColorProvider() = default;
FakeHoldingSpaceColorProvider(const FakeHoldingSpaceColorProvider&) = delete;
FakeHoldingSpaceColorProvider& operator=(
const FakeHoldingSpaceColorProvider&) = delete;
~FakeHoldingSpaceColorProvider() override = default;
// ash::HoldingSpaceColorProvider:
SkColor GetBackgroundColor() const override;
SkColor GetFileIconColor() const override;
};
} // namespace holding_space
} // namespace ash
#endif // CHROME_BROWSER_UI_ASH_HOLDING_SPACE_FAKE_HOLDING_SPACE_COLOR_PROVIDER_H_
\ No newline at end of file
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/ui/ash/holding_space/scoped_test_downloads_mount_point.h"
#include "base/files/file_util.h"
#include "chrome/browser/chromeos/file_manager/app_id.h"
#include "chrome/browser/chromeos/file_manager/fileapi_util.h"
#include "chrome/browser/chromeos/file_manager/path_util.h"
#include "storage/browser/file_system/external_mount_points.h"
#include "storage/browser/file_system/file_system_context.h"
namespace ash {
namespace holding_space {
ScopedTestDownloadsMountPoint::ScopedTestDownloadsMountPoint(Profile* profile)
: name_(file_manager::util::GetDownloadsMountPointName(profile)) {
if (!temp_dir_.CreateUniqueTempDir())
return;
storage::ExternalMountPoints::GetSystemInstance()->RegisterFileSystem(
name_, storage::kFileSystemTypeNativeLocal,
storage::FileSystemMountOption(), temp_dir_.GetPath());
file_manager::util::GetFileSystemContextForExtensionId(
profile, file_manager::kFileManagerAppId)
->external_backend()
->GrantFileAccessToExtension(file_manager::kFileManagerAppId,
base::FilePath(name_));
}
ScopedTestDownloadsMountPoint::~ScopedTestDownloadsMountPoint() {
storage::ExternalMountPoints::GetSystemInstance()->RevokeFileSystem(name_);
}
base::FilePath ScopedTestDownloadsMountPoint::CreateFile(
const base::FilePath& relative_path,
const std::string& content) {
const base::FilePath path = GetRootPath().Append(relative_path);
if (!base::CreateDirectory(path.DirName()))
return base::FilePath();
if (!base::WriteFile(path, content))
return base::FilePath();
return path;
}
base::FilePath ScopedTestDownloadsMountPoint::CreateArbitraryFile() {
return CreateFile(base::FilePath(base::UnguessableToken::Create().ToString()),
/*content=*/std::string());
}
} // namespace holding_space
} // namespace ash
\ No newline at end of file
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_UI_ASH_HOLDING_SPACE_SCOPED_TEST_DOWNLOADS_MOUNT_POINT_H_
#define CHROME_BROWSER_UI_ASH_HOLDING_SPACE_SCOPED_TEST_DOWNLOADS_MOUNT_POINT_H_
#include <memory>
#include "base/files/scoped_temp_dir.h"
class GURL;
class Profile;
namespace base {
class FilePath;
} // namespace base
namespace ash {
namespace holding_space {
// Utility class that registers the downloads external file system mount point,
// and grants file manager app access permission for the mount point.
class ScopedTestDownloadsMountPoint {
public:
explicit ScopedTestDownloadsMountPoint(Profile* profile);
ScopedTestDownloadsMountPoint(const ScopedTestDownloadsMountPoint&) = delete;
ScopedTestDownloadsMountPoint& operator=(
const ScopedTestDownloadsMountPoint&) = delete;
~ScopedTestDownloadsMountPoint();
bool IsValid() const { return temp_dir_.IsValid(); }
const base::FilePath& GetRootPath() const { return temp_dir_.GetPath(); }
const std::string& name() const { return name_; }
// Creates a file under [mount point root path]/|relative_path| with the
// provided content. Returns the created file's file path, or an empty path on
// failure.
base::FilePath CreateFile(const base::FilePath& relative_path,
const std::string& content);
// Creates an arbitrary file under the 'mount_point'.
base::FilePath CreateArbitraryFile();
private:
base::ScopedTempDir temp_dir_;
std::string name_;
};
} // namespace holding_space
} // namespace ash
#endif // CHROME_BROWSER_UI_ASH_HOLDING_SPACE_SCOPED_TEST_DOWNLOADS_MOUNT_POINT_H_
\ No newline at end of file
...@@ -5017,6 +5017,7 @@ test("unit_tests") { ...@@ -5017,6 +5017,7 @@ test("unit_tests") {
"//chrome/browser/resources/chromeos/zip_archiver/cpp:ziparchiver_unittests", "//chrome/browser/resources/chromeos/zip_archiver/cpp:ziparchiver_unittests",
"//chrome/browser/ui/app_list/search/search_result_ranker:app_launch_predictor_proto", "//chrome/browser/ui/app_list/search/search_result_ranker:app_launch_predictor_proto",
"//chrome/browser/ui/app_list/search/search_result_ranker:recurrence_ranker_proto", "//chrome/browser/ui/app_list/search/search_result_ranker:recurrence_ranker_proto",
"//chrome/browser/ui/ash/holding_space:test_support",
"//chrome/services/printing:pdf_thumbnailer_test", "//chrome/services/printing:pdf_thumbnailer_test",
"//chrome/services/sharing:unit_tests", "//chrome/services/sharing:unit_tests",
"//chrome/services/sharing/nearby:unit_tests", "//chrome/services/sharing/nearby:unit_tests",
......
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