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

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: Merged with trunk 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_delegate.h"
9
10 namespace athena {
11
12 class AppRegistryImpl : public AppRegistry {
13 public:
14 AppRegistryImpl();
15 virtual ~AppRegistryImpl();
16
17 // Overrides the used AppContentDelegate. This function will own it
18 // afterwards. A value of NULL is invalid.
19 virtual void SetDelegate(AppContentDelegate* delegate) OVERRIDE;
20
21 // Retrieves the application content delegate. The ownership remains with this
22 // class.
23 virtual AppContentDelegate* GetDelegate() OVERRIDE;
24
25 // Returns an |AppActivityRegistry| for a given activity |app_id| and
26 // |browser_context|.
27 virtual AppActivityRegistry* GetAppActivityRegistry(
28 const std::string& app_id,
29 content::BrowserContext* browser_context) OVERRIDE;
30
31 // Returns the number of registered applications.
32 virtual int NumberOfApplications() const OVERRIDE { return app_list_.size(); }
33
34 protected:
35 // Only the |AppActivityRegistry| can remove itself.
36 friend AppActivityRegistry;
37
38 // Removes an activity registry for an application from the list of known
39 // applications.
40 virtual void RemoveAppActivityRegistry(
41 AppActivityRegistry* registry) OVERRIDE;
42
43 private:
44 std::vector<AppActivityRegistry*> app_list_;
45
46 scoped_ptr<AppContentDelegate> delegate_;
47
48 DISALLOW_COPY_AND_ASSIGN(AppRegistryImpl);
49 };
50
51 namespace {
52
53 // The global instance.
54 AppRegistryImpl* instance = NULL;
55
56 } // namespace
57
58 AppRegistryImpl::AppRegistryImpl() : delegate_(new AppContentDelegate) {}
59
60 AppRegistryImpl::~AppRegistryImpl() {
61 DCHECK(app_list_.empty());
62 }
63
64 void AppRegistryImpl::SetDelegate(AppContentDelegate* delegate) {
65 DCHECK(delegate);
66 delegate_.reset(delegate);
67 }
68
69 AppContentDelegate* AppRegistryImpl::GetDelegate() {
70 return delegate_.get();
71 }
72
73 AppActivityRegistry* AppRegistryImpl::GetAppActivityRegistry(
74 const std::string& app_id,
75 content::BrowserContext* browser_context) {
76 // Search for an existing proxy.
77 for (std::vector<AppActivityRegistry*>::iterator it = app_list_.begin();
78 it != app_list_.end(); ++it) {
79 if ((*it)->app_id() == app_id &&
80 (*it)->browser_context() == browser_context)
81 return *it;
82 }
83
84 // Create and return a new application object.
85 AppActivityRegistry* app_activity_registry =
86 new AppActivityRegistry(app_id, browser_context);
87 app_list_.push_back(app_activity_registry);
88 return app_activity_registry;
89 }
90
91 void AppRegistryImpl::RemoveAppActivityRegistry(AppActivityRegistry* registry) {
92 std::vector<AppActivityRegistry*>::iterator item =
93 std::find(app_list_.begin(), app_list_.end(), registry);
94 CHECK(item != app_list_.end());
95 app_list_.erase(item);
96 }
97
98 // static
99 void AppRegistry::Create() {
100 DCHECK(!instance);
101 instance = new AppRegistryImpl();
102 }
103
104 // static
105 AppRegistry* AppRegistry::Get() {
oshima 2014/08/19 21:22:24 DCHECK(instance);
Mr4D (OOO till 08-26) 2014/08/20 14:34:39 Done.
106 return instance;
107 }
108
109 // static
110 void AppRegistry::ShutDown() {
111 if (instance)
112 delete instance;
oshima 2014/08/19 21:22:24 DCHECK(instance); delete instance; (delete NU
Mr4D (OOO till 08-26) 2014/08/20 14:34:39 Done.
113 instance = NULL;
114 }
115
116 AppRegistry::AppRegistry() {}
oshima 2014/08/19 21:22:24 can you set instance in ctor/dtor?
Mr4D (OOO till 08-26) 2014/08/20 14:34:39 dtor changed.
117 AppRegistry::~AppRegistry() {}
118
119 } // namespace athena
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698