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 |
nhiroki
2015/08/17 03:57:55
nit: "#include <algorithm>" for std::sort.
jeremyarcher
2015/08/17 04:51:28
Done.
| |
7 #include <map> | 7 #include <map> |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
11 #include "base/guid.h" | 11 #include "base/guid.h" |
12 #include "base/location.h" | 12 #include "base/location.h" |
13 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
14 #include "base/metrics/histogram_macros.h" | 14 #include "base/metrics/histogram_macros.h" |
15 #include "base/single_thread_task_runner.h" | 15 #include "base/single_thread_task_runner.h" |
16 #include "base/stl_util.h" | 16 #include "base/stl_util.h" |
(...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
371 void AddNonWindowClient(ServiceWorkerProviderHost* host, | 371 void AddNonWindowClient(ServiceWorkerProviderHost* host, |
372 const ServiceWorkerClientQueryOptions& options, | 372 const ServiceWorkerClientQueryOptions& options, |
373 ServiceWorkerClients* clients) { | 373 ServiceWorkerClients* clients) { |
374 blink::WebServiceWorkerClientType host_client_type = host->client_type(); | 374 blink::WebServiceWorkerClientType host_client_type = host->client_type(); |
375 if (host_client_type == blink::WebServiceWorkerClientTypeWindow) | 375 if (host_client_type == blink::WebServiceWorkerClientTypeWindow) |
376 return; | 376 return; |
377 if (options.client_type != blink::WebServiceWorkerClientTypeAll && | 377 if (options.client_type != blink::WebServiceWorkerClientTypeAll && |
378 options.client_type != host_client_type) | 378 options.client_type != host_client_type) |
379 return; | 379 return; |
380 | 380 |
381 ServiceWorkerClientInfo client_info( | 381 ServiceWorkerClientInfo client_info(blink::WebPageVisibilityStateHidden, |
382 blink::WebPageVisibilityStateHidden, | 382 false, // is_focused |
383 false, // is_focused | 383 host->document_url(), |
384 host->document_url(), REQUEST_CONTEXT_FRAME_TYPE_NONE, host_client_type); | 384 REQUEST_CONTEXT_FRAME_TYPE_NONE, |
385 base::TimeTicks(), host_client_type); | |
385 client_info.client_uuid = host->client_uuid(); | 386 client_info.client_uuid = host->client_uuid(); |
386 clients->push_back(client_info); | 387 clients->push_back(client_info); |
387 } | 388 } |
388 | 389 |
389 bool IsInstalled(ServiceWorkerVersion::Status status) { | 390 bool IsInstalled(ServiceWorkerVersion::Status status) { |
390 switch (status) { | 391 switch (status) { |
391 case ServiceWorkerVersion::NEW: | 392 case ServiceWorkerVersion::NEW: |
392 case ServiceWorkerVersion::INSTALLING: | 393 case ServiceWorkerVersion::INSTALLING: |
393 case ServiceWorkerVersion::REDUNDANT: | 394 case ServiceWorkerVersion::REDUNDANT: |
394 return false; | 395 return false; |
(...skipping 869 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1264 } | 1265 } |
1265 | 1266 |
1266 void ServiceWorkerVersion::OnGetClients( | 1267 void ServiceWorkerVersion::OnGetClients( |
1267 int request_id, | 1268 int request_id, |
1268 const ServiceWorkerClientQueryOptions& options) { | 1269 const ServiceWorkerClientQueryOptions& options) { |
1269 TRACE_EVENT_ASYNC_BEGIN2( | 1270 TRACE_EVENT_ASYNC_BEGIN2( |
1270 "ServiceWorker", "ServiceWorkerVersion::OnGetClients", request_id, | 1271 "ServiceWorker", "ServiceWorkerVersion::OnGetClients", request_id, |
1271 "client_type", options.client_type, "include_uncontrolled", | 1272 "client_type", options.client_type, "include_uncontrolled", |
1272 options.include_uncontrolled); | 1273 options.include_uncontrolled); |
1273 | 1274 |
1275 ServiceWorkerClients clients; | |
1274 if (controllee_map_.empty() && !options.include_uncontrolled) { | 1276 if (controllee_map_.empty() && !options.include_uncontrolled) { |
1275 OnGetClientsFinished(request_id, std::vector<ServiceWorkerClientInfo>()); | 1277 OnGetClientsFinished(request_id, &clients); |
1276 return; | 1278 return; |
1277 } | 1279 } |
1278 | 1280 |
1279 // For Window clients we want to query the info on the UI thread first. | 1281 // For Window clients we want to query the info on the UI thread first. |
1280 if (options.client_type == blink::WebServiceWorkerClientTypeWindow || | 1282 if (options.client_type == blink::WebServiceWorkerClientTypeWindow || |
1281 options.client_type == blink::WebServiceWorkerClientTypeAll) { | 1283 options.client_type == blink::WebServiceWorkerClientTypeAll) { |
1282 GetWindowClients(request_id, options); | 1284 GetWindowClients(request_id, options); |
1283 return; | 1285 return; |
1284 } | 1286 } |
1285 | 1287 |
1286 ServiceWorkerClients clients; | |
1287 GetNonWindowClients(request_id, options, &clients); | 1288 GetNonWindowClients(request_id, options, &clients); |
1288 OnGetClientsFinished(request_id, clients); | 1289 OnGetClientsFinished(request_id, &clients); |
1289 } | 1290 } |
1290 | 1291 |
1291 void ServiceWorkerVersion::OnGetClientsFinished( | 1292 struct ServiceWorkerClientInfoSortMRU { |
1292 int request_id, | 1293 bool operator()(const ServiceWorkerClientInfo& a, |
1293 const ServiceWorkerClients& clients) { | 1294 const ServiceWorkerClientInfo& b) const { |
1295 return a.last_active_time > b.last_active_time; | |
1296 } | |
1297 }; | |
nhiroki
2015/08/17 03:57:55
Can you move this to unnamed namespace?
jeremyarcher
2015/08/17 04:51:28
Done.
| |
1298 | |
1299 void ServiceWorkerVersion::OnGetClientsFinished(int request_id, | |
1300 ServiceWorkerClients* clients) { | |
1294 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 1301 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
1295 TRACE_EVENT_ASYNC_END1("ServiceWorker", "ServiceWorkerVersion::OnGetClients", | 1302 TRACE_EVENT_ASYNC_END1("ServiceWorker", "ServiceWorkerVersion::OnGetClients", |
1296 request_id, "The number of clients", clients.size()); | 1303 request_id, "The number of clients", clients->size()); |
1297 | 1304 |
1298 if (running_status() != RUNNING) | 1305 if (running_status() != RUNNING) |
1299 return; | 1306 return; |
1307 // Sort clients so that the most recently active tab is in the front. | |
1308 std::sort(clients->begin(), clients->end(), ServiceWorkerClientInfoSortMRU()); | |
1300 embedded_worker_->SendMessage( | 1309 embedded_worker_->SendMessage( |
1301 ServiceWorkerMsg_DidGetClients(request_id, clients)); | 1310 ServiceWorkerMsg_DidGetClients(request_id, *clients)); |
1302 } | 1311 } |
1303 | 1312 |
1304 void ServiceWorkerVersion::OnActivateEventFinished( | 1313 void ServiceWorkerVersion::OnActivateEventFinished( |
1305 int request_id, | 1314 int request_id, |
1306 blink::WebServiceWorkerEventResult result) { | 1315 blink::WebServiceWorkerEventResult result) { |
1307 DCHECK(ACTIVATING == status() || | 1316 DCHECK(ACTIVATING == status() || |
1308 REDUNDANT == status()) << status(); | 1317 REDUNDANT == status()) << status(); |
1309 TRACE_EVENT0("ServiceWorker", | 1318 TRACE_EVENT0("ServiceWorker", |
1310 "ServiceWorkerVersion::OnActivateEventFinished"); | 1319 "ServiceWorkerVersion::OnActivateEventFinished"); |
1311 | 1320 |
(...skipping 598 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1910 return clients_info; | 1919 return clients_info; |
1911 } | 1920 } |
1912 | 1921 |
1913 void ServiceWorkerVersion::DidGetWindowClients( | 1922 void ServiceWorkerVersion::DidGetWindowClients( |
1914 int request_id, | 1923 int request_id, |
1915 const ServiceWorkerClientQueryOptions& options, | 1924 const ServiceWorkerClientQueryOptions& options, |
1916 scoped_ptr<ServiceWorkerClients> clients) { | 1925 scoped_ptr<ServiceWorkerClients> clients) { |
1917 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 1926 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
1918 if (options.client_type == blink::WebServiceWorkerClientTypeAll) | 1927 if (options.client_type == blink::WebServiceWorkerClientTypeAll) |
1919 GetNonWindowClients(request_id, options, clients.get()); | 1928 GetNonWindowClients(request_id, options, clients.get()); |
1920 OnGetClientsFinished(request_id, *clients); | 1929 OnGetClientsFinished(request_id, clients.get()); |
1921 } | 1930 } |
1922 | 1931 |
1923 void ServiceWorkerVersion::GetNonWindowClients( | 1932 void ServiceWorkerVersion::GetNonWindowClients( |
1924 int request_id, | 1933 int request_id, |
1925 const ServiceWorkerClientQueryOptions& options, | 1934 const ServiceWorkerClientQueryOptions& options, |
1926 ServiceWorkerClients* clients) { | 1935 ServiceWorkerClients* clients) { |
1927 if (!options.include_uncontrolled) { | 1936 if (!options.include_uncontrolled) { |
1928 for (auto& controllee : controllee_map_) { | 1937 for (auto& controllee : controllee_map_) { |
1929 AddNonWindowClient(controllee.second, options, clients); | 1938 AddNonWindowClient(controllee.second, options, clients); |
1930 } | 1939 } |
(...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2298 base::string16()); | 2307 base::string16()); |
2299 service_port_dispatcher_.reset(); | 2308 service_port_dispatcher_.reset(); |
2300 } | 2309 } |
2301 | 2310 |
2302 void ServiceWorkerVersion::OnBackgroundSyncDispatcherConnectionError() { | 2311 void ServiceWorkerVersion::OnBackgroundSyncDispatcherConnectionError() { |
2303 RunIDMapCallbacks(&sync_requests_, SERVICE_WORKER_ERROR_FAILED); | 2312 RunIDMapCallbacks(&sync_requests_, SERVICE_WORKER_ERROR_FAILED); |
2304 background_sync_dispatcher_.reset(); | 2313 background_sync_dispatcher_.reset(); |
2305 } | 2314 } |
2306 | 2315 |
2307 } // namespace content | 2316 } // namespace content |
OLD | NEW |