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

Add nearby shared files type to holding space model

Define a new item type for files added to the holding space via nearby
sharing functionality.

Nearby shared files will be shown in the downloads section of the
holding space and will be persisted.

Bug: 1130625
Change-Id: I6da1da172a7de5e4f3ae3c321434376ffc80a38f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2450053Reviewed-by: default avatarDavid Black <dmblack@google.com>
Reviewed-by: default avatarWeilun Shi <sweilun@chromium.org>
Reviewed-by: default avatarSteven Holte <holte@chromium.org>
Commit-Queue: Ana Salazar <anasalazar@chromium.org>
Cr-Commit-Position: refs/heads/master@{#814909}
parent 3062ff2e
...@@ -35,6 +35,8 @@ std::string TypeToString(HoldingSpaceItem::Type type) { ...@@ -35,6 +35,8 @@ std::string TypeToString(HoldingSpaceItem::Type type) {
return "download"; return "download";
case HoldingSpaceItem::Type::kScreenshot: case HoldingSpaceItem::Type::kScreenshot:
return "screenshot"; return "screenshot";
case HoldingSpaceItem::Type::kNearbyShare:
return "nearby_share";
} }
} }
......
...@@ -34,7 +34,8 @@ class ASH_PUBLIC_EXPORT HoldingSpaceItem { ...@@ -34,7 +34,8 @@ class ASH_PUBLIC_EXPORT HoldingSpaceItem {
kPinnedFile = 0, kPinnedFile = 0,
kScreenshot = 1, kScreenshot = 1,
kDownload = 2, kDownload = 2,
kMaxValue = kDownload, kNearbyShare = 3,
kMaxValue = kNearbyShare,
}; };
HoldingSpaceItem(const HoldingSpaceItem&) = delete; HoldingSpaceItem(const HoldingSpaceItem&) = delete;
......
...@@ -50,6 +50,8 @@ std::string ItemTypeToString(HoldingSpaceItem::Type type) { ...@@ -50,6 +50,8 @@ std::string ItemTypeToString(HoldingSpaceItem::Type type) {
return "PinnedFile"; return "PinnedFile";
case HoldingSpaceItem::Type::kScreenshot: case HoldingSpaceItem::Type::kScreenshot:
return "Screenshot"; return "Screenshot";
case HoldingSpaceItem::Type::kNearbyShare:
return "NearbyShare";
} }
NOTREACHED(); NOTREACHED();
return std::string(); return std::string();
......
...@@ -173,6 +173,11 @@ HoldingSpaceItem* HoldingSpaceBrowserTestBase::AddDownloadFile() { ...@@ -173,6 +173,11 @@ HoldingSpaceItem* HoldingSpaceBrowserTestBase::AddDownloadFile() {
/*file_path=*/CreateTextFile(GetProfile())); /*file_path=*/CreateTextFile(GetProfile()));
} }
HoldingSpaceItem* HoldingSpaceBrowserTestBase::AddNearbyShareFile() {
return AddItem(GetProfile(), HoldingSpaceItem::Type::kNearbyShare,
/*file_path=*/CreateImageFile(GetProfile()));
}
HoldingSpaceItem* HoldingSpaceBrowserTestBase::AddPinnedFile() { HoldingSpaceItem* HoldingSpaceBrowserTestBase::AddPinnedFile() {
return AddItem(GetProfile(), HoldingSpaceItem::Type::kPinnedFile, return AddItem(GetProfile(), HoldingSpaceItem::Type::kPinnedFile,
/*file_path=*/CreateTextFile(GetProfile())); /*file_path=*/CreateTextFile(GetProfile()));
......
...@@ -54,6 +54,9 @@ class HoldingSpaceBrowserTestBase : public InProcessBrowserTest { ...@@ -54,6 +54,9 @@ class HoldingSpaceBrowserTestBase : public InProcessBrowserTest {
// Adds and returns an arbitrary download file to the holding space. // Adds and returns an arbitrary download file to the holding space.
HoldingSpaceItem* AddDownloadFile(); HoldingSpaceItem* AddDownloadFile();
// Adds and returns an arbitrary nearby share file to the holding space.
HoldingSpaceItem* AddNearbyShareFile();
// Adds and returns an arbitrary pinned file to the holding space. // Adds and returns an arbitrary pinned file to the holding space.
HoldingSpaceItem* AddPinnedFile(); HoldingSpaceItem* AddPinnedFile();
......
...@@ -173,6 +173,26 @@ void HoldingSpaceKeyedService::AddDownload( ...@@ -173,6 +173,26 @@ void HoldingSpaceKeyedService::AddDownload(
download_file))); download_file)));
} }
void HoldingSpaceKeyedService::AddNearbyShare(
const base::FilePath& nearby_share_path) {
const bool already_exists =
holding_space_model_.GetItem(HoldingSpaceItem::GetFileBackedItemId(
HoldingSpaceItem::Type::kNearbyShare, nearby_share_path));
if (already_exists)
return;
GURL file_system_url =
holding_space_util::ResolveFileSystemUrl(profile_, nearby_share_path);
if (file_system_url.is_empty())
return;
AddItem(HoldingSpaceItem::CreateFileBackedItem(
HoldingSpaceItem::Type::kNearbyShare, nearby_share_path, file_system_url,
holding_space_util::ResolveImage(&thumbnail_loader_,
HoldingSpaceItem::Type::kNearbyShare,
nearby_share_path)));
}
void HoldingSpaceKeyedService::AddItem(std::unique_ptr<HoldingSpaceItem> item) { void HoldingSpaceKeyedService::AddItem(std::unique_ptr<HoldingSpaceItem> item) {
holding_space_model_.AddItem(std::move(item)); holding_space_model_.AddItem(std::move(item));
} }
......
...@@ -74,6 +74,9 @@ class HoldingSpaceKeyedService : public KeyedService, ...@@ -74,6 +74,9 @@ class HoldingSpaceKeyedService : public KeyedService,
// Adds a download item backed by the provided absolute file path. // Adds a download item backed by the provided absolute file path.
void AddDownload(const base::FilePath& download_path); void AddDownload(const base::FilePath& download_path);
// Adds a nearby share item backed by the provided absolute file path.
void AddNearbyShare(const base::FilePath& nearby_share_path);
// Adds the specified `item` to the holding space model. // Adds the specified `item` to the holding space model.
void AddItem(std::unique_ptr<HoldingSpaceItem> item); void AddItem(std::unique_ptr<HoldingSpaceItem> item);
......
...@@ -32,6 +32,7 @@ gfx::ImageSkia GetPlaceholderImage(HoldingSpaceItem::Type type, ...@@ -32,6 +32,7 @@ gfx::ImageSkia GetPlaceholderImage(HoldingSpaceItem::Type type,
gfx::Size size; gfx::Size size;
switch (type) { switch (type) {
case HoldingSpaceItem::Type::kDownload: case HoldingSpaceItem::Type::kDownload:
case HoldingSpaceItem::Type::kNearbyShare:
case HoldingSpaceItem::Type::kPinnedFile: case HoldingSpaceItem::Type::kPinnedFile:
size = gfx::Size(kHoldingSpaceChipIconSize, kHoldingSpaceChipIconSize); size = gfx::Size(kHoldingSpaceChipIconSize, kHoldingSpaceChipIconSize);
break; break;
......
...@@ -35889,6 +35889,7 @@ Called by update_gpu_driver_bug_workaround_entries.py.--> ...@@ -35889,6 +35889,7 @@ Called by update_gpu_driver_bug_workaround_entries.py.-->
<int value="0" label="kPinnedFile"/> <int value="0" label="kPinnedFile"/>
<int value="1" label="kScreenshot"/> <int value="1" label="kScreenshot"/>
<int value="2" label="kDownload"/> <int value="2" label="kDownload"/>
<int value="3" label="kNearbyShare"/>
</enum> </enum>
<enum name="HoldingSpacePodAction"> <enum name="HoldingSpacePodAction">
...@@ -113,6 +113,7 @@ reviews. Googlers can read more about this at go/gwsq-gerrit. ...@@ -113,6 +113,7 @@ reviews. Googlers can read more about this at go/gwsq-gerrit.
<histogram_suffixes name="HoldingSpaceItemType" separator="."> <histogram_suffixes name="HoldingSpaceItemType" separator=".">
<suffix name="All" label="Includes all item types."/> <suffix name="All" label="Includes all item types."/>
<suffix name="Download" label="Items backed by a download file."/> <suffix name="Download" label="Items backed by a download file."/>
<suffix name="NearbyShare" label="Items backed by a nearby shared file."/>
<suffix name="PinnedFile" label="Items pinned explicitly by the user."/> <suffix name="PinnedFile" label="Items pinned explicitly by the user."/>
<suffix name="Screenshot" label="Items backed by a screenshot file."/> <suffix name="Screenshot" label="Items backed by a screenshot file."/>
<affected-histogram name="HoldingSpace.Item.Count"/> <affected-histogram name="HoldingSpace.Item.Count"/>
......
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