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 "base/basictypes.h" | 5 #include "base/basictypes.h" |
| 6 #include "base/memory/weak_ptr.h" | 6 #include "base/memory/weak_ptr.h" |
| 7 #include "content/browser/service_worker/service_worker_context_core.h" | 7 #include "content/browser/service_worker/service_worker_context_core.h" |
| 8 #include "content/browser/service_worker/service_worker_provider_host.h" | 8 #include "content/browser/service_worker/service_worker_provider_host.h" |
| 9 #include "content/browser/service_worker/service_worker_register_job.h" | 9 #include "content/browser/service_worker/service_worker_register_job.h" |
| 10 #include "content/browser/service_worker/service_worker_registration.h" | 10 #include "content/browser/service_worker/service_worker_registration.h" |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 40 registration_, | 40 registration_, |
| 41 1L, context_->AsWeakPtr()); | 41 1L, context_->AsWeakPtr()); |
| 42 | 42 |
| 43 // Prepare provider hosts (for the same process). | 43 // Prepare provider hosts (for the same process). |
| 44 scoped_ptr<ServiceWorkerProviderHost> host1(new ServiceWorkerProviderHost( | 44 scoped_ptr<ServiceWorkerProviderHost> host1(new ServiceWorkerProviderHost( |
| 45 kRenderProcessId, 1 /* provider_id */, | 45 kRenderProcessId, 1 /* provider_id */, |
| 46 context_->AsWeakPtr(), NULL)); | 46 context_->AsWeakPtr(), NULL)); |
| 47 scoped_ptr<ServiceWorkerProviderHost> host2(new ServiceWorkerProviderHost( | 47 scoped_ptr<ServiceWorkerProviderHost> host2(new ServiceWorkerProviderHost( |
| 48 kRenderProcessId, 2 /* provider_id */, | 48 kRenderProcessId, 2 /* provider_id */, |
| 49 context_->AsWeakPtr(), NULL)); | 49 context_->AsWeakPtr(), NULL)); |
| 50 host1->AssociateRegistration(registration_); | |
| 51 host2->AssociateRegistration(registration_); | |
| 50 provider_host1_ = host1->AsWeakPtr(); | 52 provider_host1_ = host1->AsWeakPtr(); |
| 51 provider_host2_ = host2->AsWeakPtr(); | 53 provider_host2_ = host2->AsWeakPtr(); |
| 52 context_->AddProviderHost(make_scoped_ptr(host1.release())); | 54 context_->AddProviderHost(make_scoped_ptr(host1.release())); |
| 53 context_->AddProviderHost(make_scoped_ptr(host2.release())); | 55 context_->AddProviderHost(make_scoped_ptr(host2.release())); |
| 54 } | 56 } |
| 55 | 57 |
| 56 virtual void TearDown() OVERRIDE { | 58 virtual void TearDown() OVERRIDE { |
| 57 version_ = 0; | 59 version_ = 0; |
| 58 registration_ = 0; | 60 registration_ = 0; |
| 59 context_.reset(); | 61 context_.reset(); |
| 60 } | 62 } |
| 61 | 63 |
| 62 void SetActiveVersion( | 64 void SetActiveVersion( |
|
michaeln
2014/08/11 22:15:41
would it make sense to use the public ServiceWorke
nhiroki
2014/08/12 01:45:56
Done.
| |
| 63 base::WeakPtr<ServiceWorkerProviderHost> provider_host, | 65 base::WeakPtr<ServiceWorkerProviderHost> provider_host, |
| 64 ServiceWorkerVersion* version) { | 66 ServiceWorkerVersion* active_version) { |
| 65 provider_host->SetActiveVersion(version); | 67 provider_host->SetVersionAttributes( |
| 68 provider_host->installing_version(), | |
| 69 provider_host->waiting_version(), | |
| 70 active_version); | |
| 66 } | 71 } |
| 67 | 72 |
| 68 void SetWaitingVersion( | 73 void SetWaitingVersion( |
| 69 base::WeakPtr<ServiceWorkerProviderHost> provider_host, | 74 base::WeakPtr<ServiceWorkerProviderHost> provider_host, |
| 70 ServiceWorkerVersion* version) { | 75 ServiceWorkerVersion* waiting_version) { |
| 71 provider_host->SetWaitingVersion(version); | 76 provider_host->SetVersionAttributes( |
| 77 provider_host->installing_version(), | |
| 78 waiting_version, | |
| 79 provider_host->active_version()); | |
| 72 } | 80 } |
| 73 | 81 |
| 74 content::TestBrowserThreadBundle thread_bundle_; | 82 content::TestBrowserThreadBundle thread_bundle_; |
| 75 scoped_ptr<ServiceWorkerContextCore> context_; | 83 scoped_ptr<ServiceWorkerContextCore> context_; |
| 76 scoped_refptr<ServiceWorkerRegistration> registration_; | 84 scoped_refptr<ServiceWorkerRegistration> registration_; |
| 77 scoped_refptr<ServiceWorkerVersion> version_; | 85 scoped_refptr<ServiceWorkerVersion> version_; |
| 78 base::WeakPtr<ServiceWorkerProviderHost> provider_host1_; | 86 base::WeakPtr<ServiceWorkerProviderHost> provider_host1_; |
| 79 base::WeakPtr<ServiceWorkerProviderHost> provider_host2_; | 87 base::WeakPtr<ServiceWorkerProviderHost> provider_host2_; |
| 80 GURL scope_; | 88 GURL scope_; |
| 81 GURL script_url_; | 89 GURL script_url_; |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 106 SetActiveVersion_MultipleHostsForSameProcess) { | 114 SetActiveVersion_MultipleHostsForSameProcess) { |
| 107 ASSERT_FALSE(version_->HasProcessToRun()); | 115 ASSERT_FALSE(version_->HasProcessToRun()); |
| 108 | 116 |
| 109 // Associating version_ to two providers as active version. | 117 // Associating version_ to two providers as active version. |
| 110 SetActiveVersion(provider_host1_, version_); | 118 SetActiveVersion(provider_host1_, version_); |
| 111 SetActiveVersion(provider_host2_, version_); | 119 SetActiveVersion(provider_host2_, version_); |
| 112 ASSERT_TRUE(version_->HasProcessToRun()); | 120 ASSERT_TRUE(version_->HasProcessToRun()); |
| 113 | 121 |
| 114 // Disassociating one provider_host shouldn't remove all process refs | 122 // Disassociating one provider_host shouldn't remove all process refs |
| 115 // from the version yet. | 123 // from the version yet. |
| 116 SetActiveVersion(provider_host1_, NULL); | 124 SetActiveVersion(provider_host1_, NULL); |
|
michaeln
2014/08/11 22:15:41
This can be accomplished with the public host->Una
nhiroki
2014/08/12 01:45:56
Done.
| |
| 117 ASSERT_TRUE(version_->HasProcessToRun()); | 125 ASSERT_TRUE(version_->HasProcessToRun()); |
| 118 | 126 |
| 119 // Disassociating the other provider_host will remove all process refs. | 127 // Disassociating the other provider_host will remove all process refs. |
| 120 SetActiveVersion(provider_host2_, NULL); | 128 SetActiveVersion(provider_host2_, NULL); |
| 121 ASSERT_FALSE(version_->HasProcessToRun()); | 129 ASSERT_FALSE(version_->HasProcessToRun()); |
| 122 } | 130 } |
| 123 | 131 |
| 124 TEST_F(ServiceWorkerProviderHostTest, SetWaitingVersion_ProcessStatus) { | 132 TEST_F(ServiceWorkerProviderHostTest, SetWaitingVersion_ProcessStatus) { |
| 125 ASSERT_FALSE(version_->HasProcessToRun()); | 133 ASSERT_FALSE(version_->HasProcessToRun()); |
| 126 | 134 |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 152 // from the version yet. | 160 // from the version yet. |
| 153 SetWaitingVersion(provider_host1_, NULL); | 161 SetWaitingVersion(provider_host1_, NULL); |
| 154 ASSERT_TRUE(version_->HasProcessToRun()); | 162 ASSERT_TRUE(version_->HasProcessToRun()); |
| 155 | 163 |
| 156 // Disassociating the other provider_host will remove all process refs. | 164 // Disassociating the other provider_host will remove all process refs. |
| 157 SetWaitingVersion(provider_host2_, NULL); | 165 SetWaitingVersion(provider_host2_, NULL); |
| 158 ASSERT_FALSE(version_->HasProcessToRun()); | 166 ASSERT_FALSE(version_->HasProcessToRun()); |
| 159 } | 167 } |
| 160 | 168 |
| 161 } // namespace content | 169 } // namespace content |
| OLD | NEW |