Chromium Code Reviews| Index: base/android/library_loader/library_prefetcher.h |
| diff --git a/base/android/library_loader/library_prefetcher.h b/base/android/library_loader/library_prefetcher.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..23973e400bdb7ec7b6a92098a86346912316e28a |
| --- /dev/null |
| +++ b/base/android/library_loader/library_prefetcher.h |
| @@ -0,0 +1,57 @@ |
| +// Copyright 2015 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 BASE_ANDROID_LIBRARY_LOADER_LIBRARY_PREFETCHER_H_ |
| +#define BASE_ANDROID_LIBRARY_LOADER_LIBRARY_PREFETCHER_H_ |
| + |
| +#include <jni.h> |
| + |
| +#include <stdint.h> |
| +#include <string> |
| + |
| +#include "base/debug/proc_maps_linux.h" |
| +#include "base/gtest_prod_util.h" |
| + |
| +namespace base { |
| +namespace android { |
| + |
| +class NativeLibraryPrefetcher { |
| + public: |
| + // Finds the ranges matching the native library, forks a low priority |
| + // process pre-fetching these ranges and wait()s for it. |
| + // Returns false on error. |
| + static bool ForkAndPrefetchNativeLibrary(); |
| + |
| + private: |
| + using AddressRange = std::pair<uintptr_t, uintptr_t>; |
| + // Returns true if the region matches native code or data. |
| + static bool IsGoodToPrefetch(const base::debug::MappedMemoryRegion& region); |
| + // Filters the regions to keep only libchrome ranges if possible. |
| + static void TakeOnlyLibchromeRangesIfPossible( |
| + const std::vector<base::debug::MappedMemoryRegion>& regions, |
| + std::vector<AddressRange>* ranges); |
| + // Finds the ranges matching the native library in /proc/self/maps. |
| + // Returns true for success. |
| + static bool FindRanges(std::vector<AddressRange>* ranges); |
| + |
| + FRIEND_TEST_ALL_PREFIXES(NativeLibraryPrefetcherTest, |
| + TestIsGoodToPrefetchNoRange); |
| + FRIEND_TEST_ALL_PREFIXES(NativeLibraryPrefetcherTest, |
| + TestIsGoodToPrefetchUnreadableRange); |
| + FRIEND_TEST_ALL_PREFIXES(NativeLibraryPrefetcherTest, |
| + TestIsGoodToPrefetchSkipSharedRange); |
| + FRIEND_TEST_ALL_PREFIXES(NativeLibraryPrefetcherTest, |
| + TestIsGoodToPrefetchLibchromeRange); |
| + FRIEND_TEST_ALL_PREFIXES(NativeLibraryPrefetcherTest, |
| + TestIsGoodToPrefetchBaseApkRange); |
| + FRIEND_TEST_ALL_PREFIXES(NativeLibraryPrefetcherTest, |
| + TestTakeOnlyLibchromeRangesIfPossibleNoLibchrome); |
| + FRIEND_TEST_ALL_PREFIXES(NativeLibraryPrefetcherTest, |
| + TestTakeOnlyLibchromeRangesIfPossibleHasLibchrome); |
| +}; |
|
Robert Sesek
2015/04/02 19:46:48
DISALLOW_IMPLICIT_CONSTRUCTORS() to prevent instan
Benoit L
2015/04/03 09:47:16
Done.
|
| + |
| +} // namespace android |
| +} // namespace base |
| + |
| +#endif // BASE_ANDROID_LIBRARY_LOADER_LIBRARY_PREFETCHER_H_ |