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_context_core.h" | 5 #include "content/browser/service_worker/service_worker_context_core.h" |
6 | 6 |
7 #include "base/files/file_path.h" | 7 #include "base/files/file_path.h" |
8 #include "base/single_thread_task_runner.h" | 8 #include "base/single_thread_task_runner.h" |
9 #include "base/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
10 #include "content/browser/service_worker/embedded_worker_registry.h" | 10 #include "content/browser/service_worker/embedded_worker_registry.h" |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 ServiceWorkerContextWrapper* wrapper) | 91 ServiceWorkerContextWrapper* wrapper) |
92 : weak_factory_(this), | 92 : weak_factory_(this), |
93 wrapper_(wrapper), | 93 wrapper_(wrapper), |
94 providers_(new ProcessToProviderMap), | 94 providers_(new ProcessToProviderMap), |
95 storage_(ServiceWorkerStorage::Create(path, | 95 storage_(ServiceWorkerStorage::Create(path, |
96 AsWeakPtr(), | 96 AsWeakPtr(), |
97 database_task_runner, | 97 database_task_runner, |
98 disk_cache_thread, | 98 disk_cache_thread, |
99 quota_manager_proxy)), | 99 quota_manager_proxy)), |
100 cache_manager_( | 100 cache_manager_( |
101 ServiceWorkerCacheStorageManager::Create(path, cache_task_runner)), | 101 ServiceWorkerCacheStorageManager::Create(path, |
| 102 cache_task_runner.get())), |
102 embedded_worker_registry_(EmbeddedWorkerRegistry::Create(AsWeakPtr())), | 103 embedded_worker_registry_(EmbeddedWorkerRegistry::Create(AsWeakPtr())), |
103 job_coordinator_(new ServiceWorkerJobCoordinator(AsWeakPtr())), | 104 job_coordinator_(new ServiceWorkerJobCoordinator(AsWeakPtr())), |
104 next_handle_id_(0), | 105 next_handle_id_(0), |
105 next_registration_handle_id_(0), | 106 next_registration_handle_id_(0), |
106 observer_list_(observer_list) { | 107 observer_list_(observer_list) { |
107 } | 108 } |
108 | 109 |
109 ServiceWorkerContextCore::ServiceWorkerContextCore( | 110 ServiceWorkerContextCore::ServiceWorkerContextCore( |
110 ServiceWorkerContextCore* old_context, | 111 ServiceWorkerContextCore* old_context, |
111 ServiceWorkerContextWrapper* wrapper) | 112 ServiceWorkerContextWrapper* wrapper) |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
235 kInvalidServiceWorkerRegistrationId, | 236 kInvalidServiceWorkerRegistrationId, |
236 kInvalidServiceWorkerVersionId); | 237 kInvalidServiceWorkerVersionId); |
237 return; | 238 return; |
238 } | 239 } |
239 | 240 |
240 DCHECK(version); | 241 DCHECK(version); |
241 DCHECK_EQ(version->registration_id(), registration->id()); | 242 DCHECK_EQ(version->registration_id(), registration->id()); |
242 callback.Run(status, | 243 callback.Run(status, |
243 registration->id(), | 244 registration->id(), |
244 version->version_id()); | 245 version->version_id()); |
245 if (observer_list_) { | 246 if (observer_list_.get()) { |
246 observer_list_->Notify(&ServiceWorkerContextObserver::OnRegistrationStored, | 247 observer_list_->Notify(&ServiceWorkerContextObserver::OnRegistrationStored, |
247 pattern); | 248 pattern); |
248 } | 249 } |
249 } | 250 } |
250 | 251 |
251 void ServiceWorkerContextCore::UnregistrationComplete( | 252 void ServiceWorkerContextCore::UnregistrationComplete( |
252 const GURL& pattern, | 253 const GURL& pattern, |
253 const ServiceWorkerContextCore::UnregistrationCallback& callback, | 254 const ServiceWorkerContextCore::UnregistrationCallback& callback, |
254 ServiceWorkerStatusCode status) { | 255 ServiceWorkerStatusCode status) { |
255 callback.Run(status); | 256 callback.Run(status); |
256 if (observer_list_) { | 257 if (observer_list_.get()) { |
257 observer_list_->Notify(&ServiceWorkerContextObserver::OnRegistrationDeleted, | 258 observer_list_->Notify(&ServiceWorkerContextObserver::OnRegistrationDeleted, |
258 pattern); | 259 pattern); |
259 } | 260 } |
260 } | 261 } |
261 | 262 |
262 ServiceWorkerRegistration* ServiceWorkerContextCore::GetLiveRegistration( | 263 ServiceWorkerRegistration* ServiceWorkerContextCore::GetLiveRegistration( |
263 int64 id) { | 264 int64 id) { |
264 RegistrationsMap::iterator it = live_registrations_.find(id); | 265 RegistrationsMap::iterator it = live_registrations_.find(id); |
265 return (it != live_registrations_.end()) ? it->second : NULL; | 266 return (it != live_registrations_.end()) ? it->second : NULL; |
266 } | 267 } |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
339 void ServiceWorkerContextCore::SetBlobParametersForCache( | 340 void ServiceWorkerContextCore::SetBlobParametersForCache( |
340 net::URLRequestContext* request_context, | 341 net::URLRequestContext* request_context, |
341 base::WeakPtr<storage::BlobStorageContext> blob_storage_context) { | 342 base::WeakPtr<storage::BlobStorageContext> blob_storage_context) { |
342 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 343 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
343 | 344 |
344 cache_manager_->SetBlobParametersForCache(request_context, | 345 cache_manager_->SetBlobParametersForCache(request_context, |
345 blob_storage_context); | 346 blob_storage_context); |
346 } | 347 } |
347 | 348 |
348 void ServiceWorkerContextCore::OnWorkerStarted(ServiceWorkerVersion* version) { | 349 void ServiceWorkerContextCore::OnWorkerStarted(ServiceWorkerVersion* version) { |
349 if (!observer_list_) | 350 if (!observer_list_.get()) |
350 return; | 351 return; |
351 observer_list_->Notify(&ServiceWorkerContextObserver::OnWorkerStarted, | 352 observer_list_->Notify(&ServiceWorkerContextObserver::OnWorkerStarted, |
352 version->version_id(), | 353 version->version_id(), |
353 version->embedded_worker()->process_id(), | 354 version->embedded_worker()->process_id(), |
354 version->embedded_worker()->thread_id()); | 355 version->embedded_worker()->thread_id()); |
355 } | 356 } |
356 | 357 |
357 void ServiceWorkerContextCore::OnWorkerStopped(ServiceWorkerVersion* version) { | 358 void ServiceWorkerContextCore::OnWorkerStopped(ServiceWorkerVersion* version) { |
358 if (!observer_list_) | 359 if (!observer_list_.get()) |
359 return; | 360 return; |
360 observer_list_->Notify(&ServiceWorkerContextObserver::OnWorkerStopped, | 361 observer_list_->Notify(&ServiceWorkerContextObserver::OnWorkerStopped, |
361 version->version_id(), | 362 version->version_id(), |
362 version->embedded_worker()->process_id(), | 363 version->embedded_worker()->process_id(), |
363 version->embedded_worker()->thread_id()); | 364 version->embedded_worker()->thread_id()); |
364 } | 365 } |
365 | 366 |
366 void ServiceWorkerContextCore::OnVersionStateChanged( | 367 void ServiceWorkerContextCore::OnVersionStateChanged( |
367 ServiceWorkerVersion* version) { | 368 ServiceWorkerVersion* version) { |
368 if (!observer_list_) | 369 if (!observer_list_.get()) |
369 return; | 370 return; |
370 observer_list_->Notify(&ServiceWorkerContextObserver::OnVersionStateChanged, | 371 observer_list_->Notify(&ServiceWorkerContextObserver::OnVersionStateChanged, |
371 version->version_id()); | 372 version->version_id()); |
372 } | 373 } |
373 | 374 |
374 void ServiceWorkerContextCore::OnErrorReported( | 375 void ServiceWorkerContextCore::OnErrorReported( |
375 ServiceWorkerVersion* version, | 376 ServiceWorkerVersion* version, |
376 const base::string16& error_message, | 377 const base::string16& error_message, |
377 int line_number, | 378 int line_number, |
378 int column_number, | 379 int column_number, |
379 const GURL& source_url) { | 380 const GURL& source_url) { |
380 if (!observer_list_) | 381 if (!observer_list_.get()) |
381 return; | 382 return; |
382 observer_list_->Notify( | 383 observer_list_->Notify( |
383 &ServiceWorkerContextObserver::OnErrorReported, | 384 &ServiceWorkerContextObserver::OnErrorReported, |
384 version->version_id(), | 385 version->version_id(), |
385 version->embedded_worker()->process_id(), | 386 version->embedded_worker()->process_id(), |
386 version->embedded_worker()->thread_id(), | 387 version->embedded_worker()->thread_id(), |
387 ServiceWorkerContextObserver::ErrorInfo( | 388 ServiceWorkerContextObserver::ErrorInfo( |
388 error_message, line_number, column_number, source_url)); | 389 error_message, line_number, column_number, source_url)); |
389 } | 390 } |
390 | 391 |
391 void ServiceWorkerContextCore::OnReportConsoleMessage( | 392 void ServiceWorkerContextCore::OnReportConsoleMessage( |
392 ServiceWorkerVersion* version, | 393 ServiceWorkerVersion* version, |
393 int source_identifier, | 394 int source_identifier, |
394 int message_level, | 395 int message_level, |
395 const base::string16& message, | 396 const base::string16& message, |
396 int line_number, | 397 int line_number, |
397 const GURL& source_url) { | 398 const GURL& source_url) { |
398 if (!observer_list_) | 399 if (!observer_list_.get()) |
399 return; | 400 return; |
400 observer_list_->Notify( | 401 observer_list_->Notify( |
401 &ServiceWorkerContextObserver::OnReportConsoleMessage, | 402 &ServiceWorkerContextObserver::OnReportConsoleMessage, |
402 version->version_id(), | 403 version->version_id(), |
403 version->embedded_worker()->process_id(), | 404 version->embedded_worker()->process_id(), |
404 version->embedded_worker()->thread_id(), | 405 version->embedded_worker()->thread_id(), |
405 ServiceWorkerContextObserver::ConsoleMessage( | 406 ServiceWorkerContextObserver::ConsoleMessage( |
406 source_identifier, message_level, message, line_number, source_url)); | 407 source_identifier, message_level, message, line_number, source_url)); |
407 } | 408 } |
408 | 409 |
409 ServiceWorkerProcessManager* ServiceWorkerContextCore::process_manager() { | 410 ServiceWorkerProcessManager* ServiceWorkerContextCore::process_manager() { |
410 return wrapper_->process_manager(); | 411 return wrapper_->process_manager(); |
411 } | 412 } |
412 | 413 |
413 } // namespace content | 414 } // namespace content |
OLD | NEW |