OLD | NEW |
---|---|
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "components/subresource_filter/content/browser/async_document_subresour ce_filter.h" | 5 #include "components/subresource_filter/content/browser/async_document_subresour ce_filter.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
51 // AsyncDocumentSubresourceFilter ---------------------------------------------- | 51 // AsyncDocumentSubresourceFilter ---------------------------------------------- |
52 | 52 |
53 AsyncDocumentSubresourceFilter::AsyncDocumentSubresourceFilter( | 53 AsyncDocumentSubresourceFilter::AsyncDocumentSubresourceFilter( |
54 VerifiedRuleset::Handle* ruleset_handle, | 54 VerifiedRuleset::Handle* ruleset_handle, |
55 InitializationParams params, | 55 InitializationParams params, |
56 base::Callback<void(ActivationState)> activation_state_callback, | 56 base::Callback<void(ActivationState)> activation_state_callback, |
57 base::OnceClosure first_disallowed_load_callback) | 57 base::OnceClosure first_disallowed_load_callback) |
58 : task_runner_(ruleset_handle->task_runner()), | 58 : task_runner_(ruleset_handle->task_runner()), |
59 core_(new Core(), base::OnTaskRunnerDeleter(task_runner_)), | 59 core_(new Core(), base::OnTaskRunnerDeleter(task_runner_)), |
60 first_disallowed_load_callback_( | 60 first_disallowed_load_callback_( |
61 std::move(first_disallowed_load_callback)) { | 61 std::move(first_disallowed_load_callback)), |
62 weak_ptr_factory_(this) { | |
62 DCHECK_NE(ActivationLevel::DISABLED, | 63 DCHECK_NE(ActivationLevel::DISABLED, |
63 params.parent_activation_state.activation_level); | 64 params.parent_activation_state.activation_level); |
64 | 65 |
65 // Note: It is safe to post |ruleset_handle|'s VerifiedRuleset pointer, | 66 // Note: It is safe to post |ruleset_handle|'s VerifiedRuleset pointer, |
66 // because a task to delete it can only be posted to (and, therefore, | 67 // because a task to delete it can only be posted to (and, therefore, |
67 // processed by) |task_runner| after this method returns, hence after the | 68 // processed by) |task_runner| after this method returns, hence after the |
68 // below task is posted. | 69 // below task is posted. |
69 base::PostTaskAndReplyWithResult( | 70 base::PostTaskAndReplyWithResult( |
70 task_runner_, FROM_HERE, | 71 task_runner_, FROM_HERE, |
71 base::Bind(&Core::Initialize, base::Unretained(core_.get()), | 72 base::Bind(&Core::Initialize, base::Unretained(core_.get()), |
72 base::Passed(¶ms), ruleset_handle->ruleset_.get()), | 73 base::Passed(¶ms), ruleset_handle->ruleset_.get()), |
73 std::move(activation_state_callback)); | 74 base::Bind(&AsyncDocumentSubresourceFilter::OnActivateStateCalculated, |
75 weak_ptr_factory_.GetWeakPtr(), | |
76 std::move(activation_state_callback))); | |
74 } | 77 } |
75 | 78 |
76 AsyncDocumentSubresourceFilter::~AsyncDocumentSubresourceFilter() { | 79 AsyncDocumentSubresourceFilter::~AsyncDocumentSubresourceFilter() { |
77 DCHECK(thread_checker_.CalledOnValidThread()); | 80 DCHECK(thread_checker_.CalledOnValidThread()); |
78 } | 81 } |
79 | 82 |
83 void AsyncDocumentSubresourceFilter::OnActivateStateCalculated( | |
84 base::Callback<void(ActivationState)> activation_state_callback, | |
85 ActivationState activation_state) { | |
86 activation_state_.emplace(activation_state); | |
engedy
2017/03/10 17:36:20
nit: Looks like this is equivalent to:
activation
Charlie Harrison
2017/03/14 23:18:31
Done.
| |
87 activation_state_callback.Run(activation_state); | |
88 } | |
89 | |
80 void AsyncDocumentSubresourceFilter::GetLoadPolicyForSubdocument( | 90 void AsyncDocumentSubresourceFilter::GetLoadPolicyForSubdocument( |
81 const GURL& subdocument_url, | 91 const GURL& subdocument_url, |
82 LoadPolicyCallback result_callback) { | 92 LoadPolicyCallback result_callback) { |
83 DCHECK(thread_checker_.CalledOnValidThread()); | 93 DCHECK(thread_checker_.CalledOnValidThread()); |
84 | 94 |
85 // TODO(pkalinnikov): Think about avoiding copy of |subdocument_url| if it is | 95 // TODO(pkalinnikov): Think about avoiding copy of |subdocument_url| if it is |
86 // too big and won't be allowed anyway (e.g., it's a data: URI). | 96 // too big and won't be allowed anyway (e.g., it's a data: URI). |
87 base::PostTaskAndReplyWithResult( | 97 base::PostTaskAndReplyWithResult( |
88 task_runner_, FROM_HERE, | 98 task_runner_, FROM_HERE, |
89 base::Bind( | 99 base::Bind( |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
129 params.parent_activation_state, verified_ruleset->Get()); | 139 params.parent_activation_state, verified_ruleset->Get()); |
130 | 140 |
131 DCHECK_NE(ActivationLevel::DISABLED, activation_state.activation_level); | 141 DCHECK_NE(ActivationLevel::DISABLED, activation_state.activation_level); |
132 filter_.emplace(url::Origin(params.document_url), activation_state, | 142 filter_.emplace(url::Origin(params.document_url), activation_state, |
133 verified_ruleset->Get()); | 143 verified_ruleset->Get()); |
134 | 144 |
135 return activation_state; | 145 return activation_state; |
136 } | 146 } |
137 | 147 |
138 } // namespace subresource_filter | 148 } // namespace subresource_filter |
OLD | NEW |