Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / chrome / browser / android / compositor / tab_content_manager.h
blob78dec23cb5956fe3b4ba12fb2b20400151ec23cb
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_ANDROID_COMPOSITOR_TAB_CONTENT_MANAGER_H_
6 #define CHROME_BROWSER_ANDROID_COMPOSITOR_TAB_CONTENT_MANAGER_H_
8 #include <jni.h>
10 #include "base/android/jni_android.h"
11 #include "base/android/jni_weak_ref.h"
12 #include "base/containers/hash_tables.h"
13 #include "base/containers/scoped_ptr_hash_map.h"
14 #include "base/memory/weak_ptr.h"
15 #include "cc/layers/ui_resource_layer.h"
16 #include "chrome/browser/android/thumbnail/thumbnail_cache.h"
18 using base::android::ScopedJavaLocalRef;
20 namespace cc {
21 class CopyOutputResult;
22 class Layer;
25 namespace ui {
26 class UIResourceProvider;
29 namespace chrome {
30 namespace android {
32 class ThumbnailLayer;
34 // A native component of the Java TabContentManager class.
35 class TabContentManager : public ThumbnailCacheObserver {
36 public:
37 static TabContentManager* FromJavaObject(jobject jobj);
39 TabContentManager(JNIEnv* env,
40 jobject obj,
41 jint default_cache_size,
42 jint approximation_cache_size,
43 jint compression_queue_max_size,
44 jint write_queue_max_size,
45 jboolean use_approximation_thumbnail);
47 virtual ~TabContentManager();
49 void Destroy(JNIEnv* env, jobject obj);
51 void SetUIResourceProvider(JNIEnv* env,
52 jobject obj,
53 jlong ui_resource_provider_ptr);
54 void SetUIResourceProvider(ui::UIResourceProvider* ui_resource_provider);
56 // Get the live layer from the cache.
57 scoped_refptr<cc::Layer> GetLiveLayer(int tab_id);
59 // Get the static thumbnail from the cache, or the NTP.
60 scoped_refptr<ThumbnailLayer> GetStaticLayer(int tab_id,
61 bool force_disk_read);
63 // Should be called when a tab gets a new live layer that should be served
64 // by the cache to the CompositorView.
65 void AttachLiveLayer(int tab_id, scoped_refptr<cc::Layer> layer);
67 // Should be called when a tab removes a live layer because it should no
68 // longer be served by the CompositorView. If |layer| is NULL, will
69 // make sure all live layers are detached.
70 void DetachLiveLayer(int tab_id, scoped_refptr<cc::Layer> layer);
72 // Callback for when the thumbnail decompression for tab_id is done.
73 void OnFinishDecompressThumbnail(int tab_id, bool success, SkBitmap bitmap);
74 // JNI methods.
75 jboolean HasFullCachedThumbnail(JNIEnv* env, jobject obj, jint tab_id);
76 void CacheTab(JNIEnv* env,
77 jobject obj,
78 jobject tab,
79 jobject content_view_core,
80 jfloat thumbnail_scale);
81 void CacheTabWithBitmap(JNIEnv* env,
82 jobject obj,
83 jobject tab,
84 jobject bitmap,
85 jfloat thumbnail_scale);
86 void InvalidateIfChanged(JNIEnv* env, jobject obj, jint tab_id, jstring jurl);
87 void UpdateVisibleIds(JNIEnv* env, jobject obj, jintArray priority);
88 void RemoveTabThumbnail(JNIEnv* env, jobject obj, jint tab_id);
89 void RemoveTabThumbnailFromDiskAtAndAboveId(JNIEnv* env,
90 jobject obj,
91 jint min_forbidden_id);
92 void GetDecompressedThumbnail(JNIEnv* env, jobject obj, jint tab_id);
94 // ThumbnailCacheObserver implementation;
95 void OnFinishedThumbnailRead(TabId tab_id) override;
97 private:
98 class TabReadbackRequest;
99 typedef base::hash_map<int, scoped_refptr<cc::Layer>> LayerMap;
100 typedef base::hash_map<int, scoped_refptr<ThumbnailLayer>> ThumbnailLayerMap;
101 typedef base::ScopedPtrHashMap<int, scoped_ptr<TabReadbackRequest>>
102 TabReadbackRequestMap;
104 void PutThumbnailIntoCache(int tab_id,
105 float thumbnail_scale,
106 const SkBitmap& bitmap);
108 scoped_ptr<ThumbnailCache> thumbnail_cache_;
109 ThumbnailLayerMap static_layer_cache_;
110 LayerMap live_layer_list_;
111 TabReadbackRequestMap pending_tab_readbacks_;
113 JavaObjectWeakGlobalRef weak_java_tab_content_manager_;
114 base::WeakPtrFactory<TabContentManager> weak_factory_;
116 DISALLOW_COPY_AND_ASSIGN(TabContentManager);
119 bool RegisterTabContentManager(JNIEnv* env);
121 } // namespace android
122 } // namespace chrome
124 #endif // CHROME_BROWSER_ANDROID_COMPOSITOR_TAB_CONTENT_MANAGER_H_