ozone: evdev: Sync caps lock LED state to evdev
[chromium-blink-merge.git] / chrome / browser / safe_browsing / incident_reporting / download_metadata_manager.h
blob54152845275ad4386ee34d26d522c6f258d4c663
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|. If
56 // |request| is null, metadata for the download's BrowserContext are cleared.
57 virtual void SetRequest(content::DownloadItem* download,
58 const ClientDownloadRequest* request);
60 // Gets the persisted DownloadDetails for |browser_context|. |callback| will
61 // be run immediately if the data is available. Otherwise, it will be run
62 // later on the caller's thread.
63 virtual void GetDownloadDetails(content::BrowserContext* browser_context,
64 const GetDownloadDetailsCallback& callback);
66 protected:
67 // Returns the DownloadManager for a given BrowserContext. Virtual for tests.
68 virtual content::DownloadManager* GetDownloadManagerForBrowserContext(
69 content::BrowserContext* context);
71 // content::DownloadManager:Observer methods.
72 void OnDownloadCreated(content::DownloadManager* download_manager,
73 content::DownloadItem* item) override;
74 void ManagerGoingDown(content::DownloadManager* download_manager) override;
76 private:
77 class ManagerContext;
79 // A mapping of DownloadManagers to their corresponding contexts.
80 typedef std::map<content::DownloadManager*, ManagerContext*>
81 ManagerToContextMap;
83 // A task runner to which read tasks are posted.
84 scoped_refptr<base::SequencedTaskRunner> read_runner_;
86 // A task runner to which write tasks are posted.
87 scoped_refptr<base::SequencedTaskRunner> write_runner_;
89 // Contexts for each DownloadManager that has been added and has not yet
90 // "gone down".
91 ManagerToContextMap contexts_;
93 DISALLOW_COPY_AND_ASSIGN(DownloadMetadataManager);
96 } // namespace safe_browsing
98 #endif // CHROME_BROWSER_SAFE_BROWSING_INCIDENT_REPORTING_DOWNLOAD_METADATA_MANAGER_H_