| 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 CONTENT_BROWSER_MEMORY_MEMORY_COORDINATOR_IMPL_H_ | 5 #ifndef CONTENT_BROWSER_MEMORY_MEMORY_COORDINATOR_IMPL_H_ |
| 6 #define CONTENT_BROWSER_MEMORY_MEMORY_COORDINATOR_IMPL_H_ | 6 #define CONTENT_BROWSER_MEMORY_MEMORY_COORDINATOR_IMPL_H_ |
| 7 | 7 |
| 8 #include "base/callback.h" | 8 #include "base/callback.h" |
| 9 #include "base/memory/memory_coordinator_client.h" | 9 #include "base/memory/memory_coordinator_client.h" |
| 10 #include "base/memory/memory_pressure_monitor.h" | 10 #include "base/memory/memory_pressure_monitor.h" |
| 11 #include "base/memory/singleton.h" | 11 #include "base/memory/singleton.h" |
| 12 #include "base/single_thread_task_runner.h" | 12 #include "base/single_thread_task_runner.h" |
| 13 #include "base/threading/non_thread_safe.h" | 13 #include "base/threading/non_thread_safe.h" |
| 14 #include "base/time/time.h" | 14 #include "base/time/time.h" |
| 15 #include "content/common/content_export.h" | 15 #include "content/common/content_export.h" |
| 16 #include "content/common/memory_coordinator.mojom.h" | 16 #include "content/common/memory_coordinator.mojom.h" |
| 17 #include "content/public/browser/memory_coordinator.h" |
| 17 #include "content/public/browser/memory_coordinator_delegate.h" | 18 #include "content/public/browser/memory_coordinator_delegate.h" |
| 18 #include "content/public/browser/notification_observer.h" | 19 #include "content/public/browser/notification_observer.h" |
| 19 #include "content/public/browser/notification_registrar.h" | 20 #include "content/public/browser/notification_registrar.h" |
| 20 | 21 |
| 21 namespace content { | 22 namespace content { |
| 22 | 23 |
| 23 // NOTE: Memory coordinator is under development and not fully working. | 24 // NOTE: Memory coordinator is under development and not fully working. |
| 24 // TODO(bashi): Add content::MemoryCoordinator which is a pure virtual | |
| 25 // interface to expose APIs outside content/. | |
| 26 | 25 |
| 27 class MemoryCoordinatorHandleImpl; | 26 class MemoryCoordinatorHandleImpl; |
| 28 class MemoryCoordinatorImplTest; | 27 class MemoryCoordinatorImplTest; |
| 29 class MemoryMonitor; | 28 class MemoryMonitor; |
| 30 class MemoryStateUpdater; | 29 class MemoryStateUpdater; |
| 31 class RenderProcessHost; | 30 class RenderProcessHost; |
| 32 struct MemoryCoordinatorSingletonTraits; | 31 struct MemoryCoordinatorSingletonTraits; |
| 33 | 32 |
| 34 // MemoryCoordinatorImpl is an implementation of MemoryCoordinator. | 33 // MemoryCoordinatorImpl is an implementation of MemoryCoordinator. |
| 35 // The current implementation uses MemoryStateUpdater to update the global | 34 // The current implementation uses MemoryStateUpdater to update the global |
| 36 // memory state. See comments in MemoryStateUpdater for details. | 35 // memory state. See comments in MemoryStateUpdater for details. |
| 37 class CONTENT_EXPORT MemoryCoordinatorImpl : public NotificationObserver, | 36 class CONTENT_EXPORT MemoryCoordinatorImpl : public MemoryCoordinator, |
| 37 public NotificationObserver, |
| 38 public base::NonThreadSafe { | 38 public base::NonThreadSafe { |
| 39 public: | 39 public: |
| 40 using MemoryState = base::MemoryState; | 40 using MemoryState = base::MemoryState; |
| 41 | 41 |
| 42 static MemoryCoordinatorImpl* GetInstance(); | 42 static MemoryCoordinatorImpl* GetInstance(); |
| 43 | 43 |
| 44 MemoryCoordinatorImpl(scoped_refptr<base::SingleThreadTaskRunner> task_runner, | 44 MemoryCoordinatorImpl(scoped_refptr<base::SingleThreadTaskRunner> task_runner, |
| 45 std::unique_ptr<MemoryMonitor> monitor); | 45 std::unique_ptr<MemoryMonitor> monitor); |
| 46 ~MemoryCoordinatorImpl() override; | 46 ~MemoryCoordinatorImpl() override; |
| 47 | 47 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 73 virtual MemoryState GetGlobalMemoryState() const; | 73 virtual MemoryState GetGlobalMemoryState() const; |
| 74 | 74 |
| 75 // Returns the browser's current memory state. Note that the current state | 75 // Returns the browser's current memory state. Note that the current state |
| 76 // could be different from the global memory state as the browser won't be | 76 // could be different from the global memory state as the browser won't be |
| 77 // suspended. | 77 // suspended. |
| 78 MemoryState GetCurrentMemoryState() const; | 78 MemoryState GetCurrentMemoryState() const; |
| 79 | 79 |
| 80 // Sets the global memory state for testing. | 80 // Sets the global memory state for testing. |
| 81 void SetCurrentMemoryStateForTesting(MemoryState memory_state); | 81 void SetCurrentMemoryStateForTesting(MemoryState memory_state); |
| 82 | 82 |
| 83 // MemoryCoordinator implementation: |
| 84 MemoryState GetStateForProcess(base::ProcessHandle handle) override; |
| 85 |
| 83 // NotificationObserver implementation: | 86 // NotificationObserver implementation: |
| 84 void Observe(int type, | 87 void Observe(int type, |
| 85 const NotificationSource& source, | 88 const NotificationSource& source, |
| 86 const NotificationDetails& details) override; | 89 const NotificationDetails& details) override; |
| 87 | 90 |
| 88 // Overrides the global state to |new_state|. State update tasks won't be | 91 // Overrides the global state to |new_state|. State update tasks won't be |
| 89 // scheduled until |duration| is passed. This means that the global state | 92 // scheduled until |duration| is passed. This means that the global state |
| 90 // remains the same until |duration| is passed or another call of this method. | 93 // remains the same until |duration| is passed or another call of this method. |
| 91 void ForceSetGlobalState(base::MemoryState new_state, | 94 void ForceSetGlobalState(base::MemoryState new_state, |
| 92 base::TimeDelta duration); | 95 base::TimeDelta duration); |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 187 // MemoryCoordinator and removed automatically when an underlying binding is | 190 // MemoryCoordinator and removed automatically when an underlying binding is |
| 188 // disconnected. | 191 // disconnected. |
| 189 ChildInfoMap children_; | 192 ChildInfoMap children_; |
| 190 | 193 |
| 191 DISALLOW_COPY_AND_ASSIGN(MemoryCoordinatorImpl); | 194 DISALLOW_COPY_AND_ASSIGN(MemoryCoordinatorImpl); |
| 192 }; | 195 }; |
| 193 | 196 |
| 194 } // namespace content | 197 } // namespace content |
| 195 | 198 |
| 196 #endif // CONTENT_BROWSER_MEMORY_MEMORY_COORDINATOR_IMPL_H_ | 199 #endif // CONTENT_BROWSER_MEMORY_MEMORY_COORDINATOR_IMPL_H_ |
| OLD | NEW |