Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef CONTENT_BROWSER_MEMORY_MEMORY_COORDINATOR_IMPL_H_ | |
| 6 #define CONTENT_BROWSER_MEMORY_MEMORY_COORDINATOR_IMPL_H_ | |
| 7 | |
| 8 #include "base/callback.h" | |
| 9 #include "base/memory/singleton.h" | |
| 10 #include "base/memory/weak_ptr.h" | |
| 11 #include "base/single_thread_task_runner.h" | |
| 12 #include "base/threading/non_thread_safe.h" | |
| 13 #include "base/time/time.h" | |
| 14 #include "content/browser/memory/memory_coordinator.h" | |
| 15 | |
| 16 namespace content { | |
| 17 | |
| 18 class MemoryMonitor; | |
| 19 struct MemoryCoordinatorSingletonTraits; | |
| 20 | |
| 21 class MemoryCoordinatorImpl : public MemoryCoordinator, | |
| 22 public base::NonThreadSafe { | |
| 23 public: | |
| 24 MemoryCoordinatorImpl(scoped_refptr<base::SingleThreadTaskRunner> task_runner, | |
| 25 std::unique_ptr<MemoryMonitor> monitor); | |
| 26 ~MemoryCoordinatorImpl() override; | |
| 27 | |
| 28 void Start() override; | |
| 29 | |
| 30 void OnChildAdded(int render_process_id) override; | |
| 31 | |
| 32 private: | |
| 33 friend struct MemoryCoordinatorSingletonTraits; | |
| 34 | |
| 35 using MemoryState = base::MemoryState; | |
| 36 | |
| 37 MemoryState CalculateNextState(); | |
| 38 void UpdateState(); | |
| 39 void NotifyStateToClients(); | |
| 40 void NotifyStateToChildren(); | |
| 41 | |
| 42 void ScheduleUpdateState(base::TimeDelta delay); | |
| 43 | |
| 44 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; | |
| 45 std::unique_ptr<MemoryMonitor> memory_monitor_; | |
| 46 base::Closure update_state_callback_; | |
| 47 base::MemoryState current_state_ = MemoryState::NORMAL; | |
| 48 base::TimeTicks last_state_change_; | |
| 49 | |
| 50 // These parameters are used to determine the global state. | |
| 51 // TODO(bashi): Provide a way to change these parameters. | |
| 52 int predicted_renderer_size_; | |
| 53 int num_children_until_throttled_; | |
| 54 int num_children_until_suspended_; | |
| 55 int num_children_back_to_normal_; | |
| 56 int num_children_back_to_throttled_; | |
| 57 base::TimeDelta minimum_transition_period_; | |
| 58 base::TimeDelta monitoring_iterval_; | |
|
chrisha
2016/10/06 13:35:54
Unless these are needed for unittesting, or otherw
bashi
2016/10/07 02:10:20
Added comments. I still put these parameters in th
| |
| 59 | |
| 60 base::WeakPtrFactory<MemoryCoordinatorImpl> weak_ptr_factory_; | |
| 61 | |
| 62 DISALLOW_COPY_AND_ASSIGN(MemoryCoordinatorImpl); | |
| 63 }; | |
| 64 | |
| 65 } // namespace content | |
| 66 | |
| 67 #endif // CONTENT_BROWSER_MEMORY_MEMORY_COORDINATOR_IMPL_H_ | |
| OLD | NEW |