| OLD | NEW |
| (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 #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 | |
| 13 namespace aura { | |
| 14 class Window; | |
| 15 } | |
| 16 | |
| 17 namespace content { | |
| 18 class BrowserContext; | |
| 19 } | |
| 20 | |
| 21 namespace athena { | |
| 22 | |
| 23 class AppActivity; | |
| 24 | |
| 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(); | |
| 34 | |
| 35 // Register an |AppActivity| with this application. | |
| 36 void RegisterAppActivity(AppActivity* app_activity); | |
| 37 | |
| 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); | |
| 43 | |
| 44 // Returns the number of activities/windows with this application. | |
| 45 int NumberOfActivities() const { return activity_list_.size(); } | |
| 46 | |
| 47 // Returns the |AppActivity| at |index|. It will return NULL if an invalid | |
| 48 // index was specified. | |
| 49 AppActivity* GetAppActivityAt(size_t index); | |
| 50 | |
| 51 // Unload all application associated activities to save resources. | |
| 52 void Unload(); | |
| 53 | |
| 54 // Returns true if the application is in the unloaded state. | |
| 55 bool IsUnloaded() { return unloaded_activity_proxy_ != NULL; } | |
| 56 | |
| 57 content::BrowserContext* browser_context() const { return browser_context_; } | |
| 58 const std::string& app_id() const { return app_id_; } | |
| 59 | |
| 60 AppActivityProxy* unloaded_activity_proxy_for_test() { | |
| 61 return unloaded_activity_proxy_; | |
| 62 } | |
| 63 | |
| 64 protected: | |
| 65 friend AppActivityProxy; | |
| 66 | |
| 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); | |
| 70 | |
| 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); | |
| 75 | |
| 76 private: | |
| 77 // Move the window before the most recently used application window. | |
| 78 void MoveBeforeMruApplicationWindow(aura::Window* window); | |
| 79 | |
| 80 // A list of all activities associated with this application. | |
| 81 std::vector<AppActivity*> activity_list_; | |
| 82 | |
| 83 // The application id for this proxy. | |
| 84 std::string app_id_; | |
| 85 | |
| 86 // The browser context of the user. | |
| 87 content::BrowserContext* browser_context_; | |
| 88 | |
| 89 // When the activity is unloaded this is the AppActivityProxy. The object is | |
| 90 // owned the the ActivityManager. | |
| 91 AppActivityProxy* unloaded_activity_proxy_; | |
| 92 | |
| 93 // The presentation values. | |
| 94 SkColor color_; | |
| 95 base::string16 title_; | |
| 96 gfx::ImageSkia image_; | |
| 97 | |
| 98 DISALLOW_COPY_AND_ASSIGN(AppActivityRegistry); | |
| 99 }; | |
| 100 | |
| 101 } // namespace athena | |
| 102 | |
| 103 #endif // ATHENA_CONTENT_APP_ACTIVITY_REGISTRY_H_ | |
| OLD | NEW |