| 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/bind.h" | 5 #include "base/bind.h" |
| 6 #include "base/callback.h" | 6 #include "base/callback.h" |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/run_loop.h" | 8 #include "base/run_loop.h" |
| 9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 10 #include "content/browser/fileapi/chrome_blob_storage_context.h" | 10 #include "content/browser/fileapi/chrome_blob_storage_context.h" |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 153 public: | 153 public: |
| 154 explicit WorkerActivatedObserver(ServiceWorkerContextWrapper* context) | 154 explicit WorkerActivatedObserver(ServiceWorkerContextWrapper* context) |
| 155 : context_(context) {} | 155 : context_(context) {} |
| 156 void Init() { | 156 void Init() { |
| 157 RunOnIOThread(base::Bind(&WorkerActivatedObserver::InitOnIOThread, this)); | 157 RunOnIOThread(base::Bind(&WorkerActivatedObserver::InitOnIOThread, this)); |
| 158 } | 158 } |
| 159 // ServiceWorkerContextObserver overrides. | 159 // ServiceWorkerContextObserver overrides. |
| 160 void OnVersionStateChanged(int64 version_id, | 160 void OnVersionStateChanged(int64 version_id, |
| 161 ServiceWorkerVersion::Status) override { | 161 ServiceWorkerVersion::Status) override { |
| 162 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 162 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 163 const ServiceWorkerVersion* version = | 163 const ServiceWorkerVersion* version = context_->GetLiveVersion(version_id); |
| 164 context_->context()->GetLiveVersion(version_id); | |
| 165 if (version->status() == ServiceWorkerVersion::ACTIVATED) { | 164 if (version->status() == ServiceWorkerVersion::ACTIVATED) { |
| 166 context_->RemoveObserver(this); | 165 context_->RemoveObserver(this); |
| 167 BrowserThread::PostTask(BrowserThread::UI, | 166 BrowserThread::PostTask(BrowserThread::UI, |
| 168 FROM_HERE, | 167 FROM_HERE, |
| 169 base::Bind(&WorkerActivatedObserver::Quit, this)); | 168 base::Bind(&WorkerActivatedObserver::Quit, this)); |
| 170 } | 169 } |
| 171 } | 170 } |
| 172 void Wait() { run_loop_.Run(); } | 171 void Wait() { run_loop_.Run(); } |
| 173 | 172 |
| 174 private: | 173 private: |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 242 import_url, interceptor.Pass()); | 241 import_url, interceptor.Pass()); |
| 243 } | 242 } |
| 244 | 243 |
| 245 void CountScriptResources( | 244 void CountScriptResources( |
| 246 ServiceWorkerContextWrapper* wrapper, | 245 ServiceWorkerContextWrapper* wrapper, |
| 247 const GURL& scope, | 246 const GURL& scope, |
| 248 int* num_resources) { | 247 int* num_resources) { |
| 249 *num_resources = -1; | 248 *num_resources = -1; |
| 250 | 249 |
| 251 std::vector<ServiceWorkerRegistrationInfo> infos = | 250 std::vector<ServiceWorkerRegistrationInfo> infos = |
| 252 wrapper->context()->GetAllLiveRegistrationInfo(); | 251 wrapper->GetAllLiveRegistrationInfo(); |
| 253 if (infos.empty()) | 252 if (infos.empty()) |
| 254 return; | 253 return; |
| 255 | 254 |
| 256 int version_id; | 255 int version_id; |
| 257 size_t index = infos.size() - 1; | 256 size_t index = infos.size() - 1; |
| 258 if (infos[index].installing_version.version_id != | 257 if (infos[index].installing_version.version_id != |
| 259 kInvalidServiceWorkerVersionId) | 258 kInvalidServiceWorkerVersionId) |
| 260 version_id = infos[index].installing_version.version_id; | 259 version_id = infos[index].installing_version.version_id; |
| 261 else if (infos[index].waiting_version.version_id != | 260 else if (infos[index].waiting_version.version_id != |
| 262 kInvalidServiceWorkerVersionId) | 261 kInvalidServiceWorkerVersionId) |
| 263 version_id = infos[1].waiting_version.version_id; | 262 version_id = infos[1].waiting_version.version_id; |
| 264 else if (infos[index].active_version.version_id != | 263 else if (infos[index].active_version.version_id != |
| 265 kInvalidServiceWorkerVersionId) | 264 kInvalidServiceWorkerVersionId) |
| 266 version_id = infos[index].active_version.version_id; | 265 version_id = infos[index].active_version.version_id; |
| 267 else | 266 else |
| 268 return; | 267 return; |
| 269 | 268 |
| 270 ServiceWorkerVersion* version = | 269 ServiceWorkerVersion* version = wrapper->GetLiveVersion(version_id); |
| 271 wrapper->context()->GetLiveVersion(version_id); | |
| 272 *num_resources = static_cast<int>(version->script_cache_map()->size()); | 270 *num_resources = static_cast<int>(version->script_cache_map()->size()); |
| 273 } | 271 } |
| 274 | 272 |
| 275 } // namespace | 273 } // namespace |
| 276 | 274 |
| 277 class ServiceWorkerBrowserTest : public ContentBrowserTest { | 275 class ServiceWorkerBrowserTest : public ContentBrowserTest { |
| 278 protected: | 276 protected: |
| 279 using self = ServiceWorkerBrowserTest; | 277 using self = ServiceWorkerBrowserTest; |
| 280 | 278 |
| 281 void SetUpCommandLine(base::CommandLine* command_line) override { | 279 void SetUpCommandLine(base::CommandLine* command_line) override { |
| (...skipping 722 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1004 EXPECT_EQ(kExpectedNumResources, num_resources); | 1002 EXPECT_EQ(kExpectedNumResources, num_resources); |
| 1005 } | 1003 } |
| 1006 | 1004 |
| 1007 class ServiceWorkerBlackBoxBrowserTest : public ServiceWorkerBrowserTest { | 1005 class ServiceWorkerBlackBoxBrowserTest : public ServiceWorkerBrowserTest { |
| 1008 public: | 1006 public: |
| 1009 using self = ServiceWorkerBlackBoxBrowserTest; | 1007 using self = ServiceWorkerBlackBoxBrowserTest; |
| 1010 | 1008 |
| 1011 void FindRegistrationOnIO(const GURL& document_url, | 1009 void FindRegistrationOnIO(const GURL& document_url, |
| 1012 ServiceWorkerStatusCode* status, | 1010 ServiceWorkerStatusCode* status, |
| 1013 const base::Closure& continuation) { | 1011 const base::Closure& continuation) { |
| 1014 wrapper()->context()->storage()->FindRegistrationForDocument( | 1012 wrapper()->FindRegistrationForDocument( |
| 1015 document_url, | 1013 document_url, |
| 1016 base::Bind(&ServiceWorkerBlackBoxBrowserTest::FindRegistrationOnIO2, | 1014 base::Bind(&ServiceWorkerBlackBoxBrowserTest::FindRegistrationOnIO2, |
| 1017 this, | 1015 this, status, continuation)); |
| 1018 status, | |
| 1019 continuation)); | |
| 1020 } | 1016 } |
| 1021 | 1017 |
| 1022 void FindRegistrationOnIO2( | 1018 void FindRegistrationOnIO2( |
| 1023 ServiceWorkerStatusCode* out_status, | 1019 ServiceWorkerStatusCode* out_status, |
| 1024 const base::Closure& continuation, | 1020 const base::Closure& continuation, |
| 1025 ServiceWorkerStatusCode status, | 1021 ServiceWorkerStatusCode status, |
| 1026 const scoped_refptr<ServiceWorkerRegistration>& registration) { | 1022 const scoped_refptr<ServiceWorkerRegistration>& registration) { |
| 1027 *out_status = status; | 1023 *out_status = status; |
| 1028 if (!registration.get()) | 1024 if (!registration.get()) |
| 1029 EXPECT_NE(SERVICE_WORKER_OK, status); | 1025 EXPECT_NE(SERVICE_WORKER_OK, status); |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1204 ASSERT_EQ(SERVICE_WORKER_OK, status); | 1200 ASSERT_EQ(SERVICE_WORKER_OK, status); |
| 1205 // Stop the worker. | 1201 // Stop the worker. |
| 1206 StopWorker(SERVICE_WORKER_OK); | 1202 StopWorker(SERVICE_WORKER_OK); |
| 1207 // Restart the worker. | 1203 // Restart the worker. |
| 1208 StartWorker(SERVICE_WORKER_OK); | 1204 StartWorker(SERVICE_WORKER_OK); |
| 1209 // Stop the worker. | 1205 // Stop the worker. |
| 1210 StopWorker(SERVICE_WORKER_OK); | 1206 StopWorker(SERVICE_WORKER_OK); |
| 1211 } | 1207 } |
| 1212 | 1208 |
| 1213 } // namespace content | 1209 } // namespace content |
| OLD | NEW |