Chromium Code Reviews| 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 <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 104 } | 104 } |
| 105 | 105 |
| 106 void ReceivePrepareResult(bool* is_prepared) { | 106 void ReceivePrepareResult(bool* is_prepared) { |
| 107 *is_prepared = true; | 107 *is_prepared = true; |
| 108 } | 108 } |
| 109 | 109 |
| 110 base::Closure CreatePrepareReceiver(bool* is_prepared) { | 110 base::Closure CreatePrepareReceiver(bool* is_prepared) { |
| 111 return base::Bind(&ReceivePrepareResult, is_prepared); | 111 return base::Bind(&ReceivePrepareResult, is_prepared); |
| 112 } | 112 } |
| 113 | 113 |
| 114 // Contrary to the style guide, the output parameter of this function comes | |
| 115 // before input parameters so Bind can be used on it to create a FetchCallback | |
| 116 // to pass to DispatchFetchEvent. | |
| 117 void ReceiveFetchResult(BrowserThread::ID run_quit_thread, | |
| 118 const base::Closure& quit, | |
| 119 ChromeBlobStorageContext* blob_context, | |
| 120 FetchResult* out_result, | |
| 121 ServiceWorkerStatusCode actual_status, | |
| 122 ServiceWorkerFetchEventResult actual_result, | |
| 123 const ServiceWorkerResponse& actual_response, | |
| 124 const scoped_refptr<ServiceWorkerVersion>& worker) { | |
| 125 out_result->status = actual_status; | |
| 126 out_result->result = actual_result; | |
| 127 out_result->response = actual_response; | |
| 128 if (!actual_response.blob_uuid.empty()) { | |
| 129 out_result->blob_data_handle = | |
| 130 blob_context->context()->GetBlobDataFromUUID( | |
| 131 actual_response.blob_uuid); | |
| 132 } | |
| 133 if (!quit.is_null()) | |
| 134 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, quit); | |
| 135 } | |
| 136 | |
| 137 ServiceWorkerFetchDispatcher::FetchCallback CreateResponseReceiver( | |
| 138 BrowserThread::ID run_quit_thread, | |
| 139 const base::Closure& quit, | |
| 140 ChromeBlobStorageContext* blob_context, | |
| 141 FetchResult* result) { | |
| 142 return base::Bind(&ReceiveFetchResult, run_quit_thread, quit, | |
| 143 make_scoped_refptr<ChromeBlobStorageContext>(blob_context), | |
| 144 result); | |
| 145 } | |
| 146 | |
| 147 void ReceiveFindRegistrationStatus( | 114 void ReceiveFindRegistrationStatus( |
| 148 BrowserThread::ID run_quit_thread, | 115 BrowserThread::ID run_quit_thread, |
| 149 const base::Closure& quit, | 116 const base::Closure& quit, |
| 150 ServiceWorkerStatusCode* out_status, | 117 ServiceWorkerStatusCode* out_status, |
| 151 ServiceWorkerStatusCode status, | 118 ServiceWorkerStatusCode status, |
| 152 const scoped_refptr<ServiceWorkerRegistration>& registration) { | 119 const scoped_refptr<ServiceWorkerRegistration>& registration) { |
| 153 *out_status = status; | 120 *out_status = status; |
| 154 if (!quit.is_null()) | 121 if (!quit.is_null()) |
| 155 BrowserThread::PostTask(run_quit_thread, FROM_HERE, quit); | 122 BrowserThread::PostTask(run_quit_thread, FROM_HERE, quit); |
| 156 } | 123 } |
| (...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 443 base::RunLoop fetch_run_loop; | 410 base::RunLoop fetch_run_loop; |
| 444 BrowserThread::PostTask(BrowserThread::IO, | 411 BrowserThread::PostTask(BrowserThread::IO, |
| 445 FROM_HERE, | 412 FROM_HERE, |
| 446 base::Bind(&self::FetchOnIOThread, | 413 base::Bind(&self::FetchOnIOThread, |
| 447 this, | 414 this, |
| 448 fetch_run_loop.QuitClosure(), | 415 fetch_run_loop.QuitClosure(), |
| 449 &prepare_result, | 416 &prepare_result, |
| 450 &fetch_result)); | 417 &fetch_result)); |
| 451 fetch_run_loop.Run(); | 418 fetch_run_loop.Run(); |
| 452 ASSERT_TRUE(prepare_result); | 419 ASSERT_TRUE(prepare_result); |
| 453 ASSERT_TRUE(fetch_dispatcher_); | |
| 454 *result = fetch_result.result; | 420 *result = fetch_result.result; |
| 455 *response = fetch_result.response; | 421 *response = fetch_result.response; |
| 456 *blob_data_handle = std::move(fetch_result.blob_data_handle); | 422 *blob_data_handle = std::move(fetch_result.blob_data_handle); |
| 457 fetch_dispatcher_.reset(); | |
| 458 ASSERT_EQ(SERVICE_WORKER_OK, fetch_result.status); | 423 ASSERT_EQ(SERVICE_WORKER_OK, fetch_result.status); |
| 459 } | 424 } |
| 460 | 425 |
| 461 void FetchTestHelper(const std::string& worker_url, | 426 void FetchTestHelper(const std::string& worker_url, |
| 462 ServiceWorkerFetchEventResult* result, | 427 ServiceWorkerFetchEventResult* result, |
| 463 ServiceWorkerResponse* response, | 428 ServiceWorkerResponse* response, |
| 464 scoped_ptr<storage::BlobDataHandle>* blob_data_handle) { | 429 scoped_ptr<storage::BlobDataHandle>* blob_data_handle) { |
| 465 RunOnIOThread( | 430 RunOnIOThread( |
| 466 base::Bind(&self::SetUpRegistrationOnIOThread, this, worker_url)); | 431 base::Bind(&self::SetUpRegistrationOnIOThread, this, worker_url)); |
| 467 FetchOnRegisteredWorker(result, response, blob_data_handle); | 432 FetchOnRegisteredWorker(result, response, blob_data_handle); |
| (...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 658 bool* prepare_result, | 623 bool* prepare_result, |
| 659 FetchResult* result) { | 624 FetchResult* result) { |
| 660 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 625 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 661 scoped_ptr<ServiceWorkerFetchRequest> request(new ServiceWorkerFetchRequest( | 626 scoped_ptr<ServiceWorkerFetchRequest> request(new ServiceWorkerFetchRequest( |
| 662 embedded_test_server()->GetURL("/service_worker/empty.html"), "GET", | 627 embedded_test_server()->GetURL("/service_worker/empty.html"), "GET", |
| 663 ServiceWorkerHeaderMap(), Referrer(), false)); | 628 ServiceWorkerHeaderMap(), Referrer(), false)); |
| 664 version_->SetStatus(ServiceWorkerVersion::ACTIVATED); | 629 version_->SetStatus(ServiceWorkerVersion::ACTIVATED); |
| 665 fetch_dispatcher_.reset(new ServiceWorkerFetchDispatcher( | 630 fetch_dispatcher_.reset(new ServiceWorkerFetchDispatcher( |
| 666 std::move(request), version_.get(), | 631 std::move(request), version_.get(), |
| 667 CreatePrepareReceiver(prepare_result), | 632 CreatePrepareReceiver(prepare_result), |
| 668 CreateResponseReceiver(BrowserThread::UI, done, blob_context_.get(), | 633 CreateResponseReceiver(done, blob_context_.get(), result))); |
| 669 result))); | |
| 670 fetch_dispatcher_->Run(); | 634 fetch_dispatcher_->Run(); |
| 671 } | 635 } |
| 672 | 636 |
| 637 // Contrary to the style guide, the output parameter of this function comes | |
| 638 // before input parameters so Bind can be used on it to create a FetchCallback | |
| 639 // to pass to DispatchFetchEvent. | |
| 640 void ReceiveFetchResultOnIOThread( | |
| 641 const base::Closure& quit, | |
| 642 ChromeBlobStorageContext* blob_context, | |
| 643 FetchResult* out_result, | |
| 644 ServiceWorkerStatusCode actual_status, | |
| 645 ServiceWorkerFetchEventResult actual_result, | |
| 646 const ServiceWorkerResponse& actual_response, | |
| 647 const scoped_refptr<ServiceWorkerVersion>& worker) { | |
|
nhiroki
2016/03/01 05:58:15
ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThre
horo
2016/03/01 07:02:23
Done.
| |
| 648 ASSERT_TRUE(fetch_dispatcher_); | |
| 649 fetch_dispatcher_.reset(); | |
| 650 out_result->status = actual_status; | |
| 651 out_result->result = actual_result; | |
| 652 out_result->response = actual_response; | |
| 653 if (!actual_response.blob_uuid.empty()) { | |
| 654 out_result->blob_data_handle = | |
| 655 blob_context->context()->GetBlobDataFromUUID( | |
| 656 actual_response.blob_uuid); | |
| 657 } | |
| 658 if (!quit.is_null()) | |
| 659 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, quit); | |
| 660 } | |
| 661 | |
| 662 ServiceWorkerFetchDispatcher::FetchCallback CreateResponseReceiver( | |
| 663 const base::Closure& quit, | |
| 664 ChromeBlobStorageContext* blob_context, | |
| 665 FetchResult* result) { | |
| 666 return base::Bind( | |
| 667 &self::ReceiveFetchResultOnIOThread, this, quit, | |
| 668 make_scoped_refptr<ChromeBlobStorageContext>(blob_context), result); | |
| 669 } | |
| 670 | |
| 673 void StopOnIOThread(const base::Closure& done, | 671 void StopOnIOThread(const base::Closure& done, |
| 674 ServiceWorkerStatusCode* result) { | 672 ServiceWorkerStatusCode* result) { |
| 675 ASSERT_TRUE(version_.get()); | 673 ASSERT_TRUE(version_.get()); |
| 676 version_->StopWorker(CreateReceiver(BrowserThread::UI, done, result)); | 674 version_->StopWorker(CreateReceiver(BrowserThread::UI, done, result)); |
| 677 } | 675 } |
| 678 | 676 |
| 679 protected: | 677 protected: |
| 680 scoped_refptr<ServiceWorkerRegistration> registration_; | 678 scoped_refptr<ServiceWorkerRegistration> registration_; |
| 681 scoped_refptr<ServiceWorkerVersion> version_; | 679 scoped_refptr<ServiceWorkerVersion> version_; |
| 682 scoped_refptr<ChromeBlobStorageContext> blob_context_; | 680 scoped_refptr<ChromeBlobStorageContext> blob_context_; |
| (...skipping 629 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1312 ASSERT_EQ(SERVICE_WORKER_OK, status); | 1310 ASSERT_EQ(SERVICE_WORKER_OK, status); |
| 1313 // Stop the worker. | 1311 // Stop the worker. |
| 1314 StopWorker(SERVICE_WORKER_OK); | 1312 StopWorker(SERVICE_WORKER_OK); |
| 1315 // Restart the worker. | 1313 // Restart the worker. |
| 1316 StartWorker(SERVICE_WORKER_OK); | 1314 StartWorker(SERVICE_WORKER_OK); |
| 1317 // Stop the worker. | 1315 // Stop the worker. |
| 1318 StopWorker(SERVICE_WORKER_OK); | 1316 StopWorker(SERVICE_WORKER_OK); |
| 1319 } | 1317 } |
| 1320 | 1318 |
| 1321 } // namespace content | 1319 } // namespace content |
| OLD | NEW |