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 virtual void OnExtensionLoaded(content::BrowserContext
* browser_context
,
59 const Extension
* extension
) OVERRIDE
;
60 virtual void OnExtensionUnloaded(
61 content::BrowserContext
* browser_context
,
62 const Extension
* extension
,
63 UnloadedExtensionInfo::Reason reason
) OVERRIDE
;
66 DISALLOW_COPY_AND_ASSIGN(ContentVerifier
);
68 friend class base::RefCountedThreadSafe
<ContentVerifier
>;
69 virtual ~ContentVerifier();
71 void OnFetchComplete(const std::string
& extension_id
,
74 const std::set
<base::FilePath
>& hash_mismatch_paths
);
76 void OnFetchCompleteHelper(const std::string
& extension_id
,
77 bool shouldVerifyAnyPathsResult
);
79 // Returns true if any of the paths in |relative_paths| *should* have their
80 // contents verified. (Some files get transcoded during the install process,
81 // so we don't want to verify their contents because they are expected not
83 bool ShouldVerifyAnyPaths(const std::string
& extension_id
,
84 const base::FilePath
& extension_root
,
85 const std::set
<base::FilePath
>& relative_paths
);
87 // Set to true once we've begun shutting down.
90 content::BrowserContext
* context_
;
92 scoped_ptr
<ContentVerifierDelegate
> delegate_
;
94 // For fetching content hash signatures.
95 scoped_ptr
<ContentHashFetcher
> fetcher_
;
97 // For observing the ExtensionRegistry.
98 ScopedObserver
<ExtensionRegistry
, ExtensionRegistryObserver
> observer_
;
100 // Data that should only be used on the IO thread.
101 scoped_refptr
<ContentVerifierIOData
> io_data_
;
104 } // namespace extensions
106 #endif // EXTENSIONS_BROWSER_CONTENT_VERIFIER_H_