OLD | NEW |
---|---|
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef BASE_MEMORY_MEMORY_COORDINATOR_PROXY_H_ | 5 #ifndef BASE_MEMORY_MEMORY_COORDINATOR_PROXY_H_ |
6 #define BASE_MEMORY_MEMORY_COORDINATOR_PROXY_H_ | 6 #define BASE_MEMORY_MEMORY_COORDINATOR_PROXY_H_ |
7 | 7 |
8 #include "base/base_export.h" | 8 #include "base/base_export.h" |
9 #include "base/callback.h" | |
10 #include "base/memory/memory_coordinator_client.h" | 9 #include "base/memory/memory_coordinator_client.h" |
11 #include "base/memory/singleton.h" | 10 #include "base/memory/singleton.h" |
11 #include "base/memory/weak_ptr.h" | |
12 | 12 |
13 namespace base { | 13 namespace base { |
14 | 14 |
15 // An interface to MemoryCoordinator. See comments in MemoryCoordinatorProxy for | |
16 // method descriptions. | |
17 class BASE_EXPORT MemoryCoordinatorInterface { | |
18 public: | |
19 virtual ~MemoryCoordinatorInterface() {} | |
20 | |
21 virtual MemoryState GetLocalMemoryState() = 0; | |
22 virtual void SetMemoryStateForTesting(MemoryState state) = 0; | |
23 }; | |
24 | |
15 // The proxy of MemoryCoordinator to be accessed from components that are not | 25 // The proxy of MemoryCoordinator to be accessed from components that are not |
16 // in content/browser e.g. net. | 26 // in content/browser e.g. net. |
17 class BASE_EXPORT MemoryCoordinatorProxy { | 27 class BASE_EXPORT MemoryCoordinatorProxy { |
18 public: | 28 public: |
19 using GetCurrentMemoryStateCallback = base::Callback<MemoryState()>; | |
20 using SetCurrentMemoryStateCallback = base::Callback<void(MemoryState)>; | |
21 | |
22 static MemoryCoordinatorProxy* GetInstance(); | 29 static MemoryCoordinatorProxy* GetInstance(); |
23 | 30 |
24 // Returns the current memory state. | 31 // Sets an instance of MemoryCoordinator |
25 MemoryState GetCurrentMemoryState() const; | 32 void Set(WeakPtr<MemoryCoordinatorInterface> instance); |
26 | 33 |
27 // Sets the current memory state. This function is for testing only. | 34 // Returns the process's current memory state. Note that the local state |
28 void SetCurrentMemoryStateForTesting(MemoryState memory_state); | 35 // could be different from the global memory state as some processes cannot |
36 // be suspended. | |
37 MemoryState GetLocalMemoryState() const; | |
29 | 38 |
30 // Sets state-getter callback. | 39 // Sets the memory state of this process. This function is for testing only. |
31 void SetGetCurrentMemoryStateCallback(GetCurrentMemoryStateCallback callback); | 40 void SetMemoryStateForTesting(MemoryState memory_state); |
haraken
2016/12/12 06:51:57
This sets the global memory state, not the memory
bashi
2016/12/12 07:17:55
This is a tricky part in some reasons. First, from
| |
32 | |
33 // Sets state-setter callback. | |
34 void SetSetCurrentMemoryStateForTestingCallback( | |
35 SetCurrentMemoryStateCallback callback); | |
36 | 41 |
37 private: | 42 private: |
38 friend struct base::DefaultSingletonTraits<MemoryCoordinatorProxy>; | 43 friend struct base::DefaultSingletonTraits<MemoryCoordinatorProxy>; |
39 | 44 |
40 MemoryCoordinatorProxy(); | 45 MemoryCoordinatorProxy(); |
41 virtual ~MemoryCoordinatorProxy(); | 46 virtual ~MemoryCoordinatorProxy(); |
42 | 47 |
43 GetCurrentMemoryStateCallback getter_callback_; | 48 WeakPtr<MemoryCoordinatorInterface> instance_; |
44 SetCurrentMemoryStateCallback setter_callback_; | |
45 | 49 |
46 DISALLOW_COPY_AND_ASSIGN(MemoryCoordinatorProxy); | 50 DISALLOW_COPY_AND_ASSIGN(MemoryCoordinatorProxy); |
47 }; | 51 }; |
48 | 52 |
49 } // namespace base | 53 } // namespace base |
50 | 54 |
51 #endif // BASE_MEMORY_MEMORY_COORDINATOR_PROXY_H_ | 55 #endif // BASE_MEMORY_MEMORY_COORDINATOR_PROXY_H_ |
OLD | NEW |