blob: 5521e9f6631f5bcb93ccd170f2bf503432c58fc8 [file] [log] [blame]
Lily Chen5598dea2023-04-25 22:11:021// Copyright 2023 The Chromium Authors
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef CHROME_BROWSER_DOWNLOAD_DOWNLOAD_ITEM_WEB_APP_DATA_H_
6#define CHROME_BROWSER_DOWNLOAD_DOWNLOAD_ITEM_WEB_APP_DATA_H_
7
8#include "base/supports_user_data.h"
Glenn Hartmann06fa9d62023-09-26 17:26:219#include "components/webapps/common/web_app_id.h"
Lily Chen5598dea2023-04-25 22:11:0210
11namespace download {
12class DownloadItem;
13}
14
15// Per DownloadItem data for storing web app data on downloads. This data is
16// only set if a download was initiated by a web app.
17class DownloadItemWebAppData : public base::SupportsUserData::Data {
18 public:
Lily Chen5c4f0ec2023-05-18 14:51:4419 // Creates an instance with the given `web_app_id` and attaches it to the
20 // item. Overwrites any existing DownloadItemWebAppData on the item.
21 static void CreateAndAttachToItem(download::DownloadItem* item,
Glenn Hartmann06fa9d62023-09-26 17:26:2122 const webapps::AppId& web_app_id);
Lily Chen5c4f0ec2023-05-18 14:51:4423
Lily Chen5598dea2023-04-25 22:11:0224 // Returns nullptr if no DownloadItemWebAppData is present, which will be the
25 // case for most downloads (i.e. those not initiated by web apps).
26 static DownloadItemWebAppData* Get(download::DownloadItem* item);
27
Lily Chen5598dea2023-04-25 22:11:0228 DownloadItemWebAppData(const DownloadItemWebAppData&) = delete;
29 DownloadItemWebAppData& operator=(const DownloadItemWebAppData&) = delete;
30
Glenn Hartmann06fa9d62023-09-26 17:26:2131 const webapps::AppId& id() const { return web_app_id_; }
Lily Chen5598dea2023-04-25 22:11:0232
33 private:
34 static const char kKey[];
35
Glenn Hartmann06fa9d62023-09-26 17:26:2136 explicit DownloadItemWebAppData(const webapps::AppId& web_app_id);
Lily Chen5c4f0ec2023-05-18 14:51:4437
Glenn Hartmann06fa9d62023-09-26 17:26:2138 webapps::AppId web_app_id_;
Lily Chen5598dea2023-04-25 22:11:0239};
40
shaochenguang77a7a02b2023-11-22 19:33:5641#endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_ITEM_WEB_APP_DATA_H_