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

Side by Side Diff: content/child/service_worker/service_worker_dispatcher.cc

Issue 871013003: Gather the ServiceWorker client information in the browser process. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@rfh_getvisibilitystate
Patch Set: cleanup Created 5 years, 10 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 2013 The Chromium Authors. All rights reserved. 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 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 "content/child/service_worker/service_worker_dispatcher.h" 5 #include "content/child/service_worker/service_worker_dispatcher.h"
6 6
7 #include "base/lazy_instance.h" 7 #include "base/lazy_instance.h"
8 #include "base/stl_util.h" 8 #include "base/stl_util.h"
9 #include "base/threading/thread_local.h" 9 #include "base/threading/thread_local.h"
10 #include "base/trace_event/trace_event.h" 10 #include "base/trace_event/trace_event.h"
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ServiceWorkerStateChanged, 77 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ServiceWorkerStateChanged,
78 OnServiceWorkerStateChanged) 78 OnServiceWorkerStateChanged)
79 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_SetVersionAttributes, 79 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_SetVersionAttributes,
80 OnSetVersionAttributes) 80 OnSetVersionAttributes)
81 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_UpdateFound, 81 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_UpdateFound,
82 OnUpdateFound) 82 OnUpdateFound)
83 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_SetControllerServiceWorker, 83 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_SetControllerServiceWorker,
84 OnSetControllerServiceWorker) 84 OnSetControllerServiceWorker)
85 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_MessageToDocument, 85 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_MessageToDocument,
86 OnPostMessage) 86 OnPostMessage)
87 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_GetClientInfo,
88 OnGetClientInfo)
89 IPC_MESSAGE_UNHANDLED(handled = false) 87 IPC_MESSAGE_UNHANDLED(handled = false)
90 IPC_END_MESSAGE_MAP() 88 IPC_END_MESSAGE_MAP()
91 DCHECK(handled) << "Unhandled message:" << msg.type(); 89 DCHECK(handled) << "Unhandled message:" << msg.type();
92 } 90 }
93 91
94 bool ServiceWorkerDispatcher::Send(IPC::Message* msg) { 92 bool ServiceWorkerDispatcher::Send(IPC::Message* msg) {
95 return thread_safe_sender_->Send(msg); 93 return thread_safe_sender_->Send(msg);
96 } 94 }
97 95
98 void ServiceWorkerDispatcher::RegisterServiceWorker( 96 void ServiceWorkerDispatcher::RegisterServiceWorker(
(...skipping 557 matching lines...) Expand 10 before | Expand all | Expand 10 after
656 for (size_t i = 0; i < sent_message_port_ids.size(); ++i) { 654 for (size_t i = 0; i < sent_message_port_ids.size(); ++i) {
657 ports[i] = new WebMessagePortChannelImpl( 655 ports[i] = new WebMessagePortChannelImpl(
658 new_routing_ids[i], sent_message_port_ids[i], 656 new_routing_ids[i], sent_message_port_ids[i],
659 base::MessageLoopProxy::current()); 657 base::MessageLoopProxy::current());
660 } 658 }
661 } 659 }
662 660
663 found->second->dispatchMessageEvent(message, ports); 661 found->second->dispatchMessageEvent(message, ports);
664 } 662 }
665 663
666 void ServiceWorkerDispatcher::OnGetClientInfo(int thread_id,
667 int embedded_worker_id,
668 int request_id,
669 int provider_id) {
670 blink::WebServiceWorkerClientInfo info;
671 ProviderClientMap::iterator found = provider_clients_.find(provider_id);
672 // TODO(ksakamoto): Could we track these values in the browser side? Except
673 // for |isFocused|, it would be pretty easy.
674 if (found != provider_clients_.end() && found->second->getClientInfo(&info)) {
675 ServiceWorkerClientInfo result;
676 result.client_id = info.clientID;
677 result.page_visibility_state = info.pageVisibilityState;
678 result.is_focused = info.isFocused;
679 result.url = info.url;
680 result.frame_type = static_cast<RequestContextFrameType>(info.frameType);
681
682 thread_safe_sender_->Send(new ServiceWorkerHostMsg_GetClientInfoSuccess(
683 embedded_worker_id, request_id, result));
684 } else {
685 thread_safe_sender_->Send(new ServiceWorkerHostMsg_GetClientInfoError(
686 embedded_worker_id, request_id));
687 }
688 }
689
690 void ServiceWorkerDispatcher::AddServiceWorker( 664 void ServiceWorkerDispatcher::AddServiceWorker(
691 int handle_id, WebServiceWorkerImpl* worker) { 665 int handle_id, WebServiceWorkerImpl* worker) {
692 DCHECK(!ContainsKey(service_workers_, handle_id)); 666 DCHECK(!ContainsKey(service_workers_, handle_id));
693 service_workers_[handle_id] = worker; 667 service_workers_[handle_id] = worker;
694 } 668 }
695 669
696 void ServiceWorkerDispatcher::RemoveServiceWorker(int handle_id) { 670 void ServiceWorkerDispatcher::RemoveServiceWorker(int handle_id) {
697 DCHECK(ContainsKey(service_workers_, handle_id)); 671 DCHECK(ContainsKey(service_workers_, handle_id));
698 service_workers_.erase(handle_id); 672 service_workers_.erase(handle_id);
699 } 673 }
(...skipping 29 matching lines...) Expand all
729 attrs.installing, thread_safe_sender_.get()); 703 attrs.installing, thread_safe_sender_.get());
730 ServiceWorkerHandleReference::Adopt( 704 ServiceWorkerHandleReference::Adopt(
731 attrs.waiting, thread_safe_sender_.get()); 705 attrs.waiting, thread_safe_sender_.get());
732 ServiceWorkerHandleReference::Adopt( 706 ServiceWorkerHandleReference::Adopt(
733 attrs.active, thread_safe_sender_.get()); 707 attrs.active, thread_safe_sender_.get());
734 } 708 }
735 return registration; 709 return registration;
736 } 710 }
737 711
738 } // namespace content 712 } // namespace content
OLDNEW
« no previous file with comments | « content/child/service_worker/service_worker_dispatcher.h ('k') | content/common/service_worker/service_worker_client_info.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698