Updating trunk VERSION from 2139.0 to 2140.0
[chromium-blink-merge.git] / athena / activity / activity_manager_impl.cc
blobc1e1faa6afa87a49dbdedf2a1323a7ed2688ee2c
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"
7 #include <algorithm>
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"
15 namespace athena {
17 namespace {
19 ActivityManager* instance = NULL;
21 } // namespace
23 ActivityManagerImpl::ActivityManagerImpl() {
24 CHECK(!instance);
25 instance = this;
28 ActivityManagerImpl::~ActivityManagerImpl() {
29 while (!activities_.empty())
30 delete activities_.front();
32 CHECK_EQ(this, instance);
33 instance = NULL;
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,
43 observers_,
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,
51 observers_,
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);
73 // static
74 ActivityManager* ActivityManager::Create() {
75 ActivityViewManager::Create();
77 new ActivityManagerImpl();
78 CHECK(instance);
79 return instance;
82 ActivityManager* ActivityManager::Get() {
83 return instance;
86 void ActivityManager::Shutdown() {
87 CHECK(instance);
88 delete instance;
89 ActivityViewManager::Shutdown();
93 } // namespace athena