OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef EXTENSIONS_BROWSER_CONTENT_VERIFIER_H_ | 5 #ifndef EXTENSIONS_BROWSER_CONTENT_VERIFIER_H_ |
6 #define EXTENSIONS_BROWSER_CONTENT_VERIFIER_H_ | 6 #define EXTENSIONS_BROWSER_CONTENT_VERIFIER_H_ |
7 | 7 |
8 #include <set> | 8 #include <set> |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "base/macros.h" | 11 #include "base/macros.h" |
12 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
| 14 #include "base/scoped_observer.h" |
| 15 #include "base/version.h" |
| 16 #include "extensions/browser/content_verifier_delegate.h" |
14 #include "extensions/browser/content_verify_job.h" | 17 #include "extensions/browser/content_verify_job.h" |
| 18 #include "extensions/browser/extension_registry_observer.h" |
15 | 19 |
16 namespace base { | 20 namespace base { |
17 class FilePath; | 21 class FilePath; |
18 } | 22 } |
19 | 23 |
20 namespace content { | 24 namespace content { |
21 class BrowserContext; | 25 class BrowserContext; |
22 } | 26 } |
23 | 27 |
24 namespace extensions { | 28 namespace extensions { |
25 | 29 |
26 class Extension; | 30 class Extension; |
27 class ContentHashFetcher; | 31 class ContentHashFetcher; |
28 class ContentVerifierDelegate; | 32 class ContentVerifierIOData; |
29 | 33 |
30 // Used for managing overall content verification - both fetching content | 34 // Used for managing overall content verification - both fetching content |
31 // hashes as needed, and supplying job objects to verify file contents as they | 35 // hashes as needed, and supplying job objects to verify file contents as they |
32 // are read. | 36 // are read. |
33 class ContentVerifier : public base::RefCountedThreadSafe<ContentVerifier> { | 37 class ContentVerifier : public base::RefCountedThreadSafe<ContentVerifier>, |
| 38 public ExtensionRegistryObserver { |
34 public: | 39 public: |
35 // Takes ownership of |delegate|. | 40 // Takes ownership of |delegate|. |
36 ContentVerifier(content::BrowserContext* context, | 41 ContentVerifier(content::BrowserContext* context, |
37 ContentVerifierDelegate* delegate); | 42 ContentVerifierDelegate* delegate); |
38 void Start(); | 43 void Start(); |
39 void Shutdown(); | 44 void Shutdown(); |
40 | 45 |
41 // Call this before reading a file within an extension. The caller owns the | 46 // Call this before reading a file within an extension. The caller owns the |
42 // returned job. | 47 // returned job. |
43 ContentVerifyJob* CreateJobFor(const std::string& extension_id, | 48 ContentVerifyJob* CreateJobFor(const std::string& extension_id, |
44 const base::FilePath& extension_root, | 49 const base::FilePath& extension_root, |
45 const base::FilePath& relative_path); | 50 const base::FilePath& relative_path); |
46 | 51 |
47 // Called (typically by a verification job) to indicate that verification | 52 // Called (typically by a verification job) to indicate that verification |
48 // failed while reading some file in |extension_id|. | 53 // failed while reading some file in |extension_id|. |
49 void VerifyFailed(const std::string& extension_id, | 54 void VerifyFailed(const std::string& extension_id, |
50 ContentVerifyJob::FailureReason reason); | 55 ContentVerifyJob::FailureReason reason); |
51 | 56 |
52 void OnFetchComplete(const std::string& extension_id, | 57 // ExtensionRegistryObserver interface |
53 bool success, | 58 virtual void OnExtensionLoaded(content::BrowserContext* browser_context, |
54 bool was_force_check, | 59 const Extension* extension) OVERRIDE; |
55 const std::set<base::FilePath>& hash_mismatch_paths); | 60 virtual void OnExtensionUnloaded( |
| 61 content::BrowserContext* browser_context, |
| 62 const Extension* extension, |
| 63 UnloadedExtensionInfo::Reason reason) OVERRIDE; |
56 | 64 |
57 private: | 65 private: |
58 DISALLOW_COPY_AND_ASSIGN(ContentVerifier); | 66 DISALLOW_COPY_AND_ASSIGN(ContentVerifier); |
59 | 67 |
60 friend class base::RefCountedThreadSafe<ContentVerifier>; | 68 friend class base::RefCountedThreadSafe<ContentVerifier>; |
61 virtual ~ContentVerifier(); | 69 virtual ~ContentVerifier(); |
62 | 70 |
| 71 void OnFetchComplete(const std::string& extension_id, |
| 72 bool success, |
| 73 bool was_force_check, |
| 74 const std::set<base::FilePath>& hash_mismatch_paths); |
| 75 |
| 76 void OnFetchCompleteHelper(const std::string& extension_id, |
| 77 bool shouldVerifyAnyPathsResult); |
| 78 |
63 // Returns true if any of the paths in |relative_paths| *should* have their | 79 // Returns true if any of the paths in |relative_paths| *should* have their |
64 // contents verified. (Some files get transcoded during the install process, | 80 // contents verified. (Some files get transcoded during the install process, |
65 // so we don't want to verify their contents because they are expected not | 81 // so we don't want to verify their contents because they are expected not |
66 // to match). | 82 // to match). |
67 bool ShouldVerifyAnyPaths(const Extension* extension, | 83 bool ShouldVerifyAnyPaths(const std::string& extension_id, |
| 84 const base::FilePath& extension_root, |
68 const std::set<base::FilePath>& relative_paths); | 85 const std::set<base::FilePath>& relative_paths); |
69 | 86 |
| 87 // Set to true once we've begun shutting down. |
| 88 bool shutdown_; |
| 89 |
70 content::BrowserContext* context_; | 90 content::BrowserContext* context_; |
71 | 91 |
72 scoped_ptr<ContentVerifierDelegate> delegate_; | 92 scoped_ptr<ContentVerifierDelegate> delegate_; |
73 | 93 |
74 // For fetching content hash signatures. | 94 // For fetching content hash signatures. |
75 scoped_ptr<ContentHashFetcher> fetcher_; | 95 scoped_ptr<ContentHashFetcher> fetcher_; |
| 96 |
| 97 // For observing the ExtensionRegistry. |
| 98 ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver> observer_; |
| 99 |
| 100 // Data that should only be used on the IO thread. |
| 101 scoped_refptr<ContentVerifierIOData> io_data_; |
76 }; | 102 }; |
77 | 103 |
78 } // namespace extensions | 104 } // namespace extensions |
79 | 105 |
80 #endif // EXTENSIONS_BROWSER_CONTENT_VERIFIER_H_ | 106 #endif // EXTENSIONS_BROWSER_CONTENT_VERIFIER_H_ |
OLD | NEW |