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

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

Powered by Google App Engine
This is Rietveld 408576698