| 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..22f1d97b720cbb68a335c04e29d62916ece16174
|
| --- /dev/null
|
| +++ b/base/android/library_loader/library_prefetcher.h
|
| @@ -0,0 +1,62 @@
|
| +// 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 <sys/types.h>
|
| +#include <string>
|
| +
|
| +#include "base/files/file_util.h"
|
| +#include "base/gtest_prod_util.h"
|
| +#include "base/macros.h"
|
| +#include "base/strings/string_split.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:
|
| + struct Mapping {
|
| + uint64_t start;
|
| + uint64_t end;
|
| + std::string flags;
|
| + std::string filename;
|
| + };
|
| +
|
| + // Returns true for success.
|
| + static bool ParseMapping(const std::string& line, Mapping* mapping);
|
| + // Returns true if the mapping matches native code or data.
|
| + static bool MappingMatches(const Mapping& mapping);
|
| + // Finds the ranges matching the native library in /proc/self/maps.
|
| + // Returns true for success.
|
| + static bool FindRanges(std::vector<std::pair<uint64_t, uint64_t>>* range);
|
| +
|
| + FRIEND_TEST_ALL_PREFIXES(NativeLibraryPrefetcherTest, TestParseLine32Bits);
|
| + FRIEND_TEST_ALL_PREFIXES(NativeLibraryPrefetcherTest, TestParseLine64Bits);
|
| + FRIEND_TEST_ALL_PREFIXES(NativeLibraryPrefetcherTest, TestParseLineNoFile);
|
| + FRIEND_TEST_ALL_PREFIXES(
|
| + NativeLibraryPrefetcherTest, TestMappingMatchesNoRange);
|
| + FRIEND_TEST_ALL_PREFIXES(
|
| + NativeLibraryPrefetcherTest, TestMappingMatchesUnreadableRange);
|
| + FRIEND_TEST_ALL_PREFIXES(
|
| + NativeLibraryPrefetcherTest, TestMappingMatchesSkipSharedRange);
|
| + FRIEND_TEST_ALL_PREFIXES(
|
| + NativeLibraryPrefetcherTest, TestMappingMatchesLibchromeRange);
|
| + FRIEND_TEST_ALL_PREFIXES(
|
| + NativeLibraryPrefetcherTest, TestMappingMatchesBaseApkRange);
|
| +};
|
| +
|
| +} // namespace android
|
| +} // namespace base
|
| +
|
| +#endif // BASE_ANDROID_LIBRARY_LOADER_LIBRARY_PREFETCHER_H_
|
|
|