Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 #include "athena/resource_manager/public/resource_manager.h" | 5 #include "athena/resource_manager/public/resource_manager.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "athena/activity/public/activity.h" | 10 #include "athena/activity/public/activity.h" |
| 11 #include "athena/activity/public/activity_manager.h" | 11 #include "athena/activity/public/activity_manager.h" |
| 12 #include "athena/activity/public/activity_manager_observer.h" | 12 #include "athena/activity/public/activity_manager_observer.h" |
| 13 #include "athena/resource_manager/memory_pressure_notifier.h" | 13 #include "athena/resource_manager/memory_pressure_notifier.h" |
| 14 #include "athena/resource_manager/public/resource_manager_delegate.h" | 14 #include "athena/resource_manager/public/resource_manager_delegate.h" |
| 15 #include "athena/wm/public/window_list_provider.h" | |
| 16 #include "athena/wm/public/window_list_provider_observer.h" | |
| 15 #include "athena/wm/public/window_manager.h" | 17 #include "athena/wm/public/window_manager.h" |
| 16 #include "athena/wm/public/window_manager_observer.h" | 18 #include "athena/wm/public/window_manager_observer.h" |
| 17 #include "base/logging.h" | 19 #include "base/logging.h" |
| 18 #include "base/memory/scoped_ptr.h" | 20 #include "base/memory/scoped_ptr.h" |
| 19 #include "ui/aura/window.h" | 21 #include "ui/aura/window.h" |
| 20 #include "ui/aura/window_observer.h" | |
| 21 | 22 |
| 22 namespace athena { | 23 namespace athena { |
| 23 | 24 |
| 24 class ResourceManagerImpl : public ResourceManager, | 25 class ResourceManagerImpl : public ResourceManager, |
| 25 public WindowManagerObserver, | 26 public WindowManagerObserver, |
| 26 public ActivityManagerObserver, | 27 public ActivityManagerObserver, |
| 27 public MemoryPressureObserver, | 28 public MemoryPressureObserver, |
| 28 public aura::WindowObserver { | 29 public WindowListProviderObserver { |
| 29 public: | 30 public: |
| 30 ResourceManagerImpl(ResourceManagerDelegate* delegate); | 31 ResourceManagerImpl(ResourceManagerDelegate* delegate); |
| 31 virtual ~ResourceManagerImpl(); | 32 virtual ~ResourceManagerImpl(); |
| 32 | 33 |
| 33 // ResourceManager: | 34 // ResourceManager: |
| 34 virtual void SetMemoryPressureAndStopMonitoring( | 35 virtual void SetMemoryPressureAndStopMonitoring( |
| 35 MemoryPressureObserver::MemoryPressure pressure) OVERRIDE; | 36 MemoryPressureObserver::MemoryPressure pressure) OVERRIDE; |
| 36 virtual void Pause(bool pause) OVERRIDE { | 37 virtual void Pause(bool pause) OVERRIDE { |
| 37 if (pause) { | 38 if (pause) { |
| 38 if (!pause_) | 39 if (!pause_) |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 56 virtual void OnOverviewModeEnter() OVERRIDE; | 57 virtual void OnOverviewModeEnter() OVERRIDE; |
| 57 virtual void OnOverviewModeExit() OVERRIDE; | 58 virtual void OnOverviewModeExit() OVERRIDE; |
| 58 virtual void OnSplitViewModeEnter() OVERRIDE; | 59 virtual void OnSplitViewModeEnter() OVERRIDE; |
| 59 virtual void OnSplitViewModeExit() OVERRIDE; | 60 virtual void OnSplitViewModeExit() OVERRIDE; |
| 60 | 61 |
| 61 // MemoryPressureObserver: | 62 // MemoryPressureObserver: |
| 62 virtual void OnMemoryPressure( | 63 virtual void OnMemoryPressure( |
| 63 MemoryPressureObserver::MemoryPressure pressure) OVERRIDE; | 64 MemoryPressureObserver::MemoryPressure pressure) OVERRIDE; |
| 64 virtual ResourceManagerDelegate* GetDelegate() OVERRIDE; | 65 virtual ResourceManagerDelegate* GetDelegate() OVERRIDE; |
| 65 | 66 |
| 66 // aura::WindowObserver: | 67 // WindowListProviderObserver: |
| 67 virtual void OnWindowStackingChanged(aura::Window* window) OVERRIDE; | 68 virtual void OnActivityStackingChanged() OVERRIDE; |
| 68 | 69 |
| 69 private: | 70 private: |
| 70 // Manage the resources for our activities. | 71 // Manage the resources for our activities. |
| 71 void ManageResource(); | 72 void ManageResource(); |
| 72 | 73 |
| 73 // Order our activity list to the order of activities of the stream. | 74 // Order our activity list to the order of activities of the stream. |
| 74 // TODO(skuhne): Once the ActivityManager is responsible to create this list | 75 // TODO(skuhne): Once the ActivityManager is responsible to create this list |
| 75 // for us, we can remove this code here. | 76 // for us, we can remove this code here. |
| 76 void UpdateActivityOrder(); | 77 void UpdateActivityOrder(); |
| 77 | 78 |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 121 ResourceManagerImpl::ResourceManagerImpl(ResourceManagerDelegate* delegate) | 122 ResourceManagerImpl::ResourceManagerImpl(ResourceManagerDelegate* delegate) |
| 122 : delegate_(delegate), | 123 : delegate_(delegate), |
| 123 current_memory_pressure_(MemoryPressureObserver::MEMORY_PRESSURE_UNKNOWN), | 124 current_memory_pressure_(MemoryPressureObserver::MEMORY_PRESSURE_UNKNOWN), |
| 124 memory_pressure_notifier_(new MemoryPressureNotifier(this)), | 125 memory_pressure_notifier_(new MemoryPressureNotifier(this)), |
| 125 pause_(false), | 126 pause_(false), |
| 126 queued_command_(false), | 127 queued_command_(false), |
| 127 activity_order_changed_(false), | 128 activity_order_changed_(false), |
| 128 in_overview_mode_(false), | 129 in_overview_mode_(false), |
| 129 in_splitview_mode_(false) { | 130 in_splitview_mode_(false) { |
| 130 WindowManager::GetInstance()->AddObserver(this); | 131 WindowManager::GetInstance()->AddObserver(this); |
| 132 WindowManager::GetInstance()->GetWindowListProvider()->AddObserver(this); | |
| 131 ActivityManager::Get()->AddObserver(this); | 133 ActivityManager::Get()->AddObserver(this); |
| 132 } | 134 } |
| 133 | 135 |
| 134 ResourceManagerImpl::~ResourceManagerImpl() { | 136 ResourceManagerImpl::~ResourceManagerImpl() { |
| 135 ActivityManager::Get()->RemoveObserver(this); | 137 ActivityManager::Get()->RemoveObserver(this); |
| 138 WindowManager::GetInstance()->GetWindowListProvider()->RemoveObserver(this); | |
| 136 WindowManager::GetInstance()->RemoveObserver(this); | 139 WindowManager::GetInstance()->RemoveObserver(this); |
| 137 | 140 |
| 138 while (!activity_list_.empty()) | 141 while (!activity_list_.empty()) |
| 139 OnActivityEnding(activity_list_.front()); | 142 OnActivityEnding(activity_list_.front()); |
| 140 } | 143 } |
| 141 | 144 |
| 142 void ResourceManagerImpl::SetMemoryPressureAndStopMonitoring( | 145 void ResourceManagerImpl::SetMemoryPressureAndStopMonitoring( |
| 143 MemoryPressureObserver::MemoryPressure pressure) { | 146 MemoryPressureObserver::MemoryPressure pressure) { |
| 144 memory_pressure_notifier_->StopObserving(); | 147 memory_pressure_notifier_->StopObserving(); |
| 145 OnMemoryPressure(pressure); | 148 OnMemoryPressure(pressure); |
| 146 } | 149 } |
| 147 | 150 |
| 148 void ResourceManagerImpl::OnActivityStarted(Activity* activity) { | 151 void ResourceManagerImpl::OnActivityStarted(Activity* activity) { |
| 149 // As long as we have to manage the list of activities ourselves, we need to | 152 // As long as we have to manage the list of activities ourselves, we need to |
| 150 // order it here. | 153 // order it here. |
| 151 activity_list_.push_back(activity); | 154 activity_list_.push_back(activity); |
| 152 UpdateActivityOrder(); | 155 UpdateActivityOrder(); |
| 153 // Update the activity states. | 156 // Update the activity states. |
| 154 ManageResource(); | 157 ManageResource(); |
| 155 // Remember that the activity order has changed. | 158 // Remember that the activity order has changed. |
| 156 activity_order_changed_ = true; | 159 activity_order_changed_ = true; |
| 157 activity->GetWindow()->AddObserver(this); | |
| 158 } | 160 } |
| 159 | 161 |
| 160 void ResourceManagerImpl::OnActivityEnding(Activity* activity) { | 162 void ResourceManagerImpl::OnActivityEnding(Activity* activity) { |
| 161 DCHECK(activity->GetWindow()); | 163 DCHECK(activity->GetWindow()); |
| 162 activity->GetWindow()->RemoveObserver(this); | |
| 163 // Remove the activity from the list again. | 164 // Remove the activity from the list again. |
| 164 std::vector<Activity*>::iterator it = | 165 std::vector<Activity*>::iterator it = |
| 165 std::find(activity_list_.begin(), activity_list_.end(), activity); | 166 std::find(activity_list_.begin(), activity_list_.end(), activity); |
| 166 DCHECK(it != activity_list_.end()); | 167 DCHECK(it != activity_list_.end()); |
| 167 activity_list_.erase(it); | 168 activity_list_.erase(it); |
| 168 // Remember that the activity order has changed. | 169 // Remember that the activity order has changed. |
| 169 activity_order_changed_ = true; | 170 activity_order_changed_ = true; |
| 170 } | 171 } |
| 171 | 172 |
| 172 void ResourceManagerImpl::OnOverviewModeEnter() { | 173 void ResourceManagerImpl::OnOverviewModeEnter() { |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 185 ManageResource(); | 186 ManageResource(); |
| 186 } | 187 } |
| 187 | 188 |
| 188 | 189 |
| 189 void ResourceManagerImpl::OnSplitViewModeExit() { | 190 void ResourceManagerImpl::OnSplitViewModeExit() { |
| 190 // We don't do immediately something yet. The next ManageResource call will | 191 // We don't do immediately something yet. The next ManageResource call will |
| 191 // come soon. | 192 // come soon. |
| 192 in_splitview_mode_ = false; | 193 in_splitview_mode_ = false; |
| 193 } | 194 } |
| 194 | 195 |
| 195 void ResourceManagerImpl::OnWindowStackingChanged(aura::Window* window) { | 196 void ResourceManagerImpl::OnActivityStackingChanged() { |
| 196 // TODO(skuhne): This needs to be changed to some WindowListProvider observer | 197 // TODO(skuhne): This needs to be changed to some WindowListProvider observer |
| 197 // if we decouple window order from activity order. | 198 // if we decouple window order from activity order. |
| 199 activity_order_changed_ = true; | |
| 200 if (pause_) { | |
|
oshima
2014/09/09 18:28:37
we don't need pause now, do we?
Mr4D (OOO till 08-26)
2014/09/10 00:01:58
It's used for unit tests (and it might come back f
oshima
2014/09/10 01:03:30
Acknowledged.
| |
| 201 queued_command_ = true; | |
| 202 return; | |
| 203 } | |
| 198 | 204 |
| 199 // No need to do anything while being in overview mode. | 205 // No need to do anything while being in overview mode. |
| 200 if (in_overview_mode_) | 206 if (in_overview_mode_) |
| 201 return; | 207 return; |
| 202 | 208 |
| 203 // As long as we have to manage the list of activities ourselves, we need to | 209 // As long as we have to manage the list of activities ourselves, we need to |
| 204 // order it here. | 210 // order it here. |
| 205 UpdateActivityOrder(); | 211 UpdateActivityOrder(); |
| 206 | 212 |
| 207 // Manage the resources of each activity. | 213 // Manage the resources of each activity. |
| (...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 393 } | 399 } |
| 394 | 400 |
| 395 ResourceManager::ResourceManager() {} | 401 ResourceManager::ResourceManager() {} |
| 396 | 402 |
| 397 ResourceManager::~ResourceManager() { | 403 ResourceManager::~ResourceManager() { |
| 398 DCHECK(instance); | 404 DCHECK(instance); |
| 399 instance = NULL; | 405 instance = NULL; |
| 400 } | 406 } |
| 401 | 407 |
| 402 } // namespace athena | 408 } // namespace athena |
| OLD | NEW |