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

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: Created 5 years, 11 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/debug/trace_event.h" 7 #include "base/debug/trace_event.h"
8 #include "base/lazy_instance.h" 8 #include "base/lazy_instance.h"
9 #include "base/stl_util.h" 9 #include "base/stl_util.h"
10 #include "base/threading/thread_local.h" 10 #include "base/threading/thread_local.h"
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ServiceWorkerStateChanged, 75 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ServiceWorkerStateChanged,
76 OnServiceWorkerStateChanged) 76 OnServiceWorkerStateChanged)
77 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_SetVersionAttributes, 77 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_SetVersionAttributes,
78 OnSetVersionAttributes) 78 OnSetVersionAttributes)
79 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_UpdateFound, 79 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_UpdateFound,
80 OnUpdateFound) 80 OnUpdateFound)
81 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_SetControllerServiceWorker, 81 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_SetControllerServiceWorker,
82 OnSetControllerServiceWorker) 82 OnSetControllerServiceWorker)
83 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_MessageToDocument, 83 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_MessageToDocument,
84 OnPostMessage) 84 OnPostMessage)
85 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_GetClientInfo,
86 OnGetClientInfo)
87 IPC_MESSAGE_UNHANDLED(handled = false) 85 IPC_MESSAGE_UNHANDLED(handled = false)
88 IPC_END_MESSAGE_MAP() 86 IPC_END_MESSAGE_MAP()
89 DCHECK(handled) << "Unhandled message:" << msg.type(); 87 DCHECK(handled) << "Unhandled message:" << msg.type();
90 } 88 }
91 89
92 bool ServiceWorkerDispatcher::Send(IPC::Message* msg) { 90 bool ServiceWorkerDispatcher::Send(IPC::Message* msg) {
93 return thread_safe_sender_->Send(msg); 91 return thread_safe_sender_->Send(msg);
94 } 92 }
95 93
96 void ServiceWorkerDispatcher::RegisterServiceWorker( 94 void ServiceWorkerDispatcher::RegisterServiceWorker(
(...skipping 534 matching lines...) Expand 10 before | Expand all | Expand 10 after
631 for (size_t i = 0; i < sent_message_port_ids.size(); ++i) { 629 for (size_t i = 0; i < sent_message_port_ids.size(); ++i) {
632 ports[i] = new WebMessagePortChannelImpl( 630 ports[i] = new WebMessagePortChannelImpl(
633 new_routing_ids[i], sent_message_port_ids[i], 631 new_routing_ids[i], sent_message_port_ids[i],
634 base::MessageLoopProxy::current()); 632 base::MessageLoopProxy::current());
635 } 633 }
636 } 634 }
637 635
638 found->second->dispatchMessageEvent(message, ports); 636 found->second->dispatchMessageEvent(message, ports);
639 } 637 }
640 638
641 void ServiceWorkerDispatcher::OnGetClientInfo(int thread_id,
642 int embedded_worker_id,
643 int request_id,
644 int provider_id) {
645 blink::WebServiceWorkerClientInfo info;
646 ProviderClientMap::iterator found = provider_clients_.find(provider_id);
647 // TODO(ksakamoto): Could we track these values in the browser side? Except
648 // for |isFocused|, it would be pretty easy.
649 if (found != provider_clients_.end() && found->second->getClientInfo(&info)) {
650 ServiceWorkerClientInfo result;
651 result.client_id = info.clientID;
652 result.page_visibility_state = info.pageVisibilityState;
653 result.is_focused = info.isFocused;
654 result.url = info.url;
655 result.frame_type = static_cast<RequestContextFrameType>(info.frameType);
656
657 thread_safe_sender_->Send(new ServiceWorkerHostMsg_GetClientInfoSuccess(
658 embedded_worker_id, request_id, result));
659 } else {
660 thread_safe_sender_->Send(new ServiceWorkerHostMsg_GetClientInfoError(
661 embedded_worker_id, request_id));
662 }
663 }
664
665 void ServiceWorkerDispatcher::AddServiceWorker( 639 void ServiceWorkerDispatcher::AddServiceWorker(
666 int handle_id, WebServiceWorkerImpl* worker) { 640 int handle_id, WebServiceWorkerImpl* worker) {
667 DCHECK(!ContainsKey(service_workers_, handle_id)); 641 DCHECK(!ContainsKey(service_workers_, handle_id));
668 service_workers_[handle_id] = worker; 642 service_workers_[handle_id] = worker;
669 } 643 }
670 644
671 void ServiceWorkerDispatcher::RemoveServiceWorker(int handle_id) { 645 void ServiceWorkerDispatcher::RemoveServiceWorker(int handle_id) {
672 DCHECK(ContainsKey(service_workers_, handle_id)); 646 DCHECK(ContainsKey(service_workers_, handle_id));
673 service_workers_.erase(handle_id); 647 service_workers_.erase(handle_id);
674 } 648 }
(...skipping 29 matching lines...) Expand all
704 attrs.installing, thread_safe_sender_.get()); 678 attrs.installing, thread_safe_sender_.get());
705 ServiceWorkerHandleReference::Adopt( 679 ServiceWorkerHandleReference::Adopt(
706 attrs.waiting, thread_safe_sender_.get()); 680 attrs.waiting, thread_safe_sender_.get());
707 ServiceWorkerHandleReference::Adopt( 681 ServiceWorkerHandleReference::Adopt(
708 attrs.active, thread_safe_sender_.get()); 682 attrs.active, thread_safe_sender_.get());
709 } 683 }
710 return registration; 684 return registration;
711 } 685 }
712 686
713 } // namespace content 687 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698