ozone: evdev: Sync caps lock LED state to evdev
[chromium-blink-merge.git] / content / browser / devtools / service_worker_devtools_manager.cc
blobd38f692b8e5bd71dc24829d27ca1756f026856c3
1 // Copyright 2014 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/browser/devtools/service_worker_devtools_manager.h"
7 #include "content/browser/devtools/devtools_manager.h"
8 #include "content/browser/devtools/ipc_devtools_agent_host.h"
9 #include "content/browser/devtools/service_worker_devtools_agent_host.h"
10 #include "content/browser/devtools/shared_worker_devtools_agent_host.h"
11 #include "content/browser/shared_worker/shared_worker_instance.h"
12 #include "content/public/browser/browser_thread.h"
13 #include "content/public/browser/render_process_host.h"
14 #include "content/public/browser/worker_service.h"
15 #include "ipc/ipc_listener.h"
17 namespace content {
19 ServiceWorkerDevToolsManager::ServiceWorkerIdentifier::ServiceWorkerIdentifier(
20 const ServiceWorkerContextCore* context,
21 base::WeakPtr<ServiceWorkerContextCore> context_weak,
22 int64 version_id,
23 const GURL& url)
24 : context_(context),
25 context_weak_(context_weak),
26 version_id_(version_id),
27 url_(url) {
30 ServiceWorkerDevToolsManager::ServiceWorkerIdentifier::ServiceWorkerIdentifier(
31 const ServiceWorkerIdentifier& other)
32 : context_(other.context_),
33 context_weak_(other.context_weak_),
34 version_id_(other.version_id_),
35 url_(other.url_) {
38 ServiceWorkerDevToolsManager::
39 ServiceWorkerIdentifier::~ServiceWorkerIdentifier() {
42 bool ServiceWorkerDevToolsManager::ServiceWorkerIdentifier::Matches(
43 const ServiceWorkerIdentifier& other) const {
44 return context_ == other.context_ && version_id_ == other.version_id_;
47 // static
48 ServiceWorkerDevToolsManager* ServiceWorkerDevToolsManager::GetInstance() {
49 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
50 return Singleton<ServiceWorkerDevToolsManager>::get();
53 bool ServiceWorkerDevToolsManager::WorkerCreated(
54 int worker_process_id,
55 int worker_route_id,
56 const ServiceWorkerIdentifier& service_worker_id) {
57 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
58 const WorkerId id(worker_process_id, worker_route_id);
59 AgentHostMap::iterator it = FindExistingWorkerAgentHost(service_worker_id);
60 if (it == workers().end()) {
61 workers()[id] = new ServiceWorkerDevToolsAgentHost(
62 id, service_worker_id, debug_service_worker_on_start_);
63 DevToolsManager::GetInstance()->AgentHostChanged(workers()[id]);
64 return debug_service_worker_on_start_;
66 WorkerRestarted(id, it);
67 return it->second->IsAttached();
70 void ServiceWorkerDevToolsManager::WorkerStopIgnored(int worker_process_id,
71 int worker_route_id) {
72 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
73 // TODO(pfeldman): Show a console message to tell the user that UA didn't
74 // terminate the worker because devtools is attached.
77 ServiceWorkerDevToolsManager::ServiceWorkerDevToolsManager()
78 : debug_service_worker_on_start_(false) {
81 ServiceWorkerDevToolsManager::~ServiceWorkerDevToolsManager() {
84 ServiceWorkerDevToolsManager::AgentHostMap::iterator
85 ServiceWorkerDevToolsManager::FindExistingWorkerAgentHost(
86 const ServiceWorkerIdentifier& service_worker_id) {
87 AgentHostMap::iterator it = workers().begin();
88 for (; it != workers().end(); ++it) {
89 if (static_cast<ServiceWorkerDevToolsAgentHost*>(
90 it->second)->Matches(service_worker_id))
91 break;
93 return it;
96 } // namespace content