OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 // See http://dev.chromium.org/developers/design-documents/multi-process-resourc
e-loading | 5 // See http://dev.chromium.org/developers/design-documents/multi-process-resourc
e-loading |
6 | 6 |
7 #include "content/common/resource_dispatcher.h" | 7 #include "content/common/resource_dispatcher.h" |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
| 10 #include "base/bind.h" |
10 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
11 #include "base/file_path.h" | 12 #include "base/file_path.h" |
12 #include "base/message_loop.h" | 13 #include "base/message_loop.h" |
13 #include "base/shared_memory.h" | 14 #include "base/shared_memory.h" |
14 #include "base/string_util.h" | 15 #include "base/string_util.h" |
15 #include "content/common/request_extra_data.h" | 16 #include "content/common/request_extra_data.h" |
16 #include "content/common/resource_messages.h" | 17 #include "content/common/resource_messages.h" |
17 #include "content/common/resource_response.h" | 18 #include "content/common/resource_response.h" |
18 #include "content/public/common/resource_dispatcher_delegate.h" | 19 #include "content/public/common/resource_dispatcher_delegate.h" |
19 #include "net/base/net_errors.h" | 20 #include "net/base/net_errors.h" |
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
250 new ResourceHostMsg_TransferRequestToNewPage(new_routing_id, | 251 new ResourceHostMsg_TransferRequestToNewPage(new_routing_id, |
251 request_id_)); | 252 request_id_)); |
252 } | 253 } |
253 | 254 |
254 } // namespace webkit_glue | 255 } // namespace webkit_glue |
255 | 256 |
256 // ResourceDispatcher --------------------------------------------------------- | 257 // ResourceDispatcher --------------------------------------------------------- |
257 | 258 |
258 ResourceDispatcher::ResourceDispatcher(IPC::Message::Sender* sender) | 259 ResourceDispatcher::ResourceDispatcher(IPC::Message::Sender* sender) |
259 : message_sender_(sender), | 260 : message_sender_(sender), |
260 ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)), | 261 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)), |
261 delegate_(NULL) { | 262 delegate_(NULL) { |
262 } | 263 } |
263 | 264 |
264 ResourceDispatcher::~ResourceDispatcher() { | 265 ResourceDispatcher::~ResourceDispatcher() { |
265 } | 266 } |
266 | 267 |
267 // ResourceDispatcher implementation ------------------------------------------ | 268 // ResourceDispatcher implementation ------------------------------------------ |
268 | 269 |
269 bool ResourceDispatcher::OnMessageReceived(const IPC::Message& message) { | 270 bool ResourceDispatcher::OnMessageReceived(const IPC::Message& message) { |
270 if (!IsResourceDispatcherMessage(message)) { | 271 if (!IsResourceDispatcherMessage(message)) { |
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
505 } | 506 } |
506 PendingRequestInfo& request_info = it->second; | 507 PendingRequestInfo& request_info = it->second; |
507 if (value) { | 508 if (value) { |
508 request_info.is_deferred = value; | 509 request_info.is_deferred = value; |
509 } else if (request_info.is_deferred) { | 510 } else if (request_info.is_deferred) { |
510 request_info.is_deferred = false; | 511 request_info.is_deferred = false; |
511 | 512 |
512 FollowPendingRedirect(request_id, request_info); | 513 FollowPendingRedirect(request_id, request_info); |
513 | 514 |
514 MessageLoop::current()->PostTask(FROM_HERE, | 515 MessageLoop::current()->PostTask(FROM_HERE, |
515 method_factory_.NewRunnableMethod( | 516 base::Bind(&ResourceDispatcher::FlushDeferredMessages, |
516 &ResourceDispatcher::FlushDeferredMessages, request_id)); | 517 weak_factory_.GetWeakPtr(), request_id)); |
517 } | 518 } |
518 } | 519 } |
519 | 520 |
520 void ResourceDispatcher::DispatchMessage(const IPC::Message& message) { | 521 void ResourceDispatcher::DispatchMessage(const IPC::Message& message) { |
521 IPC_BEGIN_MESSAGE_MAP(ResourceDispatcher, message) | 522 IPC_BEGIN_MESSAGE_MAP(ResourceDispatcher, message) |
522 IPC_MESSAGE_HANDLER(ResourceMsg_UploadProgress, OnUploadProgress) | 523 IPC_MESSAGE_HANDLER(ResourceMsg_UploadProgress, OnUploadProgress) |
523 IPC_MESSAGE_HANDLER(ResourceMsg_ReceivedResponse, OnReceivedResponse) | 524 IPC_MESSAGE_HANDLER(ResourceMsg_ReceivedResponse, OnReceivedResponse) |
524 IPC_MESSAGE_HANDLER(ResourceMsg_ReceivedCachedMetadata, | 525 IPC_MESSAGE_HANDLER(ResourceMsg_ReceivedCachedMetadata, |
525 OnReceivedCachedMetadata) | 526 OnReceivedCachedMetadata) |
526 IPC_MESSAGE_HANDLER(ResourceMsg_ReceivedRedirect, OnReceivedRedirect) | 527 IPC_MESSAGE_HANDLER(ResourceMsg_ReceivedRedirect, OnReceivedRedirect) |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
609 | 610 |
610 // static | 611 // static |
611 void ResourceDispatcher::ReleaseResourcesInMessageQueue(MessageQueue* queue) { | 612 void ResourceDispatcher::ReleaseResourcesInMessageQueue(MessageQueue* queue) { |
612 while (!queue->empty()) { | 613 while (!queue->empty()) { |
613 IPC::Message* message = queue->front(); | 614 IPC::Message* message = queue->front(); |
614 ReleaseResourcesInDataMessage(*message); | 615 ReleaseResourcesInDataMessage(*message); |
615 queue->pop_front(); | 616 queue->pop_front(); |
616 delete message; | 617 delete message; |
617 } | 618 } |
618 } | 619 } |
OLD | NEW |