summaryrefslogtreecommitdiffstats
path: root/content/browser/android
diff options
context:
space:
mode:
authorpowei@chromium.org <powei@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-06-13 07:15:45 +0000
committerpowei@chromium.org <powei@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-06-13 07:15:45 +0000
commit4825cbfd9d1ffe09f93172893e73819ab9347546 (patch)
tree0f1394483574c1711acd8e32f62a6ff098521f9b /content/browser/android
parent993c38816404ba88b532bbaef4aaf232cdcf1dea (diff)
downloadchromium_src-4825cbfd9d1ffe09f93172893e73819ab9347546.zip
chromium_src-4825cbfd9d1ffe09f93172893e73819ab9347546.tar.gz
chromium_src-4825cbfd9d1ffe09f93172893e73819ab9347546.tar.bz2
android: content::UIResourceProvider and content::UIResourceClientAndroid
We abstract out the allocation of UI resources into the UIResourceProvider. We add a client class that allows for callback from the provider when resources are invalidated (due to change in LayerTreeHost). android= https://chrome-internal-review.googlesource.com/#/c/164986 BUG= TBR=jam@chromium.org Review URL: https://codereview.chromium.org/287593002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@276955 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content/browser/android')
-rw-r--r--content/browser/android/ui_resource_provider_impl.cc60
-rw-r--r--content/browser/android/ui_resource_provider_impl.h46
2 files changed, 106 insertions, 0 deletions
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 0000000..f97975c
--- /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;
+ host_ = host;
+ UIResourcesAreInvalid();
+}
+
+void UIResourceProviderImpl::UIResourcesAreInvalid() {
+ UIResourceClientMap client_map = ui_resource_client_map_;
+ ui_resource_client_map_.clear();
+ for (UIResourceClientMap::iterator iter = client_map.begin();
+ iter != client_map.end();
+ iter++) {
+ iter->second->UIResourceIsInvalid();
+ }
+}
+
+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);
+ DCHECK(iter != ui_resource_client_map_.end());
+
+ ui_resource_client_map_.erase(iter);
+
+ if (!host_)
+ return;
+ host_->DeleteUIResource(ui_resource_id);
+}
+
+} // namespace content
diff --git a/content/browser/android/ui_resource_provider_impl.h b/content/browser/android/ui_resource_provider_impl.h
new file mode 100644
index 0000000..79c2301
--- /dev/null
+++ b/content/browser/android/ui_resource_provider_impl.h
@@ -0,0 +1,46 @@
+// 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.
+
+#ifndef CONTENT_BROWSER_ANDROID_UI_RESOURCE_PROVIDER_IMPL_H_
+#define CONTENT_BROWSER_ANDROID_UI_RESOURCE_PROVIDER_IMPL_H_
+
+#include "base/containers/hash_tables.h"
+#include "content/public/browser/android/ui_resource_provider.h"
+
+namespace cc {
+class LayerTreeHost;
+}
+
+namespace content {
+
+class UIResourceClientAndroid;
+
+class UIResourceProviderImpl : public UIResourceProvider {
+ public:
+ UIResourceProviderImpl();
+
+ virtual ~UIResourceProviderImpl();
+
+ void SetLayerTreeHost(cc::LayerTreeHost* host);
+
+ void UIResourcesAreInvalid();
+
+ virtual cc::UIResourceId CreateUIResource(
+ UIResourceClientAndroid* client) OVERRIDE;
+
+ virtual void DeleteUIResource(cc::UIResourceId resource_id) OVERRIDE;
+
+ private:
+ typedef base::hash_map<cc::UIResourceId, UIResourceClientAndroid*>
+ UIResourceClientMap;
+ UIResourceClientMap ui_resource_client_map_;
+
+ cc::LayerTreeHost* host_;
+
+ DISALLOW_COPY_AND_ASSIGN(UIResourceProviderImpl);
+};
+
+} // namespace content
+
+#endif // CONTENT_BROWSER_ANDROID_UI_RESOURCE_PROVIDER_IMPL_H_