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_
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
;
21 class CopyOutputResult
;
26 class UIResourceProvider
;
34 // A native component of the Java TabContentManager class.
35 class TabContentManager
: public ThumbnailCacheObserver
{
37 static TabContentManager
* FromJavaObject(jobject jobj
);
39 TabContentManager(JNIEnv
* env
,
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
,
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
);
75 jboolean
HasFullCachedThumbnail(JNIEnv
* env
, jobject obj
, jint tab_id
);
76 void CacheTab(JNIEnv
* env
,
79 jobject content_view_core
,
80 jfloat thumbnail_scale
);
81 void CacheTabWithBitmap(JNIEnv
* env
,
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
,
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
;
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_