OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 CHROME_BROWSER_CHROMEOS_NOTE_TAKING_HELPER_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_NOTE_TAKING_HELPER_H_ |
6 #define CHROME_BROWSER_CHROMEOS_NOTE_TAKING_HELPER_H_ | 6 #define CHROME_BROWSER_CHROMEOS_NOTE_TAKING_HELPER_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/macros.h" | 11 #include "base/macros.h" |
12 #include "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" |
13 #include "base/observer_list.h" | 13 #include "base/observer_list.h" |
| 14 #include "base/scoped_observer.h" |
14 #include "chrome/browser/chromeos/arc/arc_session_manager.h" | 15 #include "chrome/browser/chromeos/arc/arc_session_manager.h" |
15 #include "components/arc/arc_service_manager.h" | 16 #include "components/arc/arc_service_manager.h" |
| 17 #include "content/public/browser/notification_details.h" |
| 18 #include "content/public/browser/notification_observer.h" |
| 19 #include "content/public/browser/notification_registrar.h" |
| 20 #include "content/public/browser/notification_source.h" |
| 21 #include "extensions/browser/extension_registry_observer.h" |
| 22 #include "extensions/common/extension.h" |
16 | 23 |
17 class Profile; | 24 class Profile; |
18 | 25 |
19 namespace base { | 26 namespace base { |
20 class FilePath; | 27 class FilePath; |
21 } // namespace base | 28 } // namespace base |
22 | 29 |
| 30 namespace content { |
| 31 class BrowserContext; |
| 32 } // namespace content |
| 33 |
23 namespace extensions { | 34 namespace extensions { |
24 class Extension; | 35 class ExtensionRegistry; |
25 namespace api { | 36 namespace api { |
26 namespace app_runtime { | 37 namespace app_runtime { |
27 struct ActionData; | 38 struct ActionData; |
28 } // namespace app_runtime | 39 } // namespace app_runtime |
29 } // namespace api | 40 } // namespace api |
30 } // namespace extensions | 41 } // namespace extensions |
31 | 42 |
32 namespace chromeos { | 43 namespace chromeos { |
33 | 44 |
34 // Information about an installed note-taking app. | 45 // Information about an installed note-taking app. |
35 struct NoteTakingAppInfo { | 46 struct NoteTakingAppInfo { |
36 // Application name to display to user. | 47 // Application name to display to user. |
37 std::string name; | 48 std::string name; |
38 | 49 |
39 // Either an extension ID (in the case of a Chrome app) or a package name (in | 50 // Either an extension ID (in the case of a Chrome app) or a package name (in |
40 // the case of an Android app). | 51 // the case of an Android app). |
41 std::string app_id; | 52 std::string app_id; |
42 | 53 |
43 // True if this is the preferred note-taking app. | 54 // True if this is the preferred note-taking app. |
44 bool preferred; | 55 bool preferred; |
45 }; | 56 }; |
46 | 57 |
47 using NoteTakingAppInfos = std::vector<NoteTakingAppInfo>; | 58 using NoteTakingAppInfos = std::vector<NoteTakingAppInfo>; |
48 | 59 |
49 // Singleton class used to launch a note-taking app. | 60 // Singleton class used to launch a note-taking app. |
50 class NoteTakingHelper : public arc::ArcServiceManager::Observer, | 61 class NoteTakingHelper : public arc::ArcServiceManager::Observer, |
51 public arc::ArcSessionManager::Observer { | 62 public arc::ArcSessionManager::Observer, |
| 63 public content::NotificationObserver, |
| 64 public extensions::ExtensionRegistryObserver { |
52 public: | 65 public: |
53 // Interface for observing changes to the list of available apps. | 66 // Interface for observing changes to the list of available apps. |
54 class Observer { | 67 class Observer { |
55 public: | 68 public: |
56 virtual ~Observer() = default; | 69 virtual ~Observer() = default; |
57 | 70 |
58 // Called when the list of available apps that will be returned by | 71 // Called when the list of available apps that will be returned by |
59 // GetAvailableApps() changes or when |android_enabled_| changes state. | 72 // GetAvailableApps() changes or when |android_enabled_| changes state. |
60 virtual void OnAvailableNoteTakingAppsUpdated() = 0; | 73 virtual void OnAvailableNoteTakingAppsUpdated() = 0; |
61 }; | 74 }; |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 void OnArcShutdown() override; | 124 void OnArcShutdown() override; |
112 void OnIntentFiltersUpdated() override; | 125 void OnIntentFiltersUpdated() override; |
113 | 126 |
114 // arc::ArcSessionManager::Observer: | 127 // arc::ArcSessionManager::Observer: |
115 void OnArcOptInChanged(bool enabled) override; | 128 void OnArcOptInChanged(bool enabled) override; |
116 | 129 |
117 private: | 130 private: |
118 NoteTakingHelper(); | 131 NoteTakingHelper(); |
119 ~NoteTakingHelper() override; | 132 ~NoteTakingHelper() override; |
120 | 133 |
| 134 // Returns true if |extension| is a whitelisted note-taking app and false |
| 135 // otherwise. |
| 136 bool IsWhitelistedChromeApp(const extensions::Extension* extension) const; |
| 137 |
| 138 // Queries and returns all installed and enabled whitelisted Chrome |
| 139 // note-taking apps for |profile|. |
| 140 std::vector<const extensions::Extension*> GetChromeApps( |
| 141 Profile* profile) const; |
| 142 |
121 // Requests a list of Android note-taking apps from ARC. | 143 // Requests a list of Android note-taking apps from ARC. |
122 void UpdateAndroidApps(); | 144 void UpdateAndroidApps(); |
123 | 145 |
124 // Handles ARC's response to an earlier UpdateAndroidApps() call. | 146 // Handles ARC's response to an earlier UpdateAndroidApps() call. |
125 void OnGotAndroidApps(std::vector<arc::mojom::IntentHandlerInfoPtr> handlers); | 147 void OnGotAndroidApps(std::vector<arc::mojom::IntentHandlerInfoPtr> handlers); |
126 | 148 |
127 // Helper method that launches |app_id| (either an Android package name or a | 149 // Helper method that launches |app_id| (either an Android package name or a |
128 // Chrome extension ID) to create a new note with an optional attached file at | 150 // Chrome extension ID) to create a new note with an optional attached file at |
129 // |path|. Returns false if the app couldn't be launched. | 151 // |path|. Returns false if the app couldn't be launched. |
130 bool LaunchAppInternal(Profile* profile, | 152 bool LaunchAppInternal(Profile* profile, |
131 const std::string& app_id, | 153 const std::string& app_id, |
132 const base::FilePath& path); | 154 const base::FilePath& path); |
133 | 155 |
| 156 // content::NotificationObserver: |
| 157 void Observe(int type, |
| 158 const content::NotificationSource& source, |
| 159 const content::NotificationDetails& details) override; |
| 160 |
| 161 // extensions::ExtensionRegistryObserver: |
| 162 void OnExtensionLoaded(content::BrowserContext* browser_context, |
| 163 const extensions::Extension* extension) override; |
| 164 void OnExtensionUnloaded( |
| 165 content::BrowserContext* browser_context, |
| 166 const extensions::Extension* extension, |
| 167 extensions::UnloadedExtensionInfo::Reason reason) override; |
| 168 void OnShutdown(extensions::ExtensionRegistry* registry) override; |
| 169 |
134 // True iff ARC is enabled (i.e. per the checkbox on the settings page). Note | 170 // True iff ARC is enabled (i.e. per the checkbox on the settings page). Note |
135 // that ARC may not be fully started yet when this is true, but it is expected | 171 // that ARC may not be fully started yet when this is true, but it is expected |
136 // to start eventually. Similarly, ARC may not be fully shut down yet when | 172 // to start eventually. Similarly, ARC may not be fully shut down yet when |
137 // this is false, but will be eventually. | 173 // this is false, but will be eventually. |
138 bool android_enabled_ = false; | 174 bool android_enabled_ = false; |
139 | 175 |
140 // This is set to true after |android_apps_| is updated. | 176 // This is set to true after |android_apps_| is updated. |
141 bool android_apps_received_ = false; | 177 bool android_apps_received_ = false; |
142 | 178 |
143 // Callback used to launch Chrome apps. Can be overridden for tests. | 179 // Callback used to launch Chrome apps. Can be overridden for tests. |
144 LaunchChromeAppCallback launch_chrome_app_callback_; | 180 LaunchChromeAppCallback launch_chrome_app_callback_; |
145 | 181 |
| 182 // Extension IDs of whitelisted (but not necessarily installed) Chrome |
| 183 // note-taking apps in the order in which they're chosen if the user hasn't |
| 184 // expressed a preference. |
| 185 std::vector<extensions::ExtensionId> whitelisted_chrome_app_ids_; |
| 186 |
146 // Cached information about available Android note-taking apps. | 187 // Cached information about available Android note-taking apps. |
147 NoteTakingAppInfos android_apps_; | 188 NoteTakingAppInfos android_apps_; |
148 | 189 |
| 190 // Tracks ExtensionRegistry observation for different profiles. |
| 191 ScopedObserver<extensions::ExtensionRegistry, |
| 192 extensions::ExtensionRegistryObserver> |
| 193 extension_registry_observer_; |
| 194 |
149 base::ObserverList<Observer> observers_; | 195 base::ObserverList<Observer> observers_; |
150 | 196 |
| 197 content::NotificationRegistrar registrar_; |
| 198 |
151 base::WeakPtrFactory<NoteTakingHelper> weak_ptr_factory_; | 199 base::WeakPtrFactory<NoteTakingHelper> weak_ptr_factory_; |
152 | 200 |
153 DISALLOW_COPY_AND_ASSIGN(NoteTakingHelper); | 201 DISALLOW_COPY_AND_ASSIGN(NoteTakingHelper); |
154 }; | 202 }; |
155 | 203 |
156 } // namespace chromeos | 204 } // namespace chromeos |
157 | 205 |
158 #endif // CHROME_BROWSER_CHROMEOS_NOTE_TAKING_HELPER_H_ | 206 #endif // CHROME_BROWSER_CHROMEOS_NOTE_TAKING_HELPER_H_ |
OLD | NEW |