[email protected] | 6a5898e | 2014-07-22 23:33:54 | [diff] [blame] | 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. | ||||
4 | |||||
5 | #ifndef EXTENSIONS_BROWSER_CONTENT_VERIFIER_IO_DATA_H_ | ||||
6 | #define EXTENSIONS_BROWSER_CONTENT_VERIFIER_IO_DATA_H_ | ||||
7 | |||||
8 | #include <map> | ||||
dcheng | f5d24108 | 2016-04-21 03:43:11 | [diff] [blame] | 9 | #include <memory> |
[email protected] | 6a5898e | 2014-07-22 23:33:54 | [diff] [blame] | 10 | #include <set> |
11 | #include <string> | ||||
12 | |||||
13 | #include "base/files/file_path.h" | ||||
[email protected] | 6a5898e | 2014-07-22 23:33:54 | [diff] [blame] | 14 | #include "base/memory/ref_counted.h" |
[email protected] | 6a5898e | 2014-07-22 23:33:54 | [diff] [blame] | 15 | #include "base/version.h" |
Istiaque Ahmed | 0f709d22 | 2020-02-26 22:25:57 | [diff] [blame] | 16 | #include "extensions/browser/content_verifier/content_verifier_utils.h" |
Oleg Davydov | 39d1548 | 2019-11-05 20:19:06 | [diff] [blame] | 17 | #include "extensions/browser/content_verifier_delegate.h" |
[email protected] | 6a5898e | 2014-07-22 23:33:54 | [diff] [blame] | 18 | |
19 | namespace extensions { | ||||
20 | |||||
Istiaque Ahmed | 0f709d22 | 2020-02-26 22:25:57 | [diff] [blame] | 21 | using CanonicalRelativePath = content_verifier_utils::CanonicalRelativePath; |
22 | |||||
[email protected] | 6a5898e | 2014-07-22 23:33:54 | [diff] [blame] | 23 | // A helper class for keeping track of data for the ContentVerifier that should |
24 | // only be accessed on the IO thread. | ||||
Istiaque Ahmed | e83ff28f | 2019-07-02 22:48:47 | [diff] [blame] | 25 | class ContentVerifierIOData { |
[email protected] | 6a5898e | 2014-07-22 23:33:54 | [diff] [blame] | 26 | public: |
27 | struct ExtensionData { | ||||
Istiaque Ahmed | 0f709d22 | 2020-02-26 22:25:57 | [diff] [blame] | 28 | // Set of canonical file paths used as images within the browser process. |
29 | std::unique_ptr<std::set<CanonicalRelativePath>> | ||||
30 | canonical_browser_image_paths; | ||||
31 | // Set of canonical file paths used as background scripts, pages or | ||||
32 | // content scripts. | ||||
33 | std::unique_ptr<std::set<CanonicalRelativePath>> | ||||
34 | canonical_background_or_content_paths; | ||||
Karandeep Bhatia | 28cf935c | 2020-03-19 05:14:42 | [diff] [blame] | 35 | |
36 | // Set of indexed ruleset paths used by the Declarative Net Request API. | ||||
37 | std::unique_ptr<std::set<CanonicalRelativePath>> | ||||
38 | canonical_indexed_ruleset_paths; | ||||
39 | |||||
[email protected] | 6a5898e | 2014-07-22 23:33:54 | [diff] [blame] | 40 | base::Version version; |
Oleg Davydov | 39d1548 | 2019-11-05 20:19:06 | [diff] [blame] | 41 | ContentVerifierDelegate::VerifierSourceType source_type; |
[email protected] | 6a5898e | 2014-07-22 23:33:54 | [diff] [blame] | 42 | |
Istiaque Ahmed | 0f709d22 | 2020-02-26 22:25:57 | [diff] [blame] | 43 | ExtensionData(std::unique_ptr<std::set<CanonicalRelativePath>> |
44 | canonical_browser_image_paths, | ||||
45 | std::unique_ptr<std::set<CanonicalRelativePath>> | ||||
46 | canonical_background_or_content_paths, | ||||
Karandeep Bhatia | 28cf935c | 2020-03-19 05:14:42 | [diff] [blame] | 47 | std::unique_ptr<std::set<CanonicalRelativePath>> |
48 | canonical_indexed_ruleset_paths, | ||||
Istiaque Ahmed | 0f709d22 | 2020-02-26 22:25:57 | [diff] [blame] | 49 | const base::Version& version, |
50 | ContentVerifierDelegate::VerifierSourceType source_type); | ||||
[email protected] | 6a5898e | 2014-07-22 23:33:54 | [diff] [blame] | 51 | ~ExtensionData(); |
52 | }; | ||||
53 | |||||
54 | ContentVerifierIOData(); | ||||
Istiaque Ahmed | e83ff28f | 2019-07-02 22:48:47 | [diff] [blame] | 55 | ~ContentVerifierIOData(); |
[email protected] | 6a5898e | 2014-07-22 23:33:54 | [diff] [blame] | 56 | |
dcheng | f5d24108 | 2016-04-21 03:43:11 | [diff] [blame] | 57 | void AddData(const std::string& extension_id, |
58 | std::unique_ptr<ExtensionData> data); | ||||
[email protected] | 6a5898e | 2014-07-22 23:33:54 | [diff] [blame] | 59 | void RemoveData(const std::string& extension_id); |
60 | void Clear(); | ||||
61 | |||||
62 | // This should be called on the IO thread, and the return value should not | ||||
63 | // be retained or used on other threads. | ||||
64 | const ExtensionData* GetData(const std::string& extension_id); | ||||
65 | |||||
Istiaque Ahmed | e83ff28f | 2019-07-02 22:48:47 | [diff] [blame] | 66 | private: |
lazyboy | f33109d | 2016-08-31 00:37:08 | [diff] [blame] | 67 | std::map<std::string, std::unique_ptr<ExtensionData>> data_map_; |
Istiaque Ahmed | e83ff28f | 2019-07-02 22:48:47 | [diff] [blame] | 68 | |
69 | DISALLOW_COPY_AND_ASSIGN(ContentVerifierIOData); | ||||
[email protected] | 6a5898e | 2014-07-22 23:33:54 | [diff] [blame] | 70 | }; |
71 | |||||
72 | } // namespace extensions | ||||
73 | |||||
74 | #endif // EXTENSIONS_BROWSER_CONTENT_VERIFIER_IO_DATA_H_ |