Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(31)

Side by Side Diff: extensions/browser/content_verifier.h

Issue 266963003: Beginning of support for extension content verification (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: merged latest trunk Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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_H_
6 #define EXTENSIONS_BROWSER_CONTENT_VERIFIER_H_
7
8 #include "base/macros.h"
9 #include "base/memory/ref_counted.h"
10 #include "base/observer_list_threadsafe.h"
11 #include "extensions/browser/content_verifier_filter.h"
12 #include "extensions/browser/content_verify_job.h"
13
14 namespace base {
15 class FilePath;
16 }
17
18 namespace content {
19 class BrowserContext;
20 }
21
22 namespace extensions {
23
24 // Interface for clients of ContentVerifier.
25 class ContentVerifierObserver {
26 public:
27 // Called when the content verifier detects that a read of a file inside
28 // an extension did not match its expected hash.
29 virtual void ContentVerifyFailed(const std::string& extension_id) = 0;
30 };
31
32 // Used for managing overall content verification - both fetching content
33 // hashes as needed, and supplying job objects to verify file contents as they
34 // are read.
35 class ContentVerifier : public base::RefCountedThreadSafe<ContentVerifier> {
36 public:
37 ContentVerifier(content::BrowserContext* context,
38 const ContentVerifierFilter& filter);
39 void Start();
40 void Shutdown();
41
42 // Call this before reading a file within an extension. The caller owns the
43 // returned job.
44 ContentVerifyJob* CreateJobFor(const std::string& extension_id,
45 const base::FilePath& extension_root,
46 const base::FilePath& relative_path);
47
48 // Called (typically by a verification job) to indicate that verification
49 // failed while reading some file in |extension_id|.
50 void VerifyFailed(const std::string& extension_id,
51 ContentVerifyJob::FailureReason reason);
52
53 // Observers will be called back on the same thread that they call
54 // AddObserver on.
55 void AddObserver(ContentVerifierObserver* observer);
56 void RemoveObserver(ContentVerifierObserver* observer);
57
58 private:
59 DISALLOW_COPY_AND_ASSIGN(ContentVerifier);
60
61 friend class base::RefCountedThreadSafe<ContentVerifier>;
62 virtual ~ContentVerifier();
63
64 // Attempts to fetch content hashes for |extension_id|.
65 void RequestFetch(const std::string& extension_id);
66
67 // Note that it is important for these to appear in increasing "severity"
68 // order, because we use this to let command line flags increase, but not
69 // decrease, the mode you're running in compared to the experiment group.
70 enum Mode {
71 // Do not try to fetch content hashes if they are missing, and do not
72 // enforce them if they are present.
73 NONE = 0,
74
75 // If content hashes are missing, try to fetch them, but do not enforce.
76 BOOTSTRAP,
77
78 // If hashes are present, enforce them. If they are missing, try to fetch
79 // them.
80 ENFORCE,
81
82 // Treat the absence of hashes the same as a verification failure.
83 ENFORCE_STRICT
84 };
85
86 static Mode GetMode();
87
88 // The mode we're running in - set once at creation.
89 const Mode mode_;
90
91 // The filter we use to decide whether to return a ContentVerifyJob.
92 ContentVerifierFilter filter_;
93
94 // The associated BrowserContext.
95 content::BrowserContext* context_;
96
97 // The set of objects interested in verification failures.
98 scoped_refptr<ObserverListThreadSafe<ContentVerifierObserver> > observers_;
99 };
100
101 } // namespace extensions
102
103 #endif // EXTENSIONS_BROWSER_CONTENT_VERIFIER_H_
OLDNEW
« no previous file with comments | « chrome/test/data/extensions/content_verifier/v1/page.html ('k') | extensions/browser/content_verifier.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698