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" | 15 #include "athena/wm/public/window_list_provider.h" |
16 #include "athena/wm/public/window_list_provider_observer.h" | 16 #include "athena/wm/public/window_list_provider_observer.h" |
17 #include "athena/wm/public/window_manager.h" | 17 #include "athena/wm/public/window_manager.h" |
18 #include "athena/wm/public/window_manager_observer.h" | 18 #include "athena/wm/public/window_manager_observer.h" |
19 #include "base/logging.h" | 19 #include "base/logging.h" |
20 #include "base/memory/scoped_ptr.h" | 20 #include "base/memory/scoped_ptr.h" |
21 #include "base/time/time.h" | 21 #include "base/time/time.h" |
22 #include "ui/aura/window.h" | 22 #include "ui/aura/window.h" |
23 | 23 |
24 namespace athena { | 24 namespace athena { |
| 25 namespace { |
25 | 26 |
26 class ResourceManagerImpl : public ResourceManager, | 27 class ResourceManagerImpl : public ResourceManager, |
27 public WindowManagerObserver, | 28 public WindowManagerObserver, |
28 public ActivityManagerObserver, | 29 public ActivityManagerObserver, |
29 public MemoryPressureObserver, | 30 public MemoryPressureObserver, |
30 public WindowListProviderObserver { | 31 public WindowListProviderObserver { |
31 public: | 32 public: |
32 ResourceManagerImpl(ResourceManagerDelegate* delegate); | 33 ResourceManagerImpl(ResourceManagerDelegate* delegate); |
33 virtual ~ResourceManagerImpl(); | 34 virtual ~ResourceManagerImpl(); |
34 | 35 |
(...skipping 417 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
452 void ResourceManagerImpl::OnMemoryPressureIncreased() { | 453 void ResourceManagerImpl::OnMemoryPressureIncreased() { |
453 // By setting the timer to Now, the next call will immediately be performed. | 454 // By setting the timer to Now, the next call will immediately be performed. |
454 next_resource_management_time_ = base::Time::Now(); | 455 next_resource_management_time_ = base::Time::Now(); |
455 } | 456 } |
456 | 457 |
457 bool ResourceManagerImpl::AllowedToUnloadActivity() { | 458 bool ResourceManagerImpl::AllowedToUnloadActivity() { |
458 return current_memory_pressure_ != MEMORY_PRESSURE_LOW && | 459 return current_memory_pressure_ != MEMORY_PRESSURE_LOW && |
459 base::Time::Now() >= next_resource_management_time_; | 460 base::Time::Now() >= next_resource_management_time_; |
460 } | 461 } |
461 | 462 |
| 463 } // namespace |
| 464 |
462 // static | 465 // static |
463 void ResourceManager::Create() { | 466 void ResourceManager::Create() { |
464 DCHECK(!instance); | 467 DCHECK(!instance); |
465 instance = new ResourceManagerImpl( | 468 instance = new ResourceManagerImpl( |
466 ResourceManagerDelegate::CreateResourceManagerDelegate()); | 469 ResourceManagerDelegate::CreateResourceManagerDelegate()); |
467 } | 470 } |
468 | 471 |
469 // static | 472 // static |
470 ResourceManager* ResourceManager::Get() { | 473 ResourceManager* ResourceManager::Get() { |
471 return instance; | 474 return instance; |
472 } | 475 } |
473 | 476 |
474 // static | 477 // static |
475 void ResourceManager::Shutdown() { | 478 void ResourceManager::Shutdown() { |
476 DCHECK(instance); | 479 DCHECK(instance); |
477 delete instance; | 480 delete instance; |
478 instance = NULL; | 481 instance = NULL; |
479 } | 482 } |
480 | 483 |
481 ResourceManager::ResourceManager() {} | 484 ResourceManager::ResourceManager() {} |
482 | 485 |
483 ResourceManager::~ResourceManager() { | 486 ResourceManager::~ResourceManager() { |
484 DCHECK(instance); | 487 DCHECK(instance); |
485 instance = NULL; | 488 instance = NULL; |
486 } | 489 } |
487 | 490 |
488 } // namespace athena | 491 } // namespace athena |
OLD | NEW |