Supervised user whitelists: Cleanup
[chromium-blink-merge.git] / content / child / quota_message_filter.cc
blobe9290e489d9a1127e1a8c9e90df290b3f8680a77
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"
10 namespace content {
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++);
30 else
31 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,
45 int* ipc_thread_id) {
46 int request_id = -1;
47 const bool success = PickleIterator(msg).ReadInt(&request_id);
48 DCHECK(success);
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);
55 return true;
57 return false;
60 } // namespace content