Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / chrome / browser / sync / test / integration / sync_extension_helper.h
blobc81977d25e48e2dbf683c7bdf63ec0f82c894713
1 // Copyright (c) 2012 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_SYNC_TEST_INTEGRATION_SYNC_EXTENSION_HELPER_H_
6 #define CHROME_BROWSER_SYNC_TEST_INTEGRATION_SYNC_EXTENSION_HELPER_H_
8 #include <map>
9 #include <string>
10 #include <vector>
12 #include "base/basictypes.h"
13 #include "base/compiler_specific.h"
14 #include "base/memory/ref_counted.h"
15 #include "base/memory/singleton.h"
16 #include "extensions/common/manifest.h"
18 class Profile;
19 class SyncTest;
21 namespace extensions {
22 class Extension;
25 class SyncExtensionHelper {
26 public:
27 // Singleton implementation.
28 static SyncExtensionHelper* GetInstance();
30 // Initializes the profiles in |test| and registers them with
31 // internal data structures.
32 void SetupIfNecessary(SyncTest* test);
34 // Installs the extension with the given name to |profile|, and returns the
35 // extension ID of the new extension.
36 std::string InstallExtension(Profile* profile,
37 const std::string& name,
38 extensions::Manifest::Type type);
40 // Uninstalls the extension with the given name from |profile|.
41 void UninstallExtension(Profile* profile, const std::string& name);
43 // Returns a vector containing the names of all currently installed extensions
44 // on |profile|.
45 std::vector<std::string> GetInstalledExtensionNames(Profile* profile) const;
47 // Enables the extension with the given name on |profile|.
48 void EnableExtension(Profile* profile, const std::string& name);
50 // Disables the extension with the given name on |profile|.
51 void DisableExtension(Profile* profile, const std::string& name);
53 // Returns true if the extension with the given name is enabled on |profile|.
54 bool IsExtensionEnabled(Profile* profile, const std::string& name) const;
56 // Enables the extension with the given name to run in incognito mode
57 void IncognitoEnableExtension(Profile* profile, const std::string& name);
59 // Disables the extension with the given name from running in incognito mode
60 void IncognitoDisableExtension(Profile* profile, const std::string& name);
62 // Returns true iff the extension is enabled in incognito mode on |profile|.
63 bool IsIncognitoEnabled(Profile* profile, const std::string& name) const;
65 // Returns true iff the extension with the given id is pending
66 // install in |profile|.
67 bool IsExtensionPendingInstallForSync(
68 Profile* profile, const std::string& id) const;
70 // Installs all extensions pending sync in |profile|.
71 void InstallExtensionsPendingForSync(Profile* profile);
73 // Returns true iff |profile1| and |profile2| have the same extensions and
74 // they are all in the same state.
75 static bool ExtensionStatesMatch(Profile* profile1, Profile* profile2);
77 private:
78 struct ExtensionState {
79 enum EnabledState { DISABLED, PENDING, ENABLED };
81 ExtensionState();
82 ~ExtensionState();
83 bool Equals(const ExtensionState &other) const;
85 EnabledState enabled_state;
86 int disable_reasons;
87 bool incognito_enabled;
90 typedef std::map<std::string, ExtensionState> ExtensionStateMap;
91 typedef std::map<std::string, scoped_refptr<extensions::Extension> >
92 ExtensionNameMap;
93 typedef std::map<Profile*, ExtensionNameMap> ProfileExtensionNameMap;
94 typedef std::map<std::string, std::string> StringMap;
95 typedef std::map<std::string, extensions::Manifest::Type> TypeMap;
97 friend struct DefaultSingletonTraits<SyncExtensionHelper>;
99 SyncExtensionHelper();
100 ~SyncExtensionHelper();
102 // Returns a map from |profile|'s installed extensions to their state.
103 static ExtensionStateMap GetExtensionStates(Profile* profile);
105 // Initializes extensions for |profile| and creates an entry in
106 // |profile_extensions_| for it.
107 void SetupProfile(Profile* profile);
109 // Returns an extension for the given name in |profile|. type and
110 // index. Two extensions with the name but different profiles will
111 // have the same id.
112 scoped_refptr<extensions::Extension> GetExtension(
113 Profile* profile, const std::string& name,
114 extensions::Manifest::Type type) WARN_UNUSED_RESULT;
116 ProfileExtensionNameMap profile_extensions_;
117 StringMap id_to_name_;
118 TypeMap id_to_type_;
119 bool setup_completed_;
121 DISALLOW_COPY_AND_ASSIGN(SyncExtensionHelper);
124 #endif // CHROME_BROWSER_SYNC_TEST_INTEGRATION_SYNC_EXTENSION_HELPER_H_