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

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: . 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_PREFETCHER_H_
6 #define BASE_ANDROID_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 // 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.
29 virtual std::string NextLine();
30
31 protected:
32 FileLineIterator() : file_(NULL){};
petrcermak 2015/03/23 15:00:48 nullptr?
Benoit L 2015/03/23 16:41:58 Done.
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
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.
67 // process pre-fetching these ranges.
68 void ForkAndPrefetchNativeLibrary();
69
70 } // namespace android
71 } // namespace base
72
73 #endif // BASE_ANDROID_LIBRARY_PREFETCHER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698