OLD | NEW |
| (Empty) |
1 // Copyright (c) 2011 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_SYNC_TEST_LIVE_SYNC_SYNC_EXTENSION_HELPER_H_ | |
6 #define CHROME_BROWSER_SYNC_TEST_LIVE_SYNC_SYNC_EXTENSION_HELPER_H_ | |
7 #pragma once | |
8 | |
9 #include <map> | |
10 #include <string> | |
11 #include <vector> | |
12 | |
13 #include "base/basictypes.h" | |
14 #include "base/compiler_specific.h" | |
15 #include "base/memory/ref_counted.h" | |
16 #include "base/memory/singleton.h" | |
17 #include "chrome/common/extensions/extension.h" | |
18 | |
19 class Extension; | |
20 class LiveSyncTest; | |
21 class Profile; | |
22 | |
23 class SyncExtensionHelper { | |
24 public: | |
25 // Singleton implementation. | |
26 static SyncExtensionHelper* GetInstance(); | |
27 | |
28 // Returns a generated extension ID for the given name. | |
29 static std::string NameToId(const std::string& name); | |
30 | |
31 // Initializes the profiles in |test| and registers them with | |
32 // internal data structures. | |
33 void SetupIfNecessary(LiveSyncTest* test); | |
34 | |
35 // Installs the extension with the given name to |profile|. | |
36 void InstallExtension( | |
37 Profile* profile, const std::string& name, Extension::Type type); | |
38 | |
39 // Uninstalls the extension with the given name from |profile|. | |
40 void UninstallExtension(Profile* profile, const std::string& name); | |
41 | |
42 // Returns a vector containing the names of all currently installed extensions | |
43 // on |profile|. | |
44 std::vector<std::string> GetInstalledExtensionNames(Profile* profile) const; | |
45 | |
46 // Enables the extension with the given name on |profile|. | |
47 void EnableExtension(Profile* profile, const std::string& name); | |
48 | |
49 // Disables the extension with the given name on |profile|. | |
50 void DisableExtension(Profile* profile, const std::string& name); | |
51 | |
52 // Returns true if the extension with the given name is enabled on |profile|. | |
53 bool IsExtensionEnabled(Profile* profile, const std::string& name) const; | |
54 | |
55 // Enables the extension with the given name to run in incognito mode | |
56 void IncognitoEnableExtension(Profile* profile, const std::string& name); | |
57 | |
58 // Disables the extension with the given name from running in incognito mode | |
59 void IncognitoDisableExtension(Profile* profile, const std::string& name); | |
60 | |
61 // Returns true iff the extension is enabled in incognito mode on |profile|. | |
62 bool IsIncognitoEnabled(Profile* profile, const std::string& name) const; | |
63 | |
64 // Returns true iff the extension with the given id is pending | |
65 // install in |profile|. | |
66 bool IsExtensionPendingInstallForSync( | |
67 Profile* profile, const std::string& id) const; | |
68 | |
69 // Installs all extensions pending sync in |profile| of the given | |
70 // type. | |
71 void InstallExtensionsPendingForSync(Profile* profile, Extension::Type type); | |
72 | |
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); | |
76 | |
77 private: | |
78 struct ExtensionState { | |
79 enum EnabledState { DISABLED, PENDING, ENABLED }; | |
80 | |
81 ExtensionState(); | |
82 ~ExtensionState(); | |
83 bool Equals(const ExtensionState &other) const; | |
84 | |
85 EnabledState enabled_state; | |
86 bool incognito_enabled; | |
87 }; | |
88 | |
89 typedef std::map<std::string, ExtensionState> ExtensionStateMap; | |
90 typedef std::map<std::string, scoped_refptr<Extension> > ExtensionNameMap; | |
91 typedef std::map<Profile*, ExtensionNameMap> ProfileExtensionNameMap; | |
92 typedef std::map<std::string, std::string> StringMap; | |
93 | |
94 friend struct DefaultSingletonTraits<SyncExtensionHelper>; | |
95 | |
96 SyncExtensionHelper(); | |
97 ~SyncExtensionHelper(); | |
98 | |
99 // Returns a map from |profile|'s installed extensions to their state. | |
100 static ExtensionStateMap GetExtensionStates(Profile* profile); | |
101 | |
102 // Initializes extensions for |profile| and creates an entry in | |
103 // |profile_extensions_| for it. | |
104 void SetupProfile(Profile* profile); | |
105 | |
106 // Returns an extension for the given name in |profile|. type and | |
107 // index. Two extensions with the name but different profiles will | |
108 // have the same id. | |
109 scoped_refptr<Extension> GetExtension( | |
110 Profile* profile, const std::string& name, | |
111 Extension::Type type) WARN_UNUSED_RESULT; | |
112 | |
113 ProfileExtensionNameMap profile_extensions_; | |
114 StringMap id_to_name_; | |
115 bool setup_completed_; | |
116 | |
117 DISALLOW_COPY_AND_ASSIGN(SyncExtensionHelper); | |
118 }; | |
119 | |
120 #endif // CHROME_BROWSER_SYNC_TEST_LIVE_SYNC_SYNC_EXTENSION_HELPER_H_ | |
OLD | NEW |