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

Side by Side Diff: components/subresource_filter/content/browser/async_document_subresource_filter.cc

Issue 2691423006: Introduce the ThrottleManager (Closed)
Patch Set: engedy review Created 3 years, 9 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
OLDNEW
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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 InitializationParams::~InitializationParams() = default; 46 InitializationParams::~InitializationParams() = default;
47 InitializationParams::InitializationParams(InitializationParams&&) = default; 47 InitializationParams::InitializationParams(InitializationParams&&) = default;
48 InitializationParams& InitializationParams::operator=(InitializationParams&&) = 48 InitializationParams& InitializationParams::operator=(InitializationParams&&) =
49 default; 49 default;
50 50
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)
58 : task_runner_(ruleset_handle->task_runner()), 57 : task_runner_(ruleset_handle->task_runner()),
59 core_(new Core(), base::OnTaskRunnerDeleter(task_runner_)), 58 core_(new Core(), base::OnTaskRunnerDeleter(task_runner_)),
60 first_disallowed_load_callback_( 59 weak_ptr_factory_(this) {
61 std::move(first_disallowed_load_callback)) {
62 DCHECK_NE(ActivationLevel::DISABLED, 60 DCHECK_NE(ActivationLevel::DISABLED,
63 params.parent_activation_state.activation_level); 61 params.parent_activation_state.activation_level);
64 62
65 // Note: It is safe to post |ruleset_handle|'s VerifiedRuleset pointer, 63 // 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, 64 // 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 65 // processed by) |task_runner| after this method returns, hence after the
68 // below task is posted. 66 // below task is posted.
69 base::PostTaskAndReplyWithResult( 67 base::PostTaskAndReplyWithResult(
70 task_runner_, FROM_HERE, 68 task_runner_, FROM_HERE,
71 base::Bind(&Core::Initialize, base::Unretained(core_.get()), 69 base::Bind(&Core::Initialize, base::Unretained(core_.get()),
72 base::Passed(&params), ruleset_handle->ruleset_.get()), 70 base::Passed(&params), ruleset_handle->ruleset_.get()),
73 std::move(activation_state_callback)); 71 base::Bind(&AsyncDocumentSubresourceFilter::OnActivateStateCalculated,
72 weak_ptr_factory_.GetWeakPtr(),
73 std::move(activation_state_callback)));
74 } 74 }
75 75
76 AsyncDocumentSubresourceFilter::~AsyncDocumentSubresourceFilter() { 76 AsyncDocumentSubresourceFilter::~AsyncDocumentSubresourceFilter() {
77 DCHECK(thread_checker_.CalledOnValidThread()); 77 DCHECK(thread_checker_.CalledOnValidThread());
78 } 78 }
79 79
80 void AsyncDocumentSubresourceFilter::OnActivateStateCalculated(
81 base::Callback<void(ActivationState)> activation_state_callback,
82 ActivationState activation_state) {
83 activation_state_ = activation_state;
84 activation_state_callback.Run(activation_state);
85 }
86
80 void AsyncDocumentSubresourceFilter::GetLoadPolicyForSubdocument( 87 void AsyncDocumentSubresourceFilter::GetLoadPolicyForSubdocument(
81 const GURL& subdocument_url, 88 const GURL& subdocument_url,
82 LoadPolicyCallback result_callback) { 89 LoadPolicyCallback result_callback) {
83 DCHECK(thread_checker_.CalledOnValidThread()); 90 DCHECK(thread_checker_.CalledOnValidThread());
84 91
85 // TODO(pkalinnikov): Think about avoiding copy of |subdocument_url| if it is 92 // 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). 93 // too big and won't be allowed anyway (e.g., it's a data: URI).
87 base::PostTaskAndReplyWithResult( 94 base::PostTaskAndReplyWithResult(
88 task_runner_, FROM_HERE, 95 task_runner_, FROM_HERE,
89 base::Bind( 96 base::Bind(
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 params.parent_activation_state, verified_ruleset->Get()); 136 params.parent_activation_state, verified_ruleset->Get());
130 137
131 DCHECK_NE(ActivationLevel::DISABLED, activation_state.activation_level); 138 DCHECK_NE(ActivationLevel::DISABLED, activation_state.activation_level);
132 filter_.emplace(url::Origin(params.document_url), activation_state, 139 filter_.emplace(url::Origin(params.document_url), activation_state,
133 verified_ruleset->Get()); 140 verified_ruleset->Get());
134 141
135 return activation_state; 142 return activation_state;
136 } 143 }
137 144
138 } // namespace subresource_filter 145 } // namespace subresource_filter
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698