Switch global error menu icon to vectorized MD asset
[chromium-blink-merge.git] / chrome / browser / apps / drive / drive_app_provider.h
blob8b8738205649460b493bb0b8275a50616f504021
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.
5 #ifndef CHROME_BROWSER_APPS_DRIVE_DRIVE_APP_PROVIDER_H_
6 #define CHROME_BROWSER_APPS_DRIVE_DRIVE_APP_PROVIDER_H_
8 #include <set>
9 #include <string>
10 #include <vector>
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 "components/drive/drive_app_registry_observer.h"
17 #include "extensions/browser/extension_registry_observer.h"
19 namespace drive {
20 struct DriveAppInfo;
23 class BrowserContextKeyedServiceFactory;
24 class DriveAppConverter;
25 class DriveAppMapping;
26 class DriveAppUninstallSyncService;
27 class DriveServiceBridge;
28 class ExtensionService;
29 class Profile;
31 // DriveAppProvider is the integration point for Drive apps. It ensures each
32 // Drive app has a corresponding Chrome app in the extension system. If there
33 // is no matching Chrome app, a local URL app would be created. The class
34 // processes app changes from both DriveAppRegistry and extension system to
35 // keep the two in sync.
36 class DriveAppProvider : public drive::DriveAppRegistryObserver,
37 public extensions::ExtensionRegistryObserver {
38 public:
39 DriveAppProvider(Profile* profile,
40 DriveAppUninstallSyncService* uninstall_sync_service);
41 ~DriveAppProvider() override;
43 // Appends PKS factories this class depends on.
44 static void AppendDependsOnFactories(
45 std::set<BrowserContextKeyedServiceFactory*>* factories);
47 void SetDriveServiceBridgeForTest(scoped_ptr<DriveServiceBridge> test_bridge);
49 // Adds/removes uninstalled Drive app id from DriveAppUninstallSyncService.
50 // If a Drive app id is added as uninstalled Drive app, DriveAppProvider
51 // would not auto create the local URL app for it until the uninstall record
52 // is removed.
53 void AddUninstalledDriveAppFromSync(const std::string& drive_app_id);
54 void RemoveUninstalledDriveAppFromSync(const std::string& drive_app_id);
56 private:
57 friend class DriveAppProviderTest;
59 typedef std::set<std::string> IdSet;
60 typedef std::vector<drive::DriveAppInfo> DriveAppInfos;
62 // Maps |drive_app_id| to |new_app|'s id in mapping. Auto uninstall existing
63 // mapped app if it is an URL app.
64 void UpdateMappingAndExtensionSystem(const std::string& drive_app_id,
65 const extensions::Extension* new_app,
66 bool is_new_app_generated);
68 // Deferred processing of relevant extension installed message.
69 void ProcessDeferredOnExtensionInstalled(const std::string drive_app_id,
70 const std::string chrome_app_id);
72 void SchedulePendingConverters();
73 void OnLocalAppConverted(const DriveAppConverter* converter, bool success);
75 bool IsMappedUrlAppUpToDate(const drive::DriveAppInfo& drive_app) const;
77 void AddOrUpdateDriveApp(const drive::DriveAppInfo& drive_app);
78 void ProcessRemovedDriveApp(const std::string& drive_app_id);
80 void UpdateDriveApps();
82 // drive::DriveAppRegistryObserver overrides:
83 void OnDriveAppRegistryUpdated() override;
85 // extensions::ExtensionRegistryObserver overrides:
86 void OnExtensionInstalled(content::BrowserContext* browser_context,
87 const extensions::Extension* extension,
88 bool is_update) override;
89 void OnExtensionUninstalled(content::BrowserContext* browser_context,
90 const extensions::Extension* extension,
91 extensions::UninstallReason reason) override;
93 Profile* profile_;
94 DriveAppUninstallSyncService* uninstall_sync_service_;
96 scoped_ptr<DriveServiceBridge> service_bridge_;
97 scoped_ptr<DriveAppMapping> mapping_;
98 DriveAppInfos drive_apps_;
99 bool drive_app_registry_updated_;
101 // Tracks the pending web app convertions.
102 ScopedVector<DriveAppConverter> pending_converters_;
104 base::WeakPtrFactory<DriveAppProvider> weak_ptr_factory_;
106 DISALLOW_COPY_AND_ASSIGN(DriveAppProvider);
109 #endif // CHROME_BROWSER_APPS_DRIVE_DRIVE_APP_PROVIDER_H_