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

Side by Side 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: Typo. 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef BASE_ANDROID_LIBRARY_LOADER_LIBRARY_PREFETCHER_H_
6 #define BASE_ANDROID_LIBRARY_LOADER_LIBRARY_PREFETCHER_H_
7
8 #include <jni.h>
9
10 #include <stdio.h>
11 #include <sys/types.h>
12 #include <string>
13
14 #include "base/files/file_util.h"
15 #include "base/macros.h"
16 #include "base/strings/string_split.h"
17
18 namespace base {
19 namespace android {
20
21 class NativeLibraryPrefetcher {
22 public:
23 // Finds the ranges matching the native library, forks a low priority
24 // process pre-fetching these ranges and wait()s for it.
25 // Returns false on error.
26 static bool ForkAndPrefetchNativeLibrary();
27
28 protected: // Protected and not private for testing.
29 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.
30 public:
31 explicit FileLineIterator(const base::FilePath& path);
32 virtual ~FileLineIterator();
33 // Returns false on EOF or error.
34 virtual bool NextLine(std::string* line);
35
36 protected:
37 FileLineIterator() : file_(nullptr){};
38
39 private:
40 FILE* file_;
41 static const int kMaxLineLength = 4096;
42 char line_buffer_[kMaxLineLength];
43
44 DISALLOW_COPY_AND_ASSIGN(FileLineIterator);
45 };
46
47 // Iterates over a /proc/$PID/maps file.
48 class ProcMapsIterator {
49 public:
50 struct Mapping {
51 uint64_t start;
52 uint64_t end;
53 std::string flags;
54 uint64_t offset;
55 std::string device;
56 int64_t inode;
57 std::string filename;
58 };
59
60 explicit ProcMapsIterator(FileLineIterator* line_iterator);
61 bool Next(Mapping* mapping);
62
63 // Finds the ranges matching the native library in a /proc/$PID/maps file.
64 static std::vector<std::pair<uint64_t, uint64_t>> FindRanges(
65 FileLineIterator* file_line_iterator);
66
67 private:
68 FileLineIterator* line_iterator_;
69
70 DISALLOW_COPY_AND_ASSIGN(ProcMapsIterator);
71 };
72
73 NativeLibraryPrefetcher() {}
74 DISALLOW_COPY_AND_ASSIGN(NativeLibraryPrefetcher);
75 };
76
77 } // namespace android
78 } // namespace base
79
80 #endif // BASE_ANDROID_LIBRARY_LOADER_LIBRARY_PREFETCHER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698