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

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: review comments 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/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 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 555 matching lines...) Expand 10 before | Expand all | Expand 10 after
654 for (size_t i = 0; i < sent_message_port_ids.size(); ++i) { 652 for (size_t i = 0; i < sent_message_port_ids.size(); ++i) {
655 ports[i] = new WebMessagePortChannelImpl( 653 ports[i] = new WebMessagePortChannelImpl(
656 new_routing_ids[i], sent_message_port_ids[i], 654 new_routing_ids[i], sent_message_port_ids[i],
657 base::MessageLoopProxy::current()); 655 base::MessageLoopProxy::current());
658 } 656 }
659 } 657 }
660 658
661 found->second->dispatchMessageEvent(message, ports); 659 found->second->dispatchMessageEvent(message, ports);
662 } 660 }
663 661
664 void ServiceWorkerDispatcher::OnGetClientInfo(int thread_id,
665 int embedded_worker_id,
666 int request_id,
667 int provider_id) {
668 blink::WebServiceWorkerClientInfo info;
669 ProviderClientMap::iterator found = provider_clients_.find(provider_id);
670 // TODO(ksakamoto): Could we track these values in the browser side? Except
671 // for |isFocused|, it would be pretty easy.
672 if (found != provider_clients_.end() && found->second->getClientInfo(&info)) {
673 ServiceWorkerClientInfo result;
674 result.client_id = info.clientID;
675 result.page_visibility_state = info.pageVisibilityState;
676 result.is_focused = info.isFocused;
677 result.url = info.url;
678 result.frame_type = static_cast<RequestContextFrameType>(info.frameType);
679
680 thread_safe_sender_->Send(new ServiceWorkerHostMsg_GetClientInfoSuccess(
681 embedded_worker_id, request_id, result));
682 } else {
683 thread_safe_sender_->Send(new ServiceWorkerHostMsg_GetClientInfoError(
684 embedded_worker_id, request_id));
685 }
686 }
687
688 void ServiceWorkerDispatcher::AddServiceWorker( 662 void ServiceWorkerDispatcher::AddServiceWorker(
689 int handle_id, WebServiceWorkerImpl* worker) { 663 int handle_id, WebServiceWorkerImpl* worker) {
690 DCHECK(!ContainsKey(service_workers_, handle_id)); 664 DCHECK(!ContainsKey(service_workers_, handle_id));
691 service_workers_[handle_id] = worker; 665 service_workers_[handle_id] = worker;
692 } 666 }
693 667
694 void ServiceWorkerDispatcher::RemoveServiceWorker(int handle_id) { 668 void ServiceWorkerDispatcher::RemoveServiceWorker(int handle_id) {
695 DCHECK(ContainsKey(service_workers_, handle_id)); 669 DCHECK(ContainsKey(service_workers_, handle_id));
696 service_workers_.erase(handle_id); 670 service_workers_.erase(handle_id);
697 } 671 }
(...skipping 29 matching lines...) Expand all
727 attrs.installing, thread_safe_sender_.get()); 701 attrs.installing, thread_safe_sender_.get());
728 ServiceWorkerHandleReference::Adopt( 702 ServiceWorkerHandleReference::Adopt(
729 attrs.waiting, thread_safe_sender_.get()); 703 attrs.waiting, thread_safe_sender_.get());
730 ServiceWorkerHandleReference::Adopt( 704 ServiceWorkerHandleReference::Adopt(
731 attrs.active, thread_safe_sender_.get()); 705 attrs.active, thread_safe_sender_.get());
732 } 706 }
733 return registration; 707 return registration;
734 } 708 }
735 709
736 } // namespace content 710 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698