Updating trunk VERSION from 2139.0 to 2140.0
[chromium-blink-merge.git] / athena / content / app_activity_registry.h
blob14ef7de3945ba25b7e9ec445b63f1b786f07307b
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_
8 #include <vector>
10 #include "athena/activity/public/activity_view_model.h"
11 #include "athena/content/app_activity_proxy.h"
13 namespace aura {
14 class Window;
17 namespace content {
18 class BrowserContext;
21 namespace athena {
23 class AppActivity;
25 // This class keeps track of all existing |AppActivity|s and shuts down all of
26 // them when the application gets unloaded to save memory. It will then replace
27 // the |AppActivity| in the Activity list as proxy to allow restarting of the
28 // application.
29 class ATHENA_EXPORT AppActivityRegistry {
30 public:
31 AppActivityRegistry(const std::string& app_id,
32 content::BrowserContext* browser_context);
33 virtual ~AppActivityRegistry();
35 // Register an |AppActivity| with this application.
36 void RegisterAppActivity(AppActivity* app_activity);
38 // Unregister a previously attached |AppActivity|.
39 // Note that detaching the last |AppActivity| will delete this object - unless
40 // the resource manager was trying to unload the application.
41 // Note furthermore that Detach can be called without ever being registered.
42 void UnregisterAppActivity(AppActivity* app_activity);
44 // Returns the number of activities/windows with this application.
45 int NumberOfActivities() const { return activity_list_.size(); }
47 // Returns the |AppActivity| at |index|. It will return NULL if an invalid
48 // index was specified.
49 AppActivity* GetAppActivityAt(size_t index);
51 // Unload all application associated activities to save resources.
52 void Unload();
54 // Returns true if the application is in the unloaded state.
55 bool IsUnloaded() { return unloaded_activity_proxy_ != NULL; }
57 content::BrowserContext* browser_context() const { return browser_context_; }
58 const std::string& app_id() const { return app_id_; }
60 AppActivityProxy* unloaded_activity_proxy_for_test() {
61 return unloaded_activity_proxy_;
64 protected:
65 friend AppActivityProxy;
67 // When the |AppActivityProxy| gets destroyed it should call this function
68 // to disconnect from this object. This call might destroy |this|.
69 void ProxyDestroyed(AppActivityProxy* proxy);
71 // When called by the |AppActivityProxy| to restart the application, it can
72 // cause the application to restart. When that happens the proxy will get
73 // destroyed. After this call |this| might be destroyed.
74 void RestartApplication(AppActivityProxy* proxy);
76 private:
77 // Move the window before the most recently used application window.
78 void MoveBeforeMruApplicationWindow(aura::Window* window);
80 // A list of all activities associated with this application.
81 std::vector<AppActivity*> activity_list_;
83 // The application id for this proxy.
84 std::string app_id_;
86 // The browser context of the user.
87 content::BrowserContext* browser_context_;
89 // When the activity is unloaded this is the AppActivityProxy. The object is
90 // owned the the ActivityManager.
91 AppActivityProxy* unloaded_activity_proxy_;
93 // The presentation values.
94 SkColor color_;
95 base::string16 title_;
96 gfx::ImageSkia image_;
98 DISALLOW_COPY_AND_ASSIGN(AppActivityRegistry);
101 } // namespace athena
103 #endif // ATHENA_CONTENT_APP_ACTIVITY_REGISTRY_H_