blob: b0074cbab3cfcc8e657578ecb396f465d425b0df (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
|
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "athena/activity/activity_manager_impl.h"
#include <algorithm>
#include "athena/activity/public/activity.h"
#include "athena/activity/public/activity_manager_observer.h"
#include "athena/activity/public/activity_view_manager.h"
#include "base/logging.h"
#include "base/observer_list.h"
namespace athena {
namespace {
ActivityManager* instance = NULL;
} // namespace
ActivityManagerImpl::ActivityManagerImpl() {
CHECK(!instance);
instance = this;
}
ActivityManagerImpl::~ActivityManagerImpl() {
while (!activities_.empty())
Activity::Delete(activities_.front());
CHECK_EQ(this, instance);
instance = NULL;
}
void ActivityManagerImpl::AddActivity(Activity* activity) {
CHECK(activities_.end() ==
std::find(activities_.begin(), activities_.end(), activity));
activities_.push_back(activity);
ActivityViewManager* manager = ActivityViewManager::Get();
manager->AddActivity(activity);
FOR_EACH_OBSERVER(ActivityManagerObserver,
observers_,
OnActivityStarted(activity));
}
void ActivityManagerImpl::RemoveActivity(Activity* activity) {
std::vector<Activity*>::iterator find =
std::find(activities_.begin(), activities_.end(), activity);
FOR_EACH_OBSERVER(ActivityManagerObserver,
observers_,
OnActivityEnding(activity));
if (find != activities_.end()) {
activities_.erase(find);
ActivityViewManager* manager = ActivityViewManager::Get();
manager->RemoveActivity(activity);
}
}
void ActivityManagerImpl::UpdateActivity(Activity* activity) {
ActivityViewManager* manager = ActivityViewManager::Get();
manager->UpdateActivity(activity);
}
void ActivityManagerImpl::AddObserver(ActivityManagerObserver* observer) {
observers_.AddObserver(observer);
}
void ActivityManagerImpl::RemoveObserver(ActivityManagerObserver* observer) {
observers_.RemoveObserver(observer);
}
// static
ActivityManager* ActivityManager::Create() {
ActivityViewManager::Create();
new ActivityManagerImpl();
CHECK(instance);
return instance;
}
ActivityManager* ActivityManager::Get() {
return instance;
}
void ActivityManager::Shutdown() {
CHECK(instance);
delete instance;
ActivityViewManager::Shutdown();
}
} // namespace athena
|