Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / athena / content / app_activity_registry.h
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 #ifndef ATHENA_CONTENT_APP_ACTIVITY_REGISTRY_H_
6 #define ATHENA_CONTENT_APP_ACTIVITY_REGISTRY_H_
7
8 #include <vector>
9
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"
13
14 namespace aura {
15 class Window;
16 }
17
18 namespace content {
19 class BrowserContext;
20 }
21
22 namespace athena {
23
24 class AppActivity;
25
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
29 // application.
30 class ATHENA_EXPORT AppActivityRegistry {
31  public:
32   AppActivityRegistry(const std::string& app_id,
33                       content::BrowserContext* browser_context);
34   ~AppActivityRegistry();
35
36   // Register an |AppActivity| with this application.
37   void RegisterAppActivity(AppActivity* app_activity);
38
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);
44
45   // Returns the number of activities/windows with this application.
46   int NumberOfActivities() const { return activity_list_.size(); }
47
48   // Returns the |AppActivity| at |index|. It will return nullptr if an invalid
49   // index was specified.
50   AppActivity* GetAppActivityAt(size_t index);
51
52   // Unload all application associated activities to save resources.
53   void Unload();
54
55   // Returns true if the application is in the unloaded state.
56   bool IsUnloaded() { return unloaded_activity_proxy_ != nullptr; }
57
58   content::BrowserContext* browser_context() const { return browser_context_; }
59   const std::string& app_id() const { return app_id_; }
60
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_; }
64
65  protected:
66   friend AppActivityProxy;
67
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);
71
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);
76
77  private:
78   // Called if an unload of an application should take place asynchronously to
79   // avoid object destruction within an observer handler.
80   void DelayedUnload();
81
82   // Gets most recently used AppAcitivty that belongs to the same application.
83   AppActivity* GetMruActivity();
84
85   // A list of all activities associated with this application.
86   std::vector<AppActivity*> activity_list_;
87
88   // The application id for this proxy.
89   std::string app_id_;
90
91   // The browser context of the user.
92   content::BrowserContext* browser_context_;
93
94   // When the activity is unloaded this is the AppActivityProxy. The object is
95   // owned the the ActivityManager.
96   AppActivityProxy* unloaded_activity_proxy_;
97
98   // The presentation values.
99   SkColor color_;
100   base::string16 title_;
101   gfx::ImageSkia image_;
102
103   DISALLOW_COPY_AND_ASSIGN(AppActivityRegistry);
104 };
105
106 }  // namespace athena
107
108 #endif  // ATHENA_CONTENT_APP_ACTIVITY_REGISTRY_H_