| OLD | NEW |
| 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/browser/service_worker/service_worker_version.h" | 5 #include "content/browser/service_worker/service_worker_version.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/location.h" | 8 #include "base/location.h" |
| 9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
| 10 #include "base/metrics/histogram_macros.h" | 10 #include "base/metrics/histogram_macros.h" |
| (...skipping 520 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 531 const base::Closure& callback) { | 531 const base::Closure& callback) { |
| 532 status_change_callbacks_.push_back(callback); | 532 status_change_callbacks_.push_back(callback); |
| 533 } | 533 } |
| 534 | 534 |
| 535 ServiceWorkerVersionInfo ServiceWorkerVersion::GetInfo() { | 535 ServiceWorkerVersionInfo ServiceWorkerVersion::GetInfo() { |
| 536 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 536 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 537 ServiceWorkerVersionInfo info( | 537 ServiceWorkerVersionInfo info( |
| 538 running_status(), status(), script_url(), registration_id(), version_id(), | 538 running_status(), status(), script_url(), registration_id(), version_id(), |
| 539 embedded_worker()->process_id(), embedded_worker()->thread_id(), | 539 embedded_worker()->process_id(), embedded_worker()->thread_id(), |
| 540 embedded_worker()->worker_devtools_agent_route_id()); | 540 embedded_worker()->worker_devtools_agent_route_id()); |
| 541 for (auto& controllee : controllee_map_) { |
| 542 const ServiceWorkerProviderHost* const host = controllee.second; |
| 543 info.clients.insert( |
| 544 std::pair<std::string, ServiceWorkerVersionInfo::ClientInfo>( |
| 545 host->client_uuid(), ServiceWorkerVersionInfo::ClientInfo( |
| 546 host->process_id(), host->frame_id(), |
| 547 host->shared_worker_route_id()))); |
| 548 } |
| 541 if (!main_script_http_info_) | 549 if (!main_script_http_info_) |
| 542 return info; | 550 return info; |
| 543 info.script_response_time = main_script_http_info_->response_time; | 551 info.script_response_time = main_script_http_info_->response_time; |
| 544 if (main_script_http_info_->headers) | 552 if (main_script_http_info_->headers) |
| 545 main_script_http_info_->headers->GetLastModifiedValue( | 553 main_script_http_info_->headers->GetLastModifiedValue( |
| 546 &info.script_last_modified); | 554 &info.script_last_modified); |
| 547 return info; | 555 return info; |
| 548 } | 556 } |
| 549 | 557 |
| 550 void ServiceWorkerVersion::StartWorker(const StatusCallback& callback) { | 558 void ServiceWorkerVersion::StartWorker(const StatusCallback& callback) { |
| (...skipping 374 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 925 } | 933 } |
| 926 | 934 |
| 927 void ServiceWorkerVersion::AddControllee( | 935 void ServiceWorkerVersion::AddControllee( |
| 928 ServiceWorkerProviderHost* provider_host) { | 936 ServiceWorkerProviderHost* provider_host) { |
| 929 const std::string& uuid = provider_host->client_uuid(); | 937 const std::string& uuid = provider_host->client_uuid(); |
| 930 CHECK(!provider_host->client_uuid().empty()); | 938 CHECK(!provider_host->client_uuid().empty()); |
| 931 DCHECK(!ContainsKey(controllee_map_, uuid)); | 939 DCHECK(!ContainsKey(controllee_map_, uuid)); |
| 932 controllee_map_[uuid] = provider_host; | 940 controllee_map_[uuid] = provider_host; |
| 933 // Keep the worker alive a bit longer right after a new controllee is added. | 941 // Keep the worker alive a bit longer right after a new controllee is added. |
| 934 RestartTick(&idle_time_); | 942 RestartTick(&idle_time_); |
| 943 FOR_EACH_OBSERVER(Listener, listeners_, |
| 944 OnControlleeAdded(this, provider_host)); |
| 935 } | 945 } |
| 936 | 946 |
| 937 void ServiceWorkerVersion::RemoveControllee( | 947 void ServiceWorkerVersion::RemoveControllee( |
| 938 ServiceWorkerProviderHost* provider_host) { | 948 ServiceWorkerProviderHost* provider_host) { |
| 939 const std::string& uuid = provider_host->client_uuid(); | 949 const std::string& uuid = provider_host->client_uuid(); |
| 940 DCHECK(ContainsKey(controllee_map_, uuid)); | 950 DCHECK(ContainsKey(controllee_map_, uuid)); |
| 941 controllee_map_.erase(uuid); | 951 controllee_map_.erase(uuid); |
| 952 FOR_EACH_OBSERVER(Listener, listeners_, |
| 953 OnControlleeRemoved(this, provider_host)); |
| 942 if (HasControllee()) | 954 if (HasControllee()) |
| 943 return; | 955 return; |
| 944 FOR_EACH_OBSERVER(Listener, listeners_, OnNoControllees(this)); | 956 FOR_EACH_OBSERVER(Listener, listeners_, OnNoControllees(this)); |
| 945 } | 957 } |
| 946 | 958 |
| 947 void ServiceWorkerVersion::AddStreamingURLRequestJob( | 959 void ServiceWorkerVersion::AddStreamingURLRequestJob( |
| 948 const ServiceWorkerURLRequestJob* request_job) { | 960 const ServiceWorkerURLRequestJob* request_job) { |
| 949 DCHECK(streaming_url_request_jobs_.find(request_job) == | 961 DCHECK(streaming_url_request_jobs_.find(request_job) == |
| 950 streaming_url_request_jobs_.end()); | 962 streaming_url_request_jobs_.end()); |
| 951 streaming_url_request_jobs_.insert(request_job); | 963 streaming_url_request_jobs_.insert(request_job); |
| (...skipping 1083 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2035 return SERVICE_WORKER_ERROR_ABORT; | 2047 return SERVICE_WORKER_ERROR_ABORT; |
| 2036 default: | 2048 default: |
| 2037 return SERVICE_WORKER_ERROR_NETWORK; | 2049 return SERVICE_WORKER_ERROR_NETWORK; |
| 2038 } | 2050 } |
| 2039 } | 2051 } |
| 2040 | 2052 |
| 2041 return default_code; | 2053 return default_code; |
| 2042 } | 2054 } |
| 2043 | 2055 |
| 2044 } // namespace content | 2056 } // namespace content |
| OLD | NEW |