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 556 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
567 sync_callbacks_.Remove(request_id); | 567 sync_callbacks_.Remove(request_id); |
568 RunSoon(base::Bind(callback, status)); | 568 RunSoon(base::Bind(callback, status)); |
569 } | 569 } |
570 } | 570 } |
571 | 571 |
572 void ServiceWorkerVersion::DispatchNotificationClickEvent( | 572 void ServiceWorkerVersion::DispatchNotificationClickEvent( |
573 const StatusCallback& callback, | 573 const StatusCallback& callback, |
574 const std::string& notification_id, | 574 const std::string& notification_id, |
575 const PlatformNotificationData& notification_data) { | 575 const PlatformNotificationData& notification_data) { |
576 DCHECK_EQ(ACTIVATED, status()) << status(); | 576 DCHECK_EQ(ACTIVATED, status()) << status(); |
577 | |
578 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( | |
579 switches::kEnableExperimentalWebPlatformFeatures)) { | |
580 callback.Run(SERVICE_WORKER_ERROR_ABORT); | |
581 return; | |
582 } | |
583 | |
584 if (running_status() != RUNNING) { | 577 if (running_status() != RUNNING) { |
585 // Schedule calling this method after starting the worker. | 578 // Schedule calling this method after starting the worker. |
586 StartWorker(base::Bind(&RunTaskAfterStartWorker, | 579 StartWorker(base::Bind(&RunTaskAfterStartWorker, |
587 weak_factory_.GetWeakPtr(), callback, | 580 weak_factory_.GetWeakPtr(), callback, |
588 base::Bind(&self::DispatchNotificationClickEvent, | 581 base::Bind(&self::DispatchNotificationClickEvent, |
589 weak_factory_.GetWeakPtr(), | 582 weak_factory_.GetWeakPtr(), |
590 callback, notification_id, | 583 callback, notification_id, |
591 notification_data))); | 584 notification_data))); |
592 return; | 585 return; |
593 } | 586 } |
594 | 587 |
595 int request_id = | 588 int request_id = |
596 notification_click_callbacks_.Add(new StatusCallback(callback)); | 589 notification_click_callbacks_.Add(new StatusCallback(callback)); |
597 ServiceWorkerStatusCode status = embedded_worker_->SendMessage( | 590 ServiceWorkerStatusCode status = embedded_worker_->SendMessage( |
598 ServiceWorkerMsg_NotificationClickEvent(request_id, | 591 ServiceWorkerMsg_NotificationClickEvent(request_id, |
599 notification_id, | 592 notification_id, |
600 notification_data)); | 593 notification_data)); |
601 if (status != SERVICE_WORKER_OK) { | 594 if (status != SERVICE_WORKER_OK) { |
602 notification_click_callbacks_.Remove(request_id); | 595 notification_click_callbacks_.Remove(request_id); |
603 RunSoon(base::Bind(callback, status)); | 596 RunSoon(base::Bind(callback, status)); |
604 } | 597 } |
605 } | 598 } |
606 | 599 |
607 void ServiceWorkerVersion::DispatchPushEvent(const StatusCallback& callback, | 600 void ServiceWorkerVersion::DispatchPushEvent(const StatusCallback& callback, |
608 const std::string& data) { | 601 const std::string& data) { |
609 DCHECK_EQ(ACTIVATED, status()) << status(); | 602 DCHECK_EQ(ACTIVATED, status()) << status(); |
610 | |
611 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( | |
612 switches::kEnableExperimentalWebPlatformFeatures)) { | |
613 callback.Run(SERVICE_WORKER_ERROR_ABORT); | |
614 return; | |
615 } | |
616 | |
617 if (running_status() != RUNNING) { | 603 if (running_status() != RUNNING) { |
618 // Schedule calling this method after starting the worker. | 604 // Schedule calling this method after starting the worker. |
619 StartWorker(base::Bind(&RunTaskAfterStartWorker, | 605 StartWorker(base::Bind(&RunTaskAfterStartWorker, |
620 weak_factory_.GetWeakPtr(), callback, | 606 weak_factory_.GetWeakPtr(), callback, |
621 base::Bind(&self::DispatchPushEvent, | 607 base::Bind(&self::DispatchPushEvent, |
622 weak_factory_.GetWeakPtr(), | 608 weak_factory_.GetWeakPtr(), |
623 callback, data))); | 609 callback, data))); |
624 return; | 610 return; |
625 } | 611 } |
626 | 612 |
(...skipping 795 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1422 int request_id) { | 1408 int request_id) { |
1423 callbacks->Remove(request_id); | 1409 callbacks->Remove(request_id); |
1424 if (is_doomed_) { | 1410 if (is_doomed_) { |
1425 // The stop should be already scheduled, but try to stop immediately, in | 1411 // The stop should be already scheduled, but try to stop immediately, in |
1426 // order to release worker resources soon. | 1412 // order to release worker resources soon. |
1427 StopWorkerIfIdle(); | 1413 StopWorkerIfIdle(); |
1428 } | 1414 } |
1429 } | 1415 } |
1430 | 1416 |
1431 } // namespace content | 1417 } // namespace content |
OLD | NEW |