Chromium Code Reviews| Index: android_webview/browser/global_tile_manager.h |
| diff --git a/android_webview/browser/global_tile_manager.h b/android_webview/browser/global_tile_manager.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..3bc5109d4350040e8f3545b49e4a46aae920438c |
| --- /dev/null |
| +++ b/android_webview/browser/global_tile_manager.h |
| @@ -0,0 +1,65 @@ |
| +// 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 ANDROID_WEBVIEW_BROWSER_GLOBAL_TILE_MANAGER_H_ |
| +#define ANDROID_WEBVIEW_BROWSER_GLOBAL_TILE_MANAGER_H_ |
| + |
| +#include <list> |
| +#include "android_webview/browser/tile_resource_consumer.h" |
| +#include "base/basictypes.h" |
| +#include "base/lazy_instance.h" |
| +#include "base/synchronization/lock.h" |
| + |
| +namespace android_webview { |
| + |
| +// A global tile manager to keep track of the number of tile resources. Each |
| +// tile needs file descriptors (typically 2) and there is a soft limit of 1024 |
| +// file descriptors per Android process. The GlobalTileManager does not keep |
| +// track of how many tiles each individual view is actually using. The purpose |
| +// of GlobalTileManager is to behave gracefully (as in not crashing) when the |
| +// embedder of webview creates a lot of webviews and draw them at the same time. |
| +class GlobalTileManager { |
| + |
| + private: |
| + typedef std::list<TileResourceConsumer*> ListType; |
|
boliu
2014/04/28 22:22:15
newline below
hush (inactive)
2014/04/30 20:50:17
Done.
|
| + public: |
| + typedef ListType::iterator Key; |
| + static GlobalTileManager* GetInstance(); |
| + |
| + // Requests the |num_of_tiles| from the available global pool. Returns the |
| + // actual number of tiles granted to the requester. If |is_starved| is true, |
| + // the GlobalTileManager will evict tiles allocated to other |
| + // requesters. |
| + size_t RequestTiles(size_t old_num_of_tiles, size_t new_num_of_tiles, |
|
boliu
2014/04/28 22:22:15
c++ has a different new line wrap style, either al
hush (inactive)
2014/04/30 20:50:17
Pretty cool. Just did git cl format.
On 2014/04/28
|
| + bool is_starved, Key key); |
| + |
| + Key PushBack(TileResourceConsumer* tile_resource_consumer); |
| + |
| + // |key| must be already in manager. Move renderer corresponding to |key| to |
| + // most recent. |
| + void DidDrawGL(Key key); |
| + |
| + void Remove(Key key); |
|
boliu
2014/04/28 22:22:15
newline below
hush (inactive)
2014/04/30 20:50:17
Done.
|
| + private: |
| + friend struct base::DefaultLazyInstanceTraits<GlobalTileManager>; |
| + GlobalTileManager(); |
| + ~GlobalTileManager(); |
|
boliu
2014/04/28 22:22:15
new line below
hush (inactive)
2014/04/30 20:50:17
Done.
|
| + // Continues evicting the least recently drawn views until freeing up at least |
| + // amount of memory specified by |desired_policy| to draw a view specified |
| + // by |key|. |
| + // Returns the amount of memory that was actually evicted. |
| + // This function is called when a requester is starved. |
| + size_t EvictUntilSatisfied(size_t desired_num_tiles, Key key); |
| + |
| + size_t allocated_tiles_; |
|
boliu
2014/04/28 22:22:15
total_allocated_tiles_
hush (inactive)
2014/04/30 20:50:17
Done.
|
| + ListType mru_list_; |
| + // The list of inactive views is from inactive_views_ to mru_list_end(). |
| + Key inactive_views_; |
| + |
|
boliu
2014/04/28 22:22:15
This class lives on UI, right? Add a SequenceCheck
hush (inactive)
2014/04/30 20:50:17
yes it does. But I don't understand "sequenceCheck
boliu
2014/05/01 00:37:40
Yes. Let's try not depending on BrowserThreads in
|
| + DISALLOW_COPY_AND_ASSIGN(GlobalTileManager); |
| +}; |
| + |
| +} // namespace android_webview |
| + |
| +#endif |
|
boliu
2014/04/28 22:22:15
comment on endif
hush (inactive)
2014/04/30 20:50:17
Done.
|