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/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
9 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
10 #include "base/strings/string16.h" | 10 #include "base/strings/string16.h" |
(...skipping 20 matching lines...) Expand all Loading... |
31 #include "content/public/common/content_client.h" | 31 #include "content/public/common/content_client.h" |
32 #include "content/public/common/content_switches.h" | 32 #include "content/public/common/content_switches.h" |
33 #include "content/public/common/result_codes.h" | 33 #include "content/public/common/result_codes.h" |
34 #include "net/http/http_response_info.h" | 34 #include "net/http/http_response_info.h" |
35 | 35 |
36 namespace content { | 36 namespace content { |
37 | 37 |
38 typedef ServiceWorkerVersion::StatusCallback StatusCallback; | 38 typedef ServiceWorkerVersion::StatusCallback StatusCallback; |
39 typedef ServiceWorkerVersion::MessageCallback MessageCallback; | 39 typedef ServiceWorkerVersion::MessageCallback MessageCallback; |
40 | 40 |
41 class ServiceWorkerVersion::GetClientDocumentsCallback | 41 class ServiceWorkerVersion::GetClientsCallback |
42 : public base::RefCounted<GetClientDocumentsCallback> { | 42 : public base::RefCounted<GetClientsCallback> { |
43 public: | 43 public: |
44 GetClientDocumentsCallback(int request_id, | 44 GetClientsCallback(int request_id, ServiceWorkerVersion* version) |
45 ServiceWorkerVersion* version) | |
46 : request_id_(request_id), | 45 : request_id_(request_id), |
47 version_(version) { | 46 version_(version) { |
48 DCHECK(version_); | 47 DCHECK(version_); |
49 } | 48 } |
50 | 49 |
51 void AddClientInfo(int client_id, const ServiceWorkerClientInfo& info) { | 50 void AddClientInfo(int client_id, const ServiceWorkerClientInfo& info) { |
52 clients_.push_back(info); | 51 clients_.push_back(info); |
53 clients_.back().client_id = client_id; | 52 clients_.back().client_id = client_id; |
54 } | 53 } |
55 | 54 |
56 private: | 55 private: |
57 friend class base::RefCounted<GetClientDocumentsCallback>; | 56 friend class base::RefCounted<GetClientsCallback>; |
58 | 57 |
59 virtual ~GetClientDocumentsCallback() { | 58 virtual ~GetClientsCallback() { |
60 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 59 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
61 | 60 |
62 if (version_->running_status() == RUNNING) { | 61 if (version_->running_status() == RUNNING) { |
63 version_->embedded_worker_->SendMessage( | 62 version_->embedded_worker_->SendMessage( |
64 ServiceWorkerMsg_DidGetClientDocuments(request_id_, clients_)); | 63 ServiceWorkerMsg_DidGetClients(request_id_, clients_)); |
65 } | 64 } |
66 } | 65 } |
67 | 66 |
68 std::vector<ServiceWorkerClientInfo> clients_; | 67 std::vector<ServiceWorkerClientInfo> clients_; |
69 int request_id_; | 68 int request_id_; |
70 scoped_refptr<ServiceWorkerVersion> version_; | 69 scoped_refptr<ServiceWorkerVersion> version_; |
71 | 70 |
72 DISALLOW_COPY_AND_ASSIGN(GetClientDocumentsCallback); | 71 DISALLOW_COPY_AND_ASSIGN(GetClientsCallback); |
73 }; | 72 }; |
74 | 73 |
75 namespace { | 74 namespace { |
76 | 75 |
77 // Default delay for scheduled stop. | 76 // Default delay for scheduled stop. |
78 // (Note that if all references to the version is dropped the worker | 77 // (Note that if all references to the version is dropped the worker |
79 // is also stopped without delay) | 78 // is also stopped without delay) |
80 const int64 kStopWorkerDelay = 30; // 30 secs. | 79 const int64 kStopWorkerDelay = 30; // 30 secs. |
81 | 80 |
82 // Delay for attempting to stop a doomed worker with in-flight requests. | 81 // Delay for attempting to stop a doomed worker with in-flight requests. |
(...skipping 809 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
892 source_identifier, | 891 source_identifier, |
893 message_level, | 892 message_level, |
894 message, | 893 message, |
895 line_number, | 894 line_number, |
896 source_url)); | 895 source_url)); |
897 } | 896 } |
898 | 897 |
899 bool ServiceWorkerVersion::OnMessageReceived(const IPC::Message& message) { | 898 bool ServiceWorkerVersion::OnMessageReceived(const IPC::Message& message) { |
900 bool handled = true; | 899 bool handled = true; |
901 IPC_BEGIN_MESSAGE_MAP(ServiceWorkerVersion, message) | 900 IPC_BEGIN_MESSAGE_MAP(ServiceWorkerVersion, message) |
902 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_GetClientDocuments, | 901 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_GetClients, |
903 OnGetClientDocuments) | 902 OnGetClients) |
904 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_ActivateEventFinished, | 903 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_ActivateEventFinished, |
905 OnActivateEventFinished) | 904 OnActivateEventFinished) |
906 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_InstallEventFinished, | 905 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_InstallEventFinished, |
907 OnInstallEventFinished) | 906 OnInstallEventFinished) |
908 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_FetchEventFinished, | 907 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_FetchEventFinished, |
909 OnFetchEventFinished) | 908 OnFetchEventFinished) |
910 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_SyncEventFinished, | 909 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_SyncEventFinished, |
911 OnSyncEventFinished) | 910 OnSyncEventFinished) |
912 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_NotificationClickEventFinished, | 911 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_NotificationClickEventFinished, |
913 OnNotificationClickEventFinished) | 912 OnNotificationClickEventFinished) |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
965 | 964 |
966 int request_id = activate_callbacks_.Add(new StatusCallback(callback)); | 965 int request_id = activate_callbacks_.Add(new StatusCallback(callback)); |
967 ServiceWorkerStatusCode status = | 966 ServiceWorkerStatusCode status = |
968 embedded_worker_->SendMessage(ServiceWorkerMsg_ActivateEvent(request_id)); | 967 embedded_worker_->SendMessage(ServiceWorkerMsg_ActivateEvent(request_id)); |
969 if (status != SERVICE_WORKER_OK) { | 968 if (status != SERVICE_WORKER_OK) { |
970 activate_callbacks_.Remove(request_id); | 969 activate_callbacks_.Remove(request_id); |
971 RunSoon(base::Bind(callback, status)); | 970 RunSoon(base::Bind(callback, status)); |
972 } | 971 } |
973 } | 972 } |
974 | 973 |
975 void ServiceWorkerVersion::OnGetClientDocuments(int request_id) { | 974 void ServiceWorkerVersion::OnGetClients( |
| 975 int request_id, |
| 976 const ServiceWorkerClientQueryOptions& /* options */) { |
| 977 // TODO(kinuko): Handle ClientQueryOptions. (crbug.com/455241, 460415 etc) |
976 if (controllee_by_id_.IsEmpty()) { | 978 if (controllee_by_id_.IsEmpty()) { |
977 if (running_status() == RUNNING) { | 979 if (running_status() == RUNNING) { |
978 embedded_worker_->SendMessage( | 980 embedded_worker_->SendMessage( |
979 ServiceWorkerMsg_DidGetClientDocuments(request_id, | 981 ServiceWorkerMsg_DidGetClients(request_id, |
980 std::vector<ServiceWorkerClientInfo>())); | 982 std::vector<ServiceWorkerClientInfo>())); |
981 } | 983 } |
982 return; | 984 return; |
983 } | 985 } |
984 scoped_refptr<GetClientDocumentsCallback> callback( | 986 scoped_refptr<GetClientsCallback> callback( |
985 new GetClientDocumentsCallback(request_id, this)); | 987 new GetClientsCallback(request_id, this)); |
986 ControlleeByIDMap::iterator it(&controllee_by_id_); | 988 ControlleeByIDMap::iterator it(&controllee_by_id_); |
987 TRACE_EVENT0("ServiceWorker", | 989 TRACE_EVENT0("ServiceWorker", |
988 "ServiceWorkerVersion::OnGetClientDocuments"); | 990 "ServiceWorkerVersion::OnGetClients"); |
989 while (!it.IsAtEnd()) { | 991 while (!it.IsAtEnd()) { |
990 // TODO(mlamouri): we could coalesce those requests into one. | 992 // TODO(mlamouri): we could coalesce those requests into one. |
991 it.GetCurrentValue()->GetClientInfo( | 993 it.GetCurrentValue()->GetClientInfo( |
992 base::Bind(&ServiceWorkerVersion::DidGetClientInfo, | 994 base::Bind(&ServiceWorkerVersion::DidGetClientInfo, |
993 weak_factory_.GetWeakPtr(), it.GetCurrentKey(), callback)); | 995 weak_factory_.GetWeakPtr(), it.GetCurrentKey(), callback)); |
994 it.Advance(); | 996 it.Advance(); |
995 } | 997 } |
996 } | 998 } |
997 | 999 |
998 void ServiceWorkerVersion::OnActivateEventFinished( | 1000 void ServiceWorkerVersion::OnActivateEventFinished( |
(...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1378 request_id, blink::WebServiceWorkerError::ErrorTypeAbort, | 1380 request_id, blink::WebServiceWorkerError::ErrorTypeAbort, |
1379 base::ASCIIToUTF16(kClaimClientsShutdownErrorMesage))); | 1381 base::ASCIIToUTF16(kClaimClientsShutdownErrorMesage))); |
1380 return; | 1382 return; |
1381 } | 1383 } |
1382 DCHECK(status == SERVICE_WORKER_OK); | 1384 DCHECK(status == SERVICE_WORKER_OK); |
1383 embedded_worker_->SendMessage(ServiceWorkerMsg_DidClaimClients(request_id)); | 1385 embedded_worker_->SendMessage(ServiceWorkerMsg_DidClaimClients(request_id)); |
1384 } | 1386 } |
1385 | 1387 |
1386 void ServiceWorkerVersion::DidGetClientInfo( | 1388 void ServiceWorkerVersion::DidGetClientInfo( |
1387 int client_id, | 1389 int client_id, |
1388 scoped_refptr<GetClientDocumentsCallback> callback, | 1390 scoped_refptr<GetClientsCallback> callback, |
1389 const ServiceWorkerClientInfo& info) { | 1391 const ServiceWorkerClientInfo& info) { |
1390 // If the request to the provider_host returned an empty | 1392 // If the request to the provider_host returned an empty |
1391 // ServiceWorkerClientInfo, that means that it wasn't possible to associate | 1393 // ServiceWorkerClientInfo, that means that it wasn't possible to associate |
1392 // it with a valid RenderFrameHost. It might be because the frame was killed | 1394 // it with a valid RenderFrameHost. It might be because the frame was killed |
1393 // or navigated in between. | 1395 // or navigated in between. |
1394 if (info.IsEmpty()) | 1396 if (info.IsEmpty()) |
1395 return; | 1397 return; |
1396 | 1398 |
1397 // We can get info for a frame that was navigating end ended up with a | 1399 // We can get info for a frame that was navigating end ended up with a |
1398 // different URL than expected. In such case, we should make sure to not | 1400 // different URL than expected. In such case, we should make sure to not |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1501 int request_id) { | 1503 int request_id) { |
1502 callbacks->Remove(request_id); | 1504 callbacks->Remove(request_id); |
1503 if (is_doomed_) { | 1505 if (is_doomed_) { |
1504 // The stop should be already scheduled, but try to stop immediately, in | 1506 // The stop should be already scheduled, but try to stop immediately, in |
1505 // order to release worker resources soon. | 1507 // order to release worker resources soon. |
1506 StopWorkerIfIdle(); | 1508 StopWorkerIfIdle(); |
1507 } | 1509 } |
1508 } | 1510 } |
1509 | 1511 |
1510 } // namespace content | 1512 } // namespace content |
OLD | NEW |