| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "device/vr/android/gvr/gvr_delegate.h" | 5 #include "device/vr/android/gvr/gvr_delegate.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/memory/singleton.h" | |
| 9 | 8 |
| 10 namespace device { | 9 namespace device { |
| 11 | 10 |
| 12 GvrDelegateManager* GvrDelegateManager::GetInstance() { | 11 GvrDelegateProvider* GvrDelegateProvider::delegate_provider_ = nullptr; |
| 13 return base::Singleton<GvrDelegateManager>::get(); | 12 |
| 13 GvrDelegateProvider* GvrDelegateProvider::GetInstance() { |
| 14 return delegate_provider_; |
| 14 } | 15 } |
| 15 | 16 |
| 16 GvrDelegateManager::GvrDelegateManager() : delegate_(nullptr) {} | 17 void GvrDelegateProvider::SetInstance(GvrDelegateProvider* delegate_provider) { |
| 17 | 18 // Don't initialize the delegate_provider_ twice. |
| 18 GvrDelegateManager::~GvrDelegateManager() {} | 19 DCHECK(!delegate_provider_); |
| 19 | 20 delegate_provider_ = delegate_provider; |
| 20 void GvrDelegateManager::AddClient(GvrDelegateClient* client) { | |
| 21 clients_.push_back(client); | |
| 22 | |
| 23 if (delegate_) | |
| 24 client->OnDelegateInitialized(delegate_); | |
| 25 } | |
| 26 | |
| 27 void GvrDelegateManager::RemoveClient(GvrDelegateClient* client) { | |
| 28 clients_.erase(std::remove(clients_.begin(), clients_.end(), client), | |
| 29 clients_.end()); | |
| 30 } | |
| 31 | |
| 32 void GvrDelegateManager::Initialize(GvrDelegate* delegate) { | |
| 33 // Don't initialize the delegate manager twice. | |
| 34 DCHECK(!delegate_); | |
| 35 | |
| 36 delegate_ = delegate; | |
| 37 | |
| 38 for (const auto& client : clients_) | |
| 39 client->OnDelegateInitialized(delegate_); | |
| 40 } | |
| 41 | |
| 42 void GvrDelegateManager::Shutdown() { | |
| 43 if (!delegate_) | |
| 44 return; | |
| 45 | |
| 46 delegate_ = nullptr; | |
| 47 | |
| 48 for (const auto& client : clients_) | |
| 49 client->OnDelegateShutdown(); | |
| 50 } | 21 } |
| 51 | 22 |
| 52 } // namespace device | 23 } // namespace device |
| OLD | NEW |