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