Chromium Code Reviews| Index: content/browser/android/ui_resource_provider_impl.cc |
| diff --git a/content/browser/android/ui_resource_provider_impl.cc b/content/browser/android/ui_resource_provider_impl.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..2b7df1f46141b9dbb904893ec0f66240e851a2ce |
| --- /dev/null |
| +++ b/content/browser/android/ui_resource_provider_impl.cc |
| @@ -0,0 +1,60 @@ |
| +// Copyright 2014 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "content/browser/android/ui_resource_provider_impl.h" |
| + |
| +#include "cc/resources/ui_resource_client.h" |
| +#include "cc/trees/layer_tree_host.h" |
| +#include "content/public/browser/android/ui_resource_client_android.h" |
| + |
| +namespace content { |
| + |
| +UIResourceProviderImpl::UIResourceProviderImpl() : host_(NULL) { |
| +} |
| + |
| +UIResourceProviderImpl::~UIResourceProviderImpl() { |
| + SetLayerTreeHost(NULL); |
| +} |
| + |
| +void UIResourceProviderImpl::SetLayerTreeHost(cc::LayerTreeHost* host) { |
| + if (host_ == host) |
| + return; |
| + UIResourcesAreInvalid(); |
|
David Trainor- moved to gerrit
2014/06/04 07:22:41
Do we have to worry about this calling back into t
powei
2014/06/04 21:29:57
Maybe this line should come after next line. That
|
| + host_ = host; |
| +} |
| + |
| +void UIResourceProviderImpl::UIResourcesAreInvalid() { |
| + for (UIResourceClientMap::iterator iter = ui_resource_client_map_.begin(); |
| + iter != ui_resource_client_map_.end(); |
| + iter++) { |
| + iter->second->UIResourceIsInvalid(); |
| + } |
| + ui_resource_client_map_.clear(); |
|
David Trainor- moved to gerrit
2014/06/04 07:22:41
Same thing, what if the client tries to recreate a
powei
2014/06/04 21:29:57
Essentially I was thinking that we should not recr
|
| +} |
| + |
| +cc::UIResourceId UIResourceProviderImpl::CreateUIResource( |
| + UIResourceClientAndroid* client) { |
| + if (!host_) |
| + return 0; |
| + cc::UIResourceId id = host_->CreateUIResource(client); |
| + DCHECK(ui_resource_client_map_.find(id) == ui_resource_client_map_.end()); |
| + |
| + ui_resource_client_map_[id] = client; |
| + return id; |
| +} |
| + |
| +void UIResourceProviderImpl::DeleteUIResource(cc::UIResourceId ui_resource_id) { |
| + UIResourceClientMap::iterator iter = |
| + ui_resource_client_map_.find(ui_resource_id); |
| + if (iter == ui_resource_client_map_.end()) |
| + return; |
| + |
| + ui_resource_client_map_.erase(iter); |
| + |
| + if (!host_) |
| + return; |
| + host_->DeleteUIResource(ui_resource_id); |
| +} |
| + |
| +} // namespace content |