| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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 <stddef.h> | 5 #include <stddef.h> |
| 6 #include <stdint.h> | 6 #include <stdint.h> |
| 7 #include <map> | 7 #include <map> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 23 matching lines...) Expand all Loading... |
| 34 #include "content/public/browser/browser_thread.h" | 34 #include "content/public/browser/browser_thread.h" |
| 35 #include "content/public/browser/content_browser_client.h" | 35 #include "content/public/browser/content_browser_client.h" |
| 36 #include "content/public/browser/navigation_entry.h" | 36 #include "content/public/browser/navigation_entry.h" |
| 37 #include "content/public/browser/render_process_host.h" | 37 #include "content/public/browser/render_process_host.h" |
| 38 #include "content/public/browser/render_view_host.h" | 38 #include "content/public/browser/render_view_host.h" |
| 39 #include "content/public/browser/storage_partition.h" | 39 #include "content/public/browser/storage_partition.h" |
| 40 #include "content/public/browser/web_contents.h" | 40 #include "content/public/browser/web_contents.h" |
| 41 #include "content/public/common/content_client.h" | 41 #include "content/public/common/content_client.h" |
| 42 #include "content/public/common/content_switches.h" | 42 #include "content/public/common/content_switches.h" |
| 43 #include "content/public/common/referrer.h" | 43 #include "content/public/common/referrer.h" |
| 44 #include "content/public/common/resource_type.h" |
| 44 #include "content/public/common/security_style.h" | 45 #include "content/public/common/security_style.h" |
| 45 #include "content/public/common/ssl_status.h" | 46 #include "content/public/common/ssl_status.h" |
| 46 #include "content/public/common/web_preferences.h" | 47 #include "content/public/common/web_preferences.h" |
| 47 #include "content/public/test/browser_test_utils.h" | 48 #include "content/public/test/browser_test_utils.h" |
| 48 #include "content/public/test/content_browser_test.h" | 49 #include "content/public/test/content_browser_test.h" |
| 49 #include "content/public/test/content_browser_test_utils.h" | 50 #include "content/public/test/content_browser_test_utils.h" |
| 50 #include "content/shell/browser/shell.h" | 51 #include "content/shell/browser/shell.h" |
| 51 #include "content/shell/browser/shell_content_browser_client.h" | 52 #include "content/shell/browser/shell_content_browser_client.h" |
| 52 #include "content/test/test_content_browser_client.h" | 53 #include "content/test/test_content_browser_client.h" |
| 53 #include "net/test/embedded_test_server/embedded_test_server.h" | 54 #include "net/test/embedded_test_server/embedded_test_server.h" |
| (...skipping 540 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 594 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 595 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 595 version_->StartWorker(CreateReceiver(BrowserThread::UI, done, result)); | 596 version_->StartWorker(CreateReceiver(BrowserThread::UI, done, result)); |
| 596 } | 597 } |
| 597 | 598 |
| 598 void InstallOnIOThread(const base::Closure& done, | 599 void InstallOnIOThread(const base::Closure& done, |
| 599 ServiceWorkerStatusCode* result) { | 600 ServiceWorkerStatusCode* result) { |
| 600 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 601 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 601 version_->SetStatus(ServiceWorkerVersion::INSTALLING); | 602 version_->SetStatus(ServiceWorkerVersion::INSTALLING); |
| 602 version_->RunAfterStartWorker( | 603 version_->RunAfterStartWorker( |
| 603 base::Bind(&self::DispatchInstallEventOnIOThread, this, done, result), | 604 base::Bind(&self::DispatchInstallEventOnIOThread, this, done, result), |
| 604 CreateReceiver(BrowserThread::UI, done, result)); | 605 CreateReceiver(BrowserThread::UI, done, result), |
| 606 ServiceWorkerMetrics::EventType::INSTALL); |
| 605 } | 607 } |
| 606 | 608 |
| 607 void DispatchInstallEventOnIOThread(const base::Closure& done, | 609 void DispatchInstallEventOnIOThread(const base::Closure& done, |
| 608 ServiceWorkerStatusCode* result) { | 610 ServiceWorkerStatusCode* result) { |
| 609 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 611 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 610 int request_id = | 612 int request_id = |
| 611 version_->StartRequest(ServiceWorkerMetrics::EventType::INSTALL, | 613 version_->StartRequest(ServiceWorkerMetrics::EventType::INSTALL, |
| 612 CreateReceiver(BrowserThread::UI, done, result)); | 614 CreateReceiver(BrowserThread::UI, done, result)); |
| 613 version_->DispatchSimpleEvent<ServiceWorkerHostMsg_InstallEventFinished>( | 615 version_->DispatchSimpleEvent<ServiceWorkerHostMsg_InstallEventFinished>( |
| 614 request_id, ServiceWorkerMsg_InstallEvent(request_id)); | 616 request_id, ServiceWorkerMsg_InstallEvent(request_id)); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 625 CreateReceiver(BrowserThread::UI, done, result)); | 627 CreateReceiver(BrowserThread::UI, done, result)); |
| 626 } | 628 } |
| 627 | 629 |
| 628 void ActivateOnIOThread(const base::Closure& done, | 630 void ActivateOnIOThread(const base::Closure& done, |
| 629 ServiceWorkerStatusCode* result) { | 631 ServiceWorkerStatusCode* result) { |
| 630 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 632 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 631 version_->SetStatus(ServiceWorkerVersion::ACTIVATING); | 633 version_->SetStatus(ServiceWorkerVersion::ACTIVATING); |
| 632 registration_->SetActiveVersion(version_.get()); | 634 registration_->SetActiveVersion(version_.get()); |
| 633 version_->RunAfterStartWorker( | 635 version_->RunAfterStartWorker( |
| 634 base::Bind(&self::DispatchActivateEventOnIOThread, this, done, result), | 636 base::Bind(&self::DispatchActivateEventOnIOThread, this, done, result), |
| 635 CreateReceiver(BrowserThread::UI, done, result)); | 637 CreateReceiver(BrowserThread::UI, done, result), |
| 638 ServiceWorkerMetrics::EventType::ACTIVATE); |
| 636 } | 639 } |
| 637 | 640 |
| 638 void DispatchActivateEventOnIOThread(const base::Closure& done, | 641 void DispatchActivateEventOnIOThread(const base::Closure& done, |
| 639 ServiceWorkerStatusCode* result) { | 642 ServiceWorkerStatusCode* result) { |
| 640 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 643 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 641 int request_id = | 644 int request_id = |
| 642 version_->StartRequest(ServiceWorkerMetrics::EventType::INSTALL, | 645 version_->StartRequest(ServiceWorkerMetrics::EventType::INSTALL, |
| 643 CreateReceiver(BrowserThread::UI, done, result)); | 646 CreateReceiver(BrowserThread::UI, done, result)); |
| 644 version_->DispatchSimpleEvent<ServiceWorkerHostMsg_ActivateEventFinished>( | 647 version_->DispatchSimpleEvent<ServiceWorkerHostMsg_ActivateEventFinished>( |
| 645 request_id, ServiceWorkerMsg_ActivateEvent(request_id)); | 648 request_id, ServiceWorkerMsg_ActivateEvent(request_id)); |
| 646 } | 649 } |
| 647 | 650 |
| 648 void FetchOnIOThread(const base::Closure& done, | 651 void FetchOnIOThread(const base::Closure& done, |
| 649 bool* prepare_result, | 652 bool* prepare_result, |
| 650 FetchResult* result) { | 653 FetchResult* result) { |
| 651 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 654 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 652 scoped_ptr<ServiceWorkerFetchRequest> request(new ServiceWorkerFetchRequest( | 655 scoped_ptr<ServiceWorkerFetchRequest> request(new ServiceWorkerFetchRequest( |
| 653 embedded_test_server()->GetURL("/service_worker/empty.html"), "GET", | 656 embedded_test_server()->GetURL("/service_worker/empty.html"), "GET", |
| 654 ServiceWorkerHeaderMap(), Referrer(), false)); | 657 ServiceWorkerHeaderMap(), Referrer(), false)); |
| 655 version_->SetStatus(ServiceWorkerVersion::ACTIVATED); | 658 version_->SetStatus(ServiceWorkerVersion::ACTIVATED); |
| 656 fetch_dispatcher_.reset(new ServiceWorkerFetchDispatcher( | 659 fetch_dispatcher_.reset(new ServiceWorkerFetchDispatcher( |
| 657 std::move(request), version_.get(), | 660 std::move(request), version_.get(), RESOURCE_TYPE_MAIN_FRAME, |
| 658 CreatePrepareReceiver(prepare_result), | 661 CreatePrepareReceiver(prepare_result), |
| 659 CreateResponseReceiver(done, blob_context_.get(), result))); | 662 CreateResponseReceiver(done, blob_context_.get(), result))); |
| 660 fetch_dispatcher_->Run(); | 663 fetch_dispatcher_->Run(); |
| 661 } | 664 } |
| 662 | 665 |
| 663 // Contrary to the style guide, the output parameter of this function comes | 666 // Contrary to the style guide, the output parameter of this function comes |
| 664 // before input parameters so Bind can be used on it to create a FetchCallback | 667 // before input parameters so Bind can be used on it to create a FetchCallback |
| 665 // to pass to DispatchFetchEvent. | 668 // to pass to DispatchFetchEvent. |
| 666 void ReceiveFetchResultOnIOThread( | 669 void ReceiveFetchResultOnIOThread( |
| 667 const base::Closure& quit, | 670 const base::Closure& quit, |
| (...skipping 816 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1484 ASSERT_EQ(SERVICE_WORKER_OK, status); | 1487 ASSERT_EQ(SERVICE_WORKER_OK, status); |
| 1485 // Stop the worker. | 1488 // Stop the worker. |
| 1486 StopWorker(SERVICE_WORKER_OK); | 1489 StopWorker(SERVICE_WORKER_OK); |
| 1487 // Restart the worker. | 1490 // Restart the worker. |
| 1488 StartWorker(SERVICE_WORKER_OK); | 1491 StartWorker(SERVICE_WORKER_OK); |
| 1489 // Stop the worker. | 1492 // Stop the worker. |
| 1490 StopWorker(SERVICE_WORKER_OK); | 1493 StopWorker(SERVICE_WORKER_OK); |
| 1491 } | 1494 } |
| 1492 | 1495 |
| 1493 } // namespace content | 1496 } // namespace content |
| OLD | NEW |