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

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
oshima 2014/08/19 21:22:25 // AppRegistry: I think all impl methods can be p
Mr4D (OOO till 08-26) 2014/08/20 14:34:40 Added comment. However - moving private here make
oshima 2014/08/20 19:51:49 I always prefer to limit the exposure of API. This
Mr4D (OOO till 08-26) 2014/08/20 22:34:21 Acknowledged.
17 virtual void SetDelegate(AppContentControlDelegate* delegate) OVERRIDE;
18 virtual AppContentControlDelegate* GetDelegate() OVERRIDE;
19 virtual AppActivityRegistry* GetAppActivityRegistry(
20 const std::string& app_id,
21 content::BrowserContext* browser_context) OVERRIDE;
22 virtual int NumberOfApplications() const OVERRIDE { return app_list_.size(); }
23
24 protected:
oshima 2014/08/20 19:51:49 why not private: ?
Mr4D (OOO till 08-26) 2014/08/20 22:34:22 Done.
25 // Only the |AppActivityRegistry| can remove itself.
26 friend AppActivityRegistry;
27
28 // Removes an activity registry for an application from the list of known
29 // applications.
30 virtual void RemoveAppActivityRegistry(
31 AppActivityRegistry* registry) OVERRIDE;
32
33 private:
34 std::vector<AppActivityRegistry*> app_list_;
35
36 scoped_ptr<AppContentControlDelegate> delegate_;
37
38 DISALLOW_COPY_AND_ASSIGN(AppRegistryImpl);
39 };
40
41 namespace {
42
43 // The global instance.
oshima 2014/08/19 21:22:25 "global" is a bit mislaeding as this is file scope
Mr4D (OOO till 08-26) 2014/08/20 14:34:40 Done.
44 AppRegistryImpl* instance = NULL;
45
46 } // namespace
47
48 AppRegistryImpl::AppRegistryImpl() :
49 delegate_(AppContentControlDelegate::CreateAppContentControlDelegate()) {}
50
51 AppRegistryImpl::~AppRegistryImpl() {
52 DCHECK(app_list_.empty());
53 }
54
55 void AppRegistryImpl::SetDelegate(AppContentControlDelegate* delegate) {
56 DCHECK(delegate);
57 delegate_.reset(delegate);
58 }
59
60 AppContentControlDelegate* AppRegistryImpl::GetDelegate() {
61 return delegate_.get();
62 }
63
64 AppActivityRegistry* AppRegistryImpl::GetAppActivityRegistry(
65 const std::string& app_id,
66 content::BrowserContext* browser_context) {
67 // Search for an existing proxy.
68 for (std::vector<AppActivityRegistry*>::iterator it = app_list_.begin();
69 it != app_list_.end(); ++it) {
70 if ((*it)->app_id() == app_id &&
71 (*it)->browser_context() == browser_context)
72 return *it;
73 }
74
75 // Create and return a new application object.
76 AppActivityRegistry* app_activity_registry =
77 new AppActivityRegistry(app_id, browser_context);
78 app_list_.push_back(app_activity_registry);
79 return app_activity_registry;
80 }
81
82 void AppRegistryImpl::RemoveAppActivityRegistry(AppActivityRegistry* registry) {
83 std::vector<AppActivityRegistry*>::iterator item =
84 std::find(app_list_.begin(), app_list_.end(), registry);
85 CHECK(item != app_list_.end());
86 app_list_.erase(item);
87 }
88
89 // static
90 void AppRegistry::Create() {
91 DCHECK(!instance);
92 instance = new AppRegistryImpl();
93 }
94
95 // static
96 AppRegistry* AppRegistry::Get() {
97 return instance;
98 }
99
100 // static
101 void AppRegistry::ShutDown() {
102 if (instance)
103 delete instance;
104 instance = NULL;
105 }
106
107 AppRegistry::AppRegistry() {}
108 AppRegistry::~AppRegistry() {}
109
110 } // namespace athena
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698