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 CHROME_BROWSER_APPS_DRIVE_DRIVE_APP_PROVIDER_H_ |
| 6 #define CHROME_BROWSER_APPS_DRIVE_DRIVE_APP_PROVIDER_H_ |
| 7 |
| 8 #include <set> |
| 9 #include <string> |
| 10 #include <vector> |
| 11 |
| 12 #include "base/macros.h" |
| 13 #include "base/memory/scoped_ptr.h" |
| 14 #include "base/memory/scoped_vector.h" |
| 15 #include "base/memory/weak_ptr.h" |
| 16 #include "chrome/browser/drive/drive_app_registry_observer.h" |
| 17 #include "extensions/browser/extension_registry_observer.h" |
| 18 |
| 19 namespace drive { |
| 20 struct DriveAppInfo; |
| 21 } |
| 22 |
| 23 class BrowserContextKeyedServiceFactory; |
| 24 class DriveAppConverter; |
| 25 class DriveAppMapping; |
| 26 class DriveServiceBridge; |
| 27 class ExtensionService; |
| 28 class Profile; |
| 29 |
| 30 // DriveAppProvider is the integration point for Drive apps. It ensures each |
| 31 // Drive app has a corresponding Chrome app in the extension system. If there |
| 32 // is no matching Chrome app, a local URL app would be created. The class |
| 33 // processes app changes from both DriveAppRegistry and extension system to |
| 34 // keep the two in sync. |
| 35 class DriveAppProvider : public drive::DriveAppRegistryObserver, |
| 36 public extensions::ExtensionRegistryObserver { |
| 37 public: |
| 38 explicit DriveAppProvider(Profile* profile); |
| 39 virtual ~DriveAppProvider(); |
| 40 |
| 41 // Appends PKS factories this class depends on. |
| 42 static void AppendDependsOnFactories( |
| 43 std::set<BrowserContextKeyedServiceFactory*>* factories); |
| 44 |
| 45 void SetDriveServiceBridgeForTest(scoped_ptr<DriveServiceBridge> test_bridge); |
| 46 |
| 47 private: |
| 48 friend class DriveAppProviderTest; |
| 49 |
| 50 typedef std::set<std::string> IdSet; |
| 51 typedef std::vector<drive::DriveAppInfo> DriveAppInfos; |
| 52 |
| 53 // Maps |drive_app_id| to |new_app|'s id in mapping. Auto uninstall existing |
| 54 // mapped app if it is an URL app. |
| 55 void UpdateMappingAndExtensionSystem(const std::string& drive_app_id, |
| 56 const extensions::Extension* new_app, |
| 57 bool is_new_app_generated); |
| 58 |
| 59 // Deferred processing of relevant extension installed message. |
| 60 void ProcessDeferredOnExtensionInstalled(const std::string drive_app_id, |
| 61 const std::string chrome_app_id); |
| 62 |
| 63 void SchedulePendingConverters(); |
| 64 void OnLocalAppConverted(const DriveAppConverter* converter, bool success); |
| 65 |
| 66 bool IsMappedUrlAppUpToDate(const drive::DriveAppInfo& drive_app) const; |
| 67 |
| 68 void AddOrUpdateDriveApp(const drive::DriveAppInfo& drive_app); |
| 69 void ProcessRemovedDriveApp(const std::string& drive_app_id); |
| 70 |
| 71 // drive::DriveAppRegistryObserver overrides: |
| 72 virtual void OnDriveAppRegistryUpdated() OVERRIDE; |
| 73 |
| 74 // extensions::ExtensionRegistryObserver overrides: |
| 75 virtual void OnExtensionInstalled( |
| 76 content::BrowserContext* browser_context, |
| 77 const extensions::Extension* extension) OVERRIDE; |
| 78 virtual void OnExtensionUninstalled( |
| 79 content::BrowserContext* browser_context, |
| 80 const extensions::Extension* extension) OVERRIDE; |
| 81 |
| 82 Profile* profile_; |
| 83 |
| 84 scoped_ptr<DriveServiceBridge> service_bridge_; |
| 85 scoped_ptr<DriveAppMapping> mapping_; |
| 86 DriveAppInfos drive_apps_; |
| 87 |
| 88 // Tracks the pending web app convertions. |
| 89 ScopedVector<DriveAppConverter> pending_converters_; |
| 90 |
| 91 base::WeakPtrFactory<DriveAppProvider> weak_ptr_factory_; |
| 92 |
| 93 DISALLOW_COPY_AND_ASSIGN(DriveAppProvider); |
| 94 }; |
| 95 |
| 96 #endif // CHROME_BROWSER_APPS_DRIVE_DRIVE_APP_PROVIDER_H_ |
OLD | NEW |