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_store.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 ThumbnailStoreObserver
{
37 static TabContentManager
* FromJavaObject(jobject jobj
);
39 TabContentManager(JNIEnv
* env
,
41 jstring disk_cache_path
,
42 jint default_cache_size
,
43 jint approximation_cache_size
,
44 jint compression_queue_max_size
,
45 jint write_queue_max_size
,
46 jboolean use_approximation_thumbnail
);
48 virtual ~TabContentManager();
50 void Destroy(JNIEnv
* env
, jobject obj
);
52 void SetUIResourceProvider(JNIEnv
* env
,
54 jlong ui_resource_provider_ptr
);
55 void SetUIResourceProvider(ui::UIResourceProvider
* ui_resource_provider
);
57 // Get the live layer from the cache.
58 scoped_refptr
<cc::Layer
> GetLiveLayer(int tab_id
);
60 // Get the static thumbnail from the cache, or the NTP.
61 scoped_refptr
<ThumbnailLayer
> GetStaticLayer(int tab_id
,
62 bool force_disk_read
);
64 // Should be called when a tab gets a new live layer that should be served
65 // by the cache to the CompositorView.
66 void AttachLiveLayer(int tab_id
, scoped_refptr
<cc::Layer
> layer
);
68 // Should be called when a tab removes a live layer because it should no
69 // longer be served by the CompositorView. If |layer| is NULL, will
70 // make sure all live layers are detached.
71 void DetachLiveLayer(int tab_id
, scoped_refptr
<cc::Layer
> layer
);
73 // Callback for when the thumbnail decompression for tab_id is done.
74 void OnFinishDecompressThumbnail(int tab_id
, bool success
, SkBitmap bitmap
);
76 jboolean
HasFullCachedThumbnail(JNIEnv
* env
, jobject obj
, jint tab_id
);
77 void CacheTab(JNIEnv
* env
,
80 jobject content_view_core
,
81 jfloat thumbnail_scale
);
82 void CacheTabWithBitmap(JNIEnv
* env
,
86 jfloat thumbnail_scale
);
87 void InvalidateIfChanged(JNIEnv
* env
, jobject obj
, jint tab_id
, jstring jurl
);
88 void UpdateVisibleIds(JNIEnv
* env
, jobject obj
, jintArray priority
);
89 void RemoveTabThumbnail(JNIEnv
* env
, jobject obj
, jint tab_id
);
90 void RemoveTabThumbnailFromDiskAtAndAboveId(JNIEnv
* env
,
92 jint min_forbidden_id
);
93 void GetDecompressedThumbnail(JNIEnv
* env
, jobject obj
, jint tab_id
);
95 // ThumbnailStoreObserver implementation;
96 void OnFinishedThumbnailRead(TabId tab_id
) override
;
99 class TabReadbackRequest
;
100 typedef base::hash_map
<int, scoped_refptr
<cc::Layer
>> LayerMap
;
101 typedef base::hash_map
<int, scoped_refptr
<ThumbnailLayer
>> ThumbnailLayerMap
;
102 typedef base::ScopedPtrHashMap
<int, TabReadbackRequest
> TabReadbackRequestMap
;
104 // TODO(): The upstream ThumbnailCache class was temporarily renamed to
105 // ThumbnailStore to avoid conflict with downstream. Please rename the
106 // upstream to ThumbnailCache once the downstream is in a good state.
107 typedef ThumbnailStore ThumbnailCache
;
109 void PutThumbnailIntoCache(int tab_id
,
110 float thumbnail_scale
,
111 const SkBitmap
& bitmap
);
113 scoped_ptr
<ThumbnailCache
> thumbnail_cache_
;
114 ThumbnailLayerMap static_layer_cache_
;
115 LayerMap live_layer_list_
;
116 TabReadbackRequestMap pending_tab_readbacks_
;
118 JavaObjectWeakGlobalRef weak_java_tab_content_manager_
;
119 base::WeakPtrFactory
<TabContentManager
> weak_factory_
;
121 DISALLOW_COPY_AND_ASSIGN(TabContentManager
);
124 bool RegisterTabContentManager(JNIEnv
* env
);
126 } // namespace android
127 } // namespace chrome
129 #endif // CHROME_BROWSER_ANDROID_COMPOSITOR_TAB_CONTENT_MANAGER_H_