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

Side by Side Diff: apps/app_lifetime_monitor.h

Issue 2729503007: Remove Profile usage from //apps (Closed)
Patch Set: deps Created 3 years, 8 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
« no previous file with comments | « apps/DEPS ('k') | apps/app_lifetime_monitor.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef APPS_APP_LIFETIME_MONITOR_H_ 5 #ifndef APPS_APP_LIFETIME_MONITOR_H_
6 #define APPS_APP_LIFETIME_MONITOR_H_ 6 #define APPS_APP_LIFETIME_MONITOR_H_
7 7
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/observer_list.h" 11 #include "base/observer_list.h"
12 #include "components/keyed_service/core/keyed_service.h" 12 #include "components/keyed_service/core/keyed_service.h"
13 #include "content/public/browser/notification_observer.h" 13 #include "content/public/browser/notification_observer.h"
14 #include "content/public/browser/notification_registrar.h" 14 #include "content/public/browser/notification_registrar.h"
15 #include "extensions/browser/app_window/app_window_registry.h" 15 #include "extensions/browser/app_window/app_window_registry.h"
16 16
17 class Profile; 17 namespace content {
18 class BrowserContext;
19 }
18 20
19 namespace apps { 21 namespace apps {
20 22
21 // Observes startup of apps and their windows and notifies observers of these 23 // Observes startup of apps and their windows and notifies observers of these
22 // events. 24 // events.
23 class AppLifetimeMonitor : public KeyedService, 25 class AppLifetimeMonitor : public KeyedService,
24 public content::NotificationObserver, 26 public content::NotificationObserver,
25 public extensions::AppWindowRegistry::Observer { 27 public extensions::AppWindowRegistry::Observer {
26 public: 28 public:
27 class Observer { 29 class Observer {
28 public: 30 public:
29 // Called when the app starts running. 31 // Called when the app starts running.
30 virtual void OnAppStart(Profile* profile, const std::string& app_id) {} 32 virtual void OnAppStart(content::BrowserContext* context,
33 const std::string& app_id) {}
31 // Called when the app becomes active to the user, i.e. the first window 34 // Called when the app becomes active to the user, i.e. the first window
32 // becomes visible. 35 // becomes visible.
33 virtual void OnAppActivated(Profile* profile, const std::string& app_id) {} 36 virtual void OnAppActivated(content::BrowserContext* context,
37 const std::string& app_id) {}
34 // Called when the app becomes inactive to the user, i.e. the last window is 38 // Called when the app becomes inactive to the user, i.e. the last window is
35 // hidden or closed. 39 // hidden or closed.
36 virtual void OnAppDeactivated(Profile* profile, const std::string& app_id) { 40 virtual void OnAppDeactivated(content::BrowserContext* context,
37 } 41 const std::string& app_id) {}
38 // Called when the app stops running. 42 // Called when the app stops running.
39 virtual void OnAppStop(Profile* profile, const std::string& app_id) {} 43 virtual void OnAppStop(content::BrowserContext* context,
44 const std::string& app_id) {}
40 45
41 protected: 46 protected:
42 virtual ~Observer() {} 47 virtual ~Observer() {}
43 }; 48 };
44 49
45 explicit AppLifetimeMonitor(Profile* profile); 50 explicit AppLifetimeMonitor(content::BrowserContext* context);
46 ~AppLifetimeMonitor() override; 51 ~AppLifetimeMonitor() override;
47 52
48 void AddObserver(Observer* observer); 53 void AddObserver(Observer* observer);
49 void RemoveObserver(Observer* observer); 54 void RemoveObserver(Observer* observer);
50 55
51 private: 56 private:
52 // content::NotificationObserver overrides: 57 // content::NotificationObserver overrides:
53 void Observe(int type, 58 void Observe(int type,
54 const content::NotificationSource& source, 59 const content::NotificationSource& source,
55 const content::NotificationDetails& details) override; 60 const content::NotificationDetails& details) override;
56 61
57 // extensions::AppWindowRegistry::Observer overrides: 62 // extensions::AppWindowRegistry::Observer overrides:
58 void OnAppWindowRemoved(extensions::AppWindow* app_window) override; 63 void OnAppWindowRemoved(extensions::AppWindow* app_window) override;
59 void OnAppWindowHidden(extensions::AppWindow* app_window) override; 64 void OnAppWindowHidden(extensions::AppWindow* app_window) override;
60 void OnAppWindowShown(extensions::AppWindow* app_window, 65 void OnAppWindowShown(extensions::AppWindow* app_window,
61 bool was_hidden) override; 66 bool was_hidden) override;
62 67
63 // KeyedService overrides: 68 // KeyedService overrides:
64 void Shutdown() override; 69 void Shutdown() override;
65 70
66 bool HasOtherVisibleAppWindows(extensions::AppWindow* app_window) const; 71 bool HasOtherVisibleAppWindows(extensions::AppWindow* app_window) const;
67 72
68 void NotifyAppStart(const std::string& app_id); 73 void NotifyAppStart(const std::string& app_id);
69 void NotifyAppActivated(const std::string& app_id); 74 void NotifyAppActivated(const std::string& app_id);
70 void NotifyAppDeactivated(const std::string& app_id); 75 void NotifyAppDeactivated(const std::string& app_id);
71 void NotifyAppStop(const std::string& app_id); 76 void NotifyAppStop(const std::string& app_id);
72 77
73 content::NotificationRegistrar registrar_; 78 content::NotificationRegistrar registrar_;
74 Profile* profile_; 79 content::BrowserContext* context_;
75 base::ObserverList<Observer> observers_; 80 base::ObserverList<Observer> observers_;
76 81
77 DISALLOW_COPY_AND_ASSIGN(AppLifetimeMonitor); 82 DISALLOW_COPY_AND_ASSIGN(AppLifetimeMonitor);
78 }; 83 };
79 84
80 } // namespace apps 85 } // namespace apps
81 86
82 #endif // APPS_APP_LIFETIME_MONITOR_H_ 87 #endif // APPS_APP_LIFETIME_MONITOR_H_
OLDNEW
« no previous file with comments | « apps/DEPS ('k') | apps/app_lifetime_monitor.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698