blob: b324b4df51a1f5b5395543d7518dcf216e701b36 [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"
9#include "chrome/browser/web_applications/web_app_id.h"
10
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,
22 const web_app::AppId& web_app_id);
23
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
31 const web_app::AppId& id() const { return web_app_id_; }
32
33 private:
34 static const char kKey[];
35
Lily Chen5c4f0ec2023-05-18 14:51:4436 explicit DownloadItemWebAppData(const web_app::AppId& web_app_id);
37
Lily Chen5598dea2023-04-25 22:11:0238 web_app::AppId web_app_id_;
39};
40
41#endif // __CHROMIUM_SRC_CHROME_BROWSER_DOWNLOAD_DOWNLOAD_ITEM_WEB_APP_DATA_H_