1 // Copyright 2013 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.
5 #include "content/child/quota_message_filter.h"
7 #include "content/child/quota_dispatcher.h"
8 #include "content/common/quota_messages.h"
12 QuotaMessageFilter::QuotaMessageFilter(ThreadSafeSender
* thread_safe_sender
)
13 : WorkerThreadMessageFilter(thread_safe_sender
), next_request_id_(0) {
16 QuotaMessageFilter::~QuotaMessageFilter() {}
18 int QuotaMessageFilter::GenerateRequestID(int thread_id
) {
19 base::AutoLock
lock(request_id_map_lock_
);
20 request_id_map_
[next_request_id_
] = thread_id
;
21 return next_request_id_
++;
24 void QuotaMessageFilter::ClearThreadRequests(int thread_id
) {
25 base::AutoLock
lock(request_id_map_lock_
);
26 for (RequestIdToThreadId::iterator iter
= request_id_map_
.begin();
27 iter
!= request_id_map_
.end();) {
28 if (iter
->second
== thread_id
)
29 request_id_map_
.erase(iter
++);
35 bool QuotaMessageFilter::ShouldHandleMessage(const IPC::Message
& msg
) const {
36 return IPC_MESSAGE_CLASS(msg
) == QuotaMsgStart
;
39 void QuotaMessageFilter::OnFilteredMessageReceived(const IPC::Message
& msg
) {
40 QuotaDispatcher::ThreadSpecificInstance(thread_safe_sender(), this)
41 ->OnMessageReceived(msg
);
44 bool QuotaMessageFilter::GetWorkerThreadIdForMessage(const IPC::Message
& msg
,
47 const bool success
= base::PickleIterator(msg
).ReadInt(&request_id
);
50 base::AutoLock
lock(request_id_map_lock_
);
51 RequestIdToThreadId::iterator found
= request_id_map_
.find(request_id
);
52 if (found
!= request_id_map_
.end()) {
53 *ipc_thread_id
= found
->second
;
54 request_id_map_
.erase(found
);
60 } // namespace content