OLD | NEW |
(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 #include "extensions/browser/content_verify_job.h" |
| 6 |
| 7 #include <algorithm> |
| 8 |
| 9 #include "base/stl_util.h" |
| 10 #include "base/task_runner_util.h" |
| 11 #include "content/public/browser/browser_thread.h" |
| 12 |
| 13 namespace extensions { |
| 14 |
| 15 namespace { |
| 16 |
| 17 ContentVerifyJob::TestDelegate* g_test_delegate = NULL; |
| 18 |
| 19 } // namespace |
| 20 |
| 21 ContentVerifyJob::ContentVerifyJob(const std::string& extension_id, |
| 22 const FailureCallback& failure_callback) |
| 23 : extension_id_(extension_id), failure_callback_(failure_callback) { |
| 24 // It's ok for this object to be constructed on a different thread from where |
| 25 // it's used. |
| 26 thread_checker_.DetachFromThread(); |
| 27 } |
| 28 |
| 29 ContentVerifyJob::~ContentVerifyJob() { |
| 30 } |
| 31 |
| 32 void ContentVerifyJob::Start() { |
| 33 DCHECK(thread_checker_.CalledOnValidThread()); |
| 34 } |
| 35 |
| 36 void ContentVerifyJob::BytesRead(int count, const char* data) { |
| 37 DCHECK(thread_checker_.CalledOnValidThread()); |
| 38 if (g_test_delegate) { |
| 39 FailureReason reason = |
| 40 g_test_delegate->BytesRead(extension_id_, count, data); |
| 41 if (reason != NONE) |
| 42 return DispatchFailureCallback(reason); |
| 43 } |
| 44 } |
| 45 |
| 46 void ContentVerifyJob::DoneReading() { |
| 47 DCHECK(thread_checker_.CalledOnValidThread()); |
| 48 if (g_test_delegate) { |
| 49 FailureReason reason = g_test_delegate->DoneReading(extension_id_); |
| 50 if (reason != NONE) { |
| 51 DispatchFailureCallback(reason); |
| 52 return; |
| 53 } |
| 54 } |
| 55 } |
| 56 |
| 57 // static |
| 58 void ContentVerifyJob::SetDelegateForTests(TestDelegate* delegate) { |
| 59 g_test_delegate = delegate; |
| 60 } |
| 61 |
| 62 void ContentVerifyJob::DispatchFailureCallback(FailureReason reason) { |
| 63 if (!failure_callback_.is_null()) { |
| 64 failure_callback_.Run(reason); |
| 65 failure_callback_.Reset(); |
| 66 } |
| 67 } |
| 68 |
| 69 } // namespace extensions |
OLD | NEW |