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
3 // found in the LICENSE file.
5 #include "athena/activity/activity_manager_impl.h"
9 #include "athena/activity/public/activity.h"
10 #include "athena/activity/public/activity_manager_observer.h"
11 #include "athena/activity/public/activity_view_manager.h"
12 #include "base/logging.h"
13 #include "base/observer_list.h"
19 ActivityManager
* instance
= NULL
;
23 ActivityManagerImpl::ActivityManagerImpl() {
28 ActivityManagerImpl::~ActivityManagerImpl() {
29 while (!activities_
.empty())
30 delete activities_
.front();
32 CHECK_EQ(this, instance
);
36 void ActivityManagerImpl::AddActivity(Activity
* activity
) {
37 CHECK(activities_
.end() ==
38 std::find(activities_
.begin(), activities_
.end(), activity
));
39 activities_
.push_back(activity
);
40 ActivityViewManager
* manager
= ActivityViewManager::Get();
41 manager
->AddActivity(activity
);
42 FOR_EACH_OBSERVER(ActivityManagerObserver
,
44 OnActivityStarted(activity
));
47 void ActivityManagerImpl::RemoveActivity(Activity
* activity
) {
48 std::vector
<Activity
*>::iterator find
=
49 std::find(activities_
.begin(), activities_
.end(), activity
);
50 FOR_EACH_OBSERVER(ActivityManagerObserver
,
52 OnActivityEnding(activity
));
53 if (find
!= activities_
.end()) {
54 activities_
.erase(find
);
55 ActivityViewManager
* manager
= ActivityViewManager::Get();
56 manager
->RemoveActivity(activity
);
60 void ActivityManagerImpl::UpdateActivity(Activity
* activity
) {
61 ActivityViewManager
* manager
= ActivityViewManager::Get();
62 manager
->UpdateActivity(activity
);
65 void ActivityManagerImpl::AddObserver(ActivityManagerObserver
* observer
) {
66 observers_
.AddObserver(observer
);
69 void ActivityManagerImpl::RemoveObserver(ActivityManagerObserver
* observer
) {
70 observers_
.RemoveObserver(observer
);
74 ActivityManager
* ActivityManager::Create() {
75 ActivityViewManager::Create();
77 new ActivityManagerImpl();
82 ActivityManager
* ActivityManager::Get() {
86 void ActivityManager::Shutdown() {
89 ActivityViewManager::Shutdown();