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..8566d4d7d9a3b906c705962768e51ae2dc2020ba |
--- /dev/null |
+++ b/base/android/library_loader/library_prefetcher.h |
@@ -0,0 +1,73 @@ |
+// 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_PREFETCHER_H_ |
+#define BASE_ANDROID_LIBRARY_PREFETCHER_H_ |
pasko
2015/03/24 17:10:36
should be: BASE_ANDROID_LIBRARY_LOADER_LIBRARY_PRE
Benoit L
2015/03/25 10:36:19
Done.
|
+ |
+#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 { |
+ |
+// Reads a file line by line. |
+// This class is visible for testing. |
+class FileLineIterator { |
+ public: |
+ explicit FileLineIterator(const base::FilePath& path); |
+ virtual ~FileLineIterator(); |
+ // Returns an empty string on EOF or error. Don't use on files containing |
+ // empty lines. |
rmcilroy
2015/03/24 15:18:26
This seems slightly dangerous. Maybe just make Nex
Benoit L
2015/03/25 10:36:19
Done.
|
+ virtual std::string NextLine(); |
+ |
+ 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. |
+// This class is visible for testing. |
+class ProcMapsIterator { |
+ public: |
+ explicit ProcMapsIterator(FileLineIterator* line_iterator); |
+ bool Next(uint64_t* start, |
+ uint64_t* end, |
+ std::string* flags, |
+ uint64_t* offset, |
+ std::string* device, |
+ int64_t* inode, |
+ std::string* filename); |
+ |
+ private: |
+ FileLineIterator* line_iterator_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(ProcMapsIterator); |
+}; |
+ |
+// Finds the ranges matching the native library in a /proc/$PID/maps file. |
+// Visible for testing. |
+std::vector<std::pair<uint64_t, uint64_t>> FindRanges( |
+ FileLineIterator* file_line_iterator); |
+ |
+// Finds the ranges matching the native library and forks a low priority |
+// process pre-fetching these ranges. |
+void ForkAndPrefetchNativeLibrary(); |
rmcilroy
2015/03/24 15:18:26
Could we wrap ForkAndPrefetchNativeLibrary as a st
Benoit L
2015/03/25 10:36:19
Yes, thank you for the suggestion. Only protected
|
+ |
+} // namespace android |
+} // namespace base |
+ |
+#endif // BASE_ANDROID_LIBRARY_PREFETCHER_H_ |