gn format //chrome
[chromium-blink-merge.git] / extensions / browser / content_verifier.h
blob47f67c1411be6c1770eac92098a63b417af67dda
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 EXTENSIONS_BROWSER_CONTENT_VERIFIER_H_
6 #define EXTENSIONS_BROWSER_CONTENT_VERIFIER_H_
8 #include <set>
9 #include <string>
11 #include "base/macros.h"
12 #include "base/memory/ref_counted.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"
17 #include "extensions/browser/content_verify_job.h"
18 #include "extensions/browser/extension_registry_observer.h"
20 namespace base {
21 class FilePath;
24 namespace content {
25 class BrowserContext;
28 namespace extensions {
30 class Extension;
31 class ContentHashFetcher;
32 class ContentVerifierIOData;
34 // Used for managing overall content verification - both fetching content
35 // hashes as needed, and supplying job objects to verify file contents as they
36 // are read.
37 class ContentVerifier : public base::RefCountedThreadSafe<ContentVerifier>,
38 public ExtensionRegistryObserver {
39 public:
40 // Takes ownership of |delegate|.
41 ContentVerifier(content::BrowserContext* context,
42 ContentVerifierDelegate* delegate);
43 void Start();
44 void Shutdown();
46 // Call this before reading a file within an extension. The caller owns the
47 // returned job.
48 ContentVerifyJob* CreateJobFor(const std::string& extension_id,
49 const base::FilePath& extension_root,
50 const base::FilePath& relative_path);
52 // Called (typically by a verification job) to indicate that verification
53 // failed while reading some file in |extension_id|.
54 void VerifyFailed(const std::string& extension_id,
55 ContentVerifyJob::FailureReason reason);
57 // ExtensionRegistryObserver interface
58 void OnExtensionLoaded(content::BrowserContext* browser_context,
59 const Extension* extension) override;
60 void OnExtensionUnloaded(content::BrowserContext* browser_context,
61 const Extension* extension,
62 UnloadedExtensionInfo::Reason reason) override;
64 private:
65 DISALLOW_COPY_AND_ASSIGN(ContentVerifier);
67 friend class base::RefCountedThreadSafe<ContentVerifier>;
68 ~ContentVerifier() override;
70 void OnFetchComplete(const std::string& extension_id,
71 bool success,
72 bool was_force_check,
73 const std::set<base::FilePath>& hash_mismatch_paths);
75 void OnFetchCompleteHelper(const std::string& extension_id,
76 bool shouldVerifyAnyPathsResult);
78 // Returns true if any of the paths in |relative_paths| *should* have their
79 // contents verified. (Some files get transcoded during the install process,
80 // so we don't want to verify their contents because they are expected not
81 // to match).
82 bool ShouldVerifyAnyPaths(const std::string& extension_id,
83 const base::FilePath& extension_root,
84 const std::set<base::FilePath>& relative_paths);
86 // Set to true once we've begun shutting down.
87 bool shutdown_;
89 content::BrowserContext* context_;
91 scoped_ptr<ContentVerifierDelegate> delegate_;
93 // For fetching content hash signatures.
94 scoped_ptr<ContentHashFetcher> fetcher_;
96 // For observing the ExtensionRegistry.
97 ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver> observer_;
99 // Data that should only be used on the IO thread.
100 scoped_refptr<ContentVerifierIOData> io_data_;
103 } // namespace extensions
105 #endif // EXTENSIONS_BROWSER_CONTENT_VERIFIER_H_