Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(27)

Side by Side Diff: athena/content/app_registry_impl.cc

Issue 477523002: Athena: Adding basic resource management framework (un-/re-loading) of V2 applications (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Aaaand another rebase. Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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.
4
5 #include "athena/content/public/app_registry.h"
6
7 #include "athena/content/app_activity_registry.h"
8 #include "athena/content/public/app_content_control_delegate.h"
9 #include "base/logging.h"
10
11 namespace athena {
12
13 class AppRegistryImpl : public AppRegistry {
14 public:
15 AppRegistryImpl();
16 virtual ~AppRegistryImpl();
17
18 // AppRegistry:
19 virtual void SetDelegate(AppContentControlDelegate* delegate) OVERRIDE;
20 virtual AppContentControlDelegate* GetDelegate() OVERRIDE;
21 virtual AppActivityRegistry* GetAppActivityRegistry(
22 const std::string& app_id,
23 content::BrowserContext* browser_context) OVERRIDE;
24 virtual int NumberOfApplications() const OVERRIDE { return app_list_.size(); }
25
26 private:
27 virtual void RemoveAppActivityRegistry(
28 AppActivityRegistry* registry) OVERRIDE;
29
30 std::vector<AppActivityRegistry*> app_list_;
31
32 scoped_ptr<AppContentControlDelegate> delegate_;
33
34 DISALLOW_COPY_AND_ASSIGN(AppRegistryImpl);
35 };
36
37 namespace {
38
39 AppRegistryImpl* instance = NULL;
40
41 } // namespace
42
43 AppRegistryImpl::AppRegistryImpl() :
44 delegate_(AppContentControlDelegate::CreateAppContentControlDelegate()) {}
45
46 AppRegistryImpl::~AppRegistryImpl() {
47 DCHECK(app_list_.empty());
48 }
49
50 void AppRegistryImpl::SetDelegate(AppContentControlDelegate* delegate) {
51 DCHECK(delegate);
52 delegate_.reset(delegate);
53 }
54
55 AppContentControlDelegate* AppRegistryImpl::GetDelegate() {
56 return delegate_.get();
57 }
58
59 AppActivityRegistry* AppRegistryImpl::GetAppActivityRegistry(
60 const std::string& app_id,
61 content::BrowserContext* browser_context) {
62 // Search for an existing proxy.
63 for (std::vector<AppActivityRegistry*>::iterator it = app_list_.begin();
64 it != app_list_.end(); ++it) {
65 if ((*it)->app_id() == app_id &&
66 (*it)->browser_context() == browser_context)
67 return *it;
68 }
69
70 // Create and return a new application object.
71 AppActivityRegistry* app_activity_registry =
72 new AppActivityRegistry(app_id, browser_context);
73 app_list_.push_back(app_activity_registry);
74 return app_activity_registry;
75 }
76
77 void AppRegistryImpl::RemoveAppActivityRegistry(AppActivityRegistry* registry) {
78 std::vector<AppActivityRegistry*>::iterator item =
79 std::find(app_list_.begin(), app_list_.end(), registry);
80 CHECK(item != app_list_.end());
81 app_list_.erase(item);
82 delete registry;
83 }
84
85 // static
86 void AppRegistry::Create() {
87 DCHECK(!instance);
88 instance = new AppRegistryImpl();
89 }
90
91 // static
92 AppRegistry* AppRegistry::Get() {
93 DCHECK(instance);
94 return instance;
95 }
96
97 // static
98 void AppRegistry::ShutDown() {
99 DCHECK(instance);
100 delete instance;
101 }
102
103 AppRegistry::AppRegistry() {}
104
105 AppRegistry::~AppRegistry() {
106 instance = NULL;
107 }
108
109 } // namespace athena
OLDNEW
« no previous file with comments | « athena/content/app_activity_unittest.cc ('k') | athena/content/delegate/app_content_control_delegate_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698