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

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: Addressed 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
10 namespace athena {
11
12 class AppRegistryImpl : public AppRegistry {
13 public:
14 AppRegistryImpl();
15 virtual ~AppRegistryImpl();
16
17 // AppRegistry:
18 virtual void SetDelegate(AppContentControlDelegate* delegate) OVERRIDE;
19 virtual AppContentControlDelegate* GetDelegate() OVERRIDE;
20 virtual AppActivityRegistry* GetAppActivityRegistry(
21 const std::string& app_id,
22 content::BrowserContext* browser_context) OVERRIDE;
23 virtual int NumberOfApplications() const OVERRIDE { return app_list_.size(); }
24 virtual void RemoveAppActivityRegistry(
25 AppActivityRegistry* registry) OVERRIDE;
26
27 private:
28 std::vector<AppActivityRegistry*> app_list_;
29
30 scoped_ptr<AppContentControlDelegate> delegate_;
31
32 DISALLOW_COPY_AND_ASSIGN(AppRegistryImpl);
33 };
34
35 namespace {
36
37 AppRegistryImpl* instance = NULL;
38
39 } // namespace
40
41 AppRegistryImpl::AppRegistryImpl() :
42 delegate_(AppContentControlDelegate::CreateAppContentControlDelegate()) {}
43
44 AppRegistryImpl::~AppRegistryImpl() {
45 DCHECK(app_list_.empty());
46 }
47
48 void AppRegistryImpl::SetDelegate(AppContentControlDelegate* delegate) {
49 DCHECK(delegate);
50 delegate_.reset(delegate);
51 }
52
53 AppContentControlDelegate* AppRegistryImpl::GetDelegate() {
54 return delegate_.get();
55 }
56
57 AppActivityRegistry* AppRegistryImpl::GetAppActivityRegistry(
58 const std::string& app_id,
59 content::BrowserContext* browser_context) {
60 // Search for an existing proxy.
61 for (std::vector<AppActivityRegistry*>::iterator it = app_list_.begin();
62 it != app_list_.end(); ++it) {
63 if ((*it)->app_id() == app_id &&
64 (*it)->browser_context() == browser_context)
65 return *it;
66 }
67
68 // Create and return a new application object.
69 AppActivityRegistry* app_activity_registry =
70 new AppActivityRegistry(app_id, browser_context);
71 app_list_.push_back(app_activity_registry);
72 return app_activity_registry;
73 }
74
75 void AppRegistryImpl::RemoveAppActivityRegistry(AppActivityRegistry* registry) {
76 std::vector<AppActivityRegistry*>::iterator item =
77 std::find(app_list_.begin(), app_list_.end(), registry);
78 CHECK(item != app_list_.end());
79 app_list_.erase(item);
80 }
81
82 // static
83 void AppRegistry::Create() {
84 DCHECK(!instance);
85 instance = new AppRegistryImpl();
86 }
87
88 // static
89 AppRegistry* AppRegistry::Get() {
90 DCHECK(instance);
91 return instance;
92 }
93
94 // static
95 void AppRegistry::ShutDown() {
96 DCHECK(instance);
97 delete instance;
98 }
99
100 AppRegistry::AppRegistry() {}
101
102 AppRegistry::~AppRegistry() {
103 instance = NULL;
104 }
105
106 } // namespace athena
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698