Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2218)

Unified Diff: base/android/library_loader/library_prefetcher.h

Issue 1001343002: Prefetch the native library from native code by parsing /proc/pid/maps. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..7d7aaebc40045dcdfdc7e7e07115131b72925930
--- /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_
+
+#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.
+ virtual std::string NextLine();
+
+ protected:
+ FileLineIterator() : file_(NULL){};
petrcermak 2015/03/23 15:00:48 nullptr?
Benoit L 2015/03/23 16:41:58 Done.
+
+ 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
petrcermak 2015/03/23 15:00:48 nit: There shouldn't be a comma before "and".
Benoit L 2015/03/23 16:41:58 Done.
+// process pre-fetching these ranges.
+void ForkAndPrefetchNativeLibrary();
+
+} // namespace android
+} // namespace base
+
+#endif // BASE_ANDROID_LIBRARY_PREFETCHER_H_

Powered by Google App Engine
This is Rietveld 408576698