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

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

Issue 266963003: Beginning of support for extension content verification (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: responded to review comments 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_VERIFY_JOB_H_
6 #define EXTENSIONS_BROWSER_CONTENT_VERIFY_JOB_H_
7
8 #include <string>
9
10 #include "base/callback.h"
11 #include "base/memory/ref_counted.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "base/threading/thread_checker.h"
14
15 namespace base {
16 class FilePath;
17 }
18
19 namespace extensions {
20
21 class ContentHashReader;
22
23 // Objects of this class are responsible for verifying that the actual content
24 // read from an extension file matches an expected set of hashes. This class
25 // can be created on any thread but the rest of the methods should be called
26 // from only one thread.
27 class ContentVerifyJob : public base::RefCountedThreadSafe<ContentVerifyJob> {
28 public:
29 enum FailureReason {
30 // No failure.
31 NONE,
32
33 // Failed because there were no expected hashes.
34 NO_HASHES,
35
36 // Some of the content read did not match the expected hash.
37 HASH_MISMATCH
38 };
39 typedef base::Callback<void(FailureReason)> FailureCallback;
40
41 // The |failure_callback| will be called at most once if there was a failure.
42 //
43 // IMPORTANT NOTE: this class is still a stub right now - in the future this
44 // constructor will also be passed information to let it lookup expected
45 // block hashes for the file being read.
46 ContentVerifyJob(const std::string& extension_id,
47 const FailureCallback& failure_callback);
48
49 // This begins the process of getting expected hashes, so it should be called
50 // as early as possible.
51 void Start();
52
53 // Call this to add more bytes to verify. If at any point the read bytes
54 // don't match the expected hashes, this will dispatch the failure
55 // callback. The failure callback will only be run once even if more bytes
56 // are read. Make sure to call DoneReading so that any final bytes that were
57 // read that didn't align exactly on a block size boundary get their hash
58 // checked as well.
59 void BytesRead(int count, const char* data);
60
61 // Call once when finished adding bytes via BytesRead.
62 void DoneReading();
63
64 class TestDelegate {
65 public:
66 // These methods will be called inside BytesRead/DoneReading respectively.
67 // If either return something other than NONE, then the failure callback
68 // will be dispatched with that reason.
69 virtual FailureReason BytesRead(const std::string& extension_id,
70 int count,
71 const char* data) = 0;
72 virtual FailureReason DoneReading(const std::string& extension_id) = 0;
73 };
74
75 static void SetDelegateForTests(TestDelegate* delegate);
76
77 private:
78 DISALLOW_COPY_AND_ASSIGN(ContentVerifyJob);
79
80 virtual ~ContentVerifyJob();
81 friend class base::RefCountedThreadSafe<ContentVerifyJob>;
82
83 void DispatchFailureCallback(FailureReason reason);
84
85 // The id of the extension for the file being verified.
86 std::string extension_id_;
87
88 // Called once if verification fails.
89 FailureCallback failure_callback_;
90
91 // For ensuring methods on called on the right thread.
92 base::ThreadChecker thread_checker_;
93 };
94
95 } // namespace extensions
96
97 #endif // EXTENSIONS_BROWSER_CONTENT_VERIFY_JOB_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698