OLD | NEW |
---|---|
(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_PREFETCHER_H_ | |
6 #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.
| |
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 // Reads a file line by line. | |
22 // This class is visible for testing. | |
23 class FileLineIterator { | |
24 public: | |
25 explicit FileLineIterator(const base::FilePath& path); | |
26 virtual ~FileLineIterator(); | |
27 // Returns an empty string on EOF or error. Don't use on files containing | |
28 // 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.
| |
29 virtual std::string NextLine(); | |
30 | |
31 protected: | |
32 FileLineIterator() : file_(nullptr){}; | |
33 | |
34 private: | |
35 FILE* file_; | |
36 static const int kMaxLineLength = 4096; | |
37 char line_buffer_[kMaxLineLength]; | |
38 | |
39 DISALLOW_COPY_AND_ASSIGN(FileLineIterator); | |
40 }; | |
41 | |
42 // Iterates over a /proc/$PID/maps file. | |
43 // This class is visible for testing. | |
44 class ProcMapsIterator { | |
45 public: | |
46 explicit ProcMapsIterator(FileLineIterator* line_iterator); | |
47 bool Next(uint64_t* start, | |
48 uint64_t* end, | |
49 std::string* flags, | |
50 uint64_t* offset, | |
51 std::string* device, | |
52 int64_t* inode, | |
53 std::string* filename); | |
54 | |
55 private: | |
56 FileLineIterator* line_iterator_; | |
57 | |
58 DISALLOW_COPY_AND_ASSIGN(ProcMapsIterator); | |
59 }; | |
60 | |
61 // Finds the ranges matching the native library in a /proc/$PID/maps file. | |
62 // Visible for testing. | |
63 std::vector<std::pair<uint64_t, uint64_t>> FindRanges( | |
64 FileLineIterator* file_line_iterator); | |
65 | |
66 // Finds the ranges matching the native library and forks a low priority | |
67 // process pre-fetching these ranges. | |
68 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
| |
69 | |
70 } // namespace android | |
71 } // namespace base | |
72 | |
73 #endif // BASE_ANDROID_LIBRARY_PREFETCHER_H_ | |
OLD | NEW |