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_
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"
28 namespace extensions
{
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
37 class ContentVerifier
: public base::RefCountedThreadSafe
<ContentVerifier
>,
38 public ExtensionRegistryObserver
{
40 // Takes ownership of |delegate|.
41 ContentVerifier(content::BrowserContext
* context
,
42 ContentVerifierDelegate
* delegate
);
46 // Call this before reading a file within an extension. The caller owns the
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
;
65 DISALLOW_COPY_AND_ASSIGN(ContentVerifier
);
67 friend class base::RefCountedThreadSafe
<ContentVerifier
>;
68 ~ContentVerifier() override
;
70 void OnFetchComplete(const std::string
& extension_id
,
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
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.
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_