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..90439b4c194dde66b285ce4508cd50842b7c677e |
--- /dev/null |
+++ b/base/android/library_loader/library_prefetcher.h |
@@ -0,0 +1,80 @@ |
+// 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 <stdio.h> |
+#include <sys/types.h> |
+#include <string> |
+ |
+#include "base/files/file_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(); |
+ |
+ protected: // Protected and not private for testing. |
+ class FileLineIterator { |
pasko
2015/03/25 12:57:58
To my taste this iterator adds unnecessary clutter
Benoit L
2015/03/26 15:45:03
Done.
|
+ public: |
+ explicit FileLineIterator(const base::FilePath& path); |
+ virtual ~FileLineIterator(); |
+ // Returns false on EOF or error. |
+ virtual bool NextLine(std::string* line); |
+ |
+ protected: |
+ FileLineIterator() : file_(nullptr){}; |
+ |
+ private: |
+ FILE* file_; |
+ static const int kMaxLineLength = 4096; |
+ char line_buffer_[kMaxLineLength]; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(FileLineIterator); |
+ }; |
+ |
+ // Iterates over a /proc/$PID/maps file. |
+ class ProcMapsIterator { |
+ public: |
+ struct Mapping { |
+ uint64_t start; |
+ uint64_t end; |
+ std::string flags; |
+ uint64_t offset; |
+ std::string device; |
+ int64_t inode; |
+ std::string filename; |
+ }; |
+ |
+ explicit ProcMapsIterator(FileLineIterator* line_iterator); |
+ bool Next(Mapping* mapping); |
+ |
+ // Finds the ranges matching the native library in a /proc/$PID/maps file. |
+ static std::vector<std::pair<uint64_t, uint64_t>> FindRanges( |
+ FileLineIterator* file_line_iterator); |
+ |
+ private: |
+ FileLineIterator* line_iterator_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(ProcMapsIterator); |
+ }; |
+ |
+ NativeLibraryPrefetcher() {} |
+ DISALLOW_COPY_AND_ASSIGN(NativeLibraryPrefetcher); |
+}; |
+ |
+} // namespace android |
+} // namespace base |
+ |
+#endif // BASE_ANDROID_LIBRARY_LOADER_LIBRARY_PREFETCHER_H_ |