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_
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"
21 namespace extensions
{
25 class SyncExtensionHelper
{
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
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 // Returns a unique extension name based in the integer |index|.
78 std::string
CreateFakeExtensionName(int index
);
80 // Converts a fake extension name back into the index used to generate it.
81 // Returns true if successful, false on failure.
82 bool ExtensionNameToIndex(const std::string
& name
, int* index
);
85 struct ExtensionState
{
86 enum EnabledState
{ DISABLED
, PENDING
, ENABLED
};
90 bool Equals(const ExtensionState
&other
) const;
92 EnabledState enabled_state
;
94 bool incognito_enabled
;
97 typedef std::map
<std::string
, ExtensionState
> ExtensionStateMap
;
98 typedef std::map
<std::string
, scoped_refptr
<extensions::Extension
> >
100 typedef std::map
<Profile
*, ExtensionNameMap
> ProfileExtensionNameMap
;
101 typedef std::map
<std::string
, std::string
> StringMap
;
102 typedef std::map
<std::string
, extensions::Manifest::Type
> TypeMap
;
104 friend struct DefaultSingletonTraits
<SyncExtensionHelper
>;
106 SyncExtensionHelper();
107 ~SyncExtensionHelper();
109 // Returns a map from |profile|'s installed extensions to their state.
110 static ExtensionStateMap
GetExtensionStates(Profile
* profile
);
112 // Initializes extensions for |profile| and creates an entry in
113 // |profile_extensions_| for it.
114 void SetupProfile(Profile
* profile
);
116 // Returns an extension for the given name in |profile|. type and
117 // index. Two extensions with the name but different profiles will
119 scoped_refptr
<extensions::Extension
> GetExtension(
120 Profile
* profile
, const std::string
& name
,
121 extensions::Manifest::Type type
) WARN_UNUSED_RESULT
;
123 std::string extension_name_prefix_
;
124 ProfileExtensionNameMap profile_extensions_
;
125 StringMap id_to_name_
;
127 bool setup_completed_
;
129 DISALLOW_COPY_AND_ASSIGN(SyncExtensionHelper
);
132 #endif // CHROME_BROWSER_SYNC_TEST_INTEGRATION_SYNC_EXTENSION_HELPER_H_