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 #ifndef ATHENA_CONTENT_APP_ACTIVITY_REGISTRY_H_
6 #define ATHENA_CONTENT_APP_ACTIVITY_REGISTRY_H_
10 #include "athena/activity/public/activity_view_model.h"
11 #include "athena/content/app_activity_proxy.h"
12 #include "ui/gfx/image/image_skia.h"
26 // This class keeps track of all existing |AppActivity|s and shuts down all of
27 // them when the application gets unloaded to save memory. It will then replace
28 // the |AppActivity| in the Activity list as proxy to allow restarting of the
30 class ATHENA_EXPORT AppActivityRegistry
{
32 AppActivityRegistry(const std::string
& app_id
,
33 content::BrowserContext
* browser_context
);
34 ~AppActivityRegistry();
36 // Register an |AppActivity| with this application.
37 void RegisterAppActivity(AppActivity
* app_activity
);
39 // Unregister a previously attached |AppActivity|.
40 // Note that detaching the last |AppActivity| will delete this object - unless
41 // the resource manager was trying to unload the application.
42 // Note furthermore that Detach can be called without ever being registered.
43 void UnregisterAppActivity(AppActivity
* app_activity
);
45 // Returns the number of activities/windows with this application.
46 int NumberOfActivities() const { return activity_list_
.size(); }
48 // Returns the |AppActivity| at |index|. It will return nullptr if an invalid
49 // index was specified.
50 AppActivity
* GetAppActivityAt(size_t index
);
52 // Unload all application associated activities to save resources.
55 // Returns true if the application is in the unloaded state.
56 bool IsUnloaded() { return unloaded_activity_proxy_
!= nullptr; }
58 content::BrowserContext
* browser_context() const { return browser_context_
; }
59 const std::string
& app_id() const { return app_id_
; }
61 // Returns the proxy - if there is one. This will get used by a newly created
62 // activity to position itself in its place before it get destroyed.
63 Activity
* unloaded_activity_proxy() { return unloaded_activity_proxy_
; }
66 friend AppActivityProxy
;
68 // When the |AppActivityProxy| gets destroyed it should call this function
69 // to disconnect from this object. This call might destroy |this|.
70 void ProxyDestroyed(AppActivityProxy
* proxy
);
72 // When called by the |AppActivityProxy| to restart the application, it can
73 // cause the application to restart. When that happens the proxy will get
74 // destroyed. After this call |this| might be destroyed.
75 void RestartApplication(AppActivityProxy
* proxy
);
78 // Called if an unload of an application should take place asynchronously to
79 // avoid object destruction within an observer handler.
82 // Gets most recently used AppAcitivty that belongs to the same application.
83 AppActivity
* GetMruActivity();
85 // A list of all activities associated with this application.
86 std::vector
<AppActivity
*> activity_list_
;
88 // The application id for this proxy.
91 // The browser context of the user.
92 content::BrowserContext
* browser_context_
;
94 // When the activity is unloaded this is the AppActivityProxy. The object is
95 // owned the the ActivityManager.
96 AppActivityProxy
* unloaded_activity_proxy_
;
98 // The presentation values.
100 base::string16 title_
;
101 gfx::ImageSkia image_
;
103 DISALLOW_COPY_AND_ASSIGN(AppActivityRegistry
);
106 } // namespace athena
108 #endif // ATHENA_CONTENT_APP_ACTIVITY_REGISTRY_H_