| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 case WebServiceWorkerStateActivated: | 94 case WebServiceWorkerStateActivated: |
| 95 return "activated"; | 95 return "activated"; |
| 96 case WebServiceWorkerStateRedundant: | 96 case WebServiceWorkerStateRedundant: |
| 97 return "redundant"; | 97 return "redundant"; |
| 98 default: | 98 default: |
| 99 ASSERT_NOT_REACHED(); | 99 ASSERT_NOT_REACHED(); |
| 100 return nullAtom; | 100 return nullAtom; |
| 101 } | 101 } |
| 102 } | 102 } |
| 103 | 103 |
| 104 PassRefPtrWillBeRawPtr<ServiceWorker> ServiceWorker::from(ExecutionContext* exec
utionContext, WebServiceWorker* worker) | 104 ServiceWorker* ServiceWorker::from(ExecutionContext* executionContext, WebServic
eWorker* worker) |
| 105 { | 105 { |
| 106 if (!worker) | 106 return getOrCreate(executionContext, worker); |
| 107 return nullptr; | |
| 108 | |
| 109 RefPtrWillBeRawPtr<ServiceWorker> serviceWorker = getOrCreate(executionConte
xt, worker); | |
| 110 return serviceWorker.release(); | |
| 111 } | 107 } |
| 112 | 108 |
| 113 bool ServiceWorker::hasPendingActivity() const | 109 bool ServiceWorker::hasPendingActivity() const |
| 114 { | 110 { |
| 115 if (AbstractWorker::hasPendingActivity()) | 111 if (AbstractWorker::hasPendingActivity()) |
| 116 return true; | 112 return true; |
| 117 if (m_wasStopped) | 113 if (m_wasStopped) |
| 118 return false; | 114 return false; |
| 119 return m_outerWorker->state() != WebServiceWorkerStateRedundant; | 115 return m_outerWorker->state() != WebServiceWorkerStateRedundant; |
| 120 } | 116 } |
| 121 | 117 |
| 122 void ServiceWorker::stop() | 118 void ServiceWorker::stop() |
| 123 { | 119 { |
| 124 m_wasStopped = true; | 120 m_wasStopped = true; |
| 125 } | 121 } |
| 126 | 122 |
| 127 PassRefPtrWillBeRawPtr<ServiceWorker> ServiceWorker::getOrCreate(ExecutionContex
t* executionContext, WebServiceWorker* outerWorker) | 123 ServiceWorker* ServiceWorker::getOrCreate(ExecutionContext* executionContext, We
bServiceWorker* outerWorker) |
| 128 { | 124 { |
| 129 if (!outerWorker) | 125 if (!outerWorker) |
| 130 return nullptr; | 126 return nullptr; |
| 131 | 127 |
| 132 ServiceWorker* existingServiceWorker = static_cast<ServiceWorker*>(outerWork
er->proxy()); | 128 ServiceWorker* existingServiceWorker = static_cast<ServiceWorker*>(outerWork
er->proxy()); |
| 133 if (existingServiceWorker) { | 129 if (existingServiceWorker) { |
| 134 ASSERT(existingServiceWorker->executionContext() == executionContext); | 130 ASSERT(existingServiceWorker->executionContext() == executionContext); |
| 135 return existingServiceWorker; | 131 return existingServiceWorker; |
| 136 } | 132 } |
| 137 | 133 |
| 138 RefPtrWillBeRawPtr<ServiceWorker> worker = adoptRefWillBeNoop(new ServiceWor
ker(executionContext, adoptPtr(outerWorker))); | 134 ServiceWorker* worker = new ServiceWorker(executionContext, adoptPtr(outerWo
rker)); |
| 139 worker->suspendIfNeeded(); | 135 worker->suspendIfNeeded(); |
| 140 return worker.release(); | 136 return worker; |
| 141 } | 137 } |
| 142 | 138 |
| 143 ServiceWorker::ServiceWorker(ExecutionContext* executionContext, PassOwnPtr<WebS
erviceWorker> worker) | 139 ServiceWorker::ServiceWorker(ExecutionContext* executionContext, PassOwnPtr<WebS
erviceWorker> worker) |
| 144 : AbstractWorker(executionContext) | 140 : AbstractWorker(executionContext) |
| 145 , m_outerWorker(worker) | 141 , m_outerWorker(worker) |
| 146 , m_wasStopped(false) | 142 , m_wasStopped(false) |
| 147 { | 143 { |
| 148 ASSERT(m_outerWorker); | 144 ASSERT(m_outerWorker); |
| 149 m_outerWorker->setProxy(this); | 145 m_outerWorker->setProxy(this); |
| 150 } | 146 } |
| 151 | 147 |
| 152 ServiceWorker::~ServiceWorker() | 148 ServiceWorker::~ServiceWorker() |
| 153 { | 149 { |
| 154 } | 150 } |
| 155 | 151 |
| 156 } // namespace blink | 152 } // namespace blink |
| OLD | NEW |