Remove aura enum from DesktopMediaID to fix desktop mirroring audio (CrOS).
[chromium-blink-merge.git] / chrome / browser / safe_browsing / incident_reporting / download_metadata_manager.h
blob60fc625c4ca2bda01d6321c22f28dfb2adb698be
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_SAFE_BROWSING_INCIDENT_REPORTING_DOWNLOAD_METADATA_MANAGER_H_
6 #define CHROME_BROWSER_SAFE_BROWSING_INCIDENT_REPORTING_DOWNLOAD_METADATA_MANAGER_H_
8 #include <map>
10 #include "base/callback_forward.h"
11 #include "base/macros.h"
12 #include "base/memory/ref_counted.h"
13 #include "content/public/browser/download_manager.h"
15 namespace base {
16 class SequencedTaskRunner;
17 class SequencedWorkerPool;
20 namespace content {
21 class BrowserContext;
22 class DownloadItem;
25 namespace safe_browsing {
27 class ClientDownloadRequest;
28 class ClientIncidentReport_DownloadDetails;
29 class DownloadMetadata;
31 // A browser-wide object that manages the persistent state of metadata
32 // pertaining to a download.
33 class DownloadMetadataManager : public content::DownloadManager::Observer {
34 public:
35 // A callback run when the results of a call to GetDownloadDetails are ready.
36 // The supplied parameter may be null, indicating that there are no persisted
37 // details for the |browser_context| passed to GetDownloadDetails.
38 typedef base::Callback<void(scoped_ptr<ClientIncidentReport_DownloadDetails>)>
39 GetDownloadDetailsCallback;
41 // Constructs a new instance for which disk IO operations will take place in
42 // |worker_pool|.
43 explicit DownloadMetadataManager(
44 const scoped_refptr<base::SequencedWorkerPool>& worker_pool);
46 // Constructor that allows tests to provide a specific runner for
47 // asynchronous tasks.
48 explicit DownloadMetadataManager(
49 const scoped_refptr<base::SequencedTaskRunner>& task_runner);
50 ~DownloadMetadataManager() override;
52 // Adds |download_manager| to the set observed by the metadata manager.
53 void AddDownloadManager(content::DownloadManager* download_manager);
55 // Sets |request| as the relevant metadata to persist for |download| upon
56 // completion. If |request| is null, metadata for the download's
57 // BrowserContext are cleared. Otherwise, |request| will be persisted when the
58 // download completes, or discarded if the download is cancelled.
59 virtual void SetRequest(content::DownloadItem* download,
60 const ClientDownloadRequest* request);
62 // Gets the persisted DownloadDetails for |browser_context|. |callback| will
63 // be run immediately if the data is available. Otherwise, it will be run
64 // later on the caller's thread.
65 virtual void GetDownloadDetails(content::BrowserContext* browser_context,
66 const GetDownloadDetailsCallback& callback);
68 protected:
69 // Returns the DownloadManager for a given BrowserContext. Virtual for tests.
70 virtual content::DownloadManager* GetDownloadManagerForBrowserContext(
71 content::BrowserContext* context);
73 // content::DownloadManager:Observer methods.
74 void OnDownloadCreated(content::DownloadManager* download_manager,
75 content::DownloadItem* item) override;
76 void ManagerGoingDown(content::DownloadManager* download_manager) override;
78 private:
79 class ManagerContext;
81 // A mapping of DownloadManagers to their corresponding contexts.
82 typedef std::map<content::DownloadManager*, ManagerContext*>
83 ManagerToContextMap;
85 // A task runner to which read tasks are posted.
86 scoped_refptr<base::SequencedTaskRunner> read_runner_;
88 // A task runner to which write tasks are posted.
89 scoped_refptr<base::SequencedTaskRunner> write_runner_;
91 // Contexts for each DownloadManager that has been added and has not yet
92 // "gone down".
93 ManagerToContextMap contexts_;
95 DISALLOW_COPY_AND_ASSIGN(DownloadMetadataManager);
98 } // namespace safe_browsing
100 #endif // CHROME_BROWSER_SAFE_BROWSING_INCIDENT_REPORTING_DOWNLOAD_METADATA_MANAGER_H_