OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_SYNC_TEST_INTEGRATION_SYNC_EXTENSION_HELPER_H_ | 5 #ifndef CHROME_BROWSER_SYNC_TEST_INTEGRATION_SYNC_EXTENSION_HELPER_H_ |
6 #define CHROME_BROWSER_SYNC_TEST_INTEGRATION_SYNC_EXTENSION_HELPER_H_ | 6 #define CHROME_BROWSER_SYNC_TEST_INTEGRATION_SYNC_EXTENSION_HELPER_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <map> | 9 #include <map> |
10 #include <string> | 10 #include <string> |
11 #include <vector> | 11 #include <vector> |
12 | 12 |
13 #include "base/basictypes.h" | 13 #include "base/basictypes.h" |
14 #include "base/compiler_specific.h" | 14 #include "base/compiler_specific.h" |
15 #include "base/memory/ref_counted.h" | 15 #include "base/memory/ref_counted.h" |
16 #include "base/memory/singleton.h" | 16 #include "base/memory/singleton.h" |
17 #include "chrome/common/extensions/extension.h" | 17 #include "chrome/common/extensions/extension.h" |
18 | 18 |
19 class Profile; | 19 class Profile; |
20 class SyncTest; | 20 class SyncTest; |
21 | 21 |
| 22 namespace extensions { |
| 23 class Extension; |
| 24 } |
| 25 |
22 class SyncExtensionHelper { | 26 class SyncExtensionHelper { |
23 public: | 27 public: |
24 // Singleton implementation. | 28 // Singleton implementation. |
25 static SyncExtensionHelper* GetInstance(); | 29 static SyncExtensionHelper* GetInstance(); |
26 | 30 |
27 // Returns a generated extension ID for the given name. | 31 // Returns a generated extension ID for the given name. |
28 static std::string NameToId(const std::string& name); | 32 static std::string NameToId(const std::string& name); |
29 | 33 |
30 // Initializes the profiles in |test| and registers them with | 34 // Initializes the profiles in |test| and registers them with |
31 // internal data structures. | 35 // internal data structures. |
32 void SetupIfNecessary(SyncTest* test); | 36 void SetupIfNecessary(SyncTest* test); |
33 | 37 |
34 // Installs the extension with the given name to |profile|, and returns the | 38 // Installs the extension with the given name to |profile|, and returns the |
35 // extension ID of the new extension. | 39 // extension ID of the new extension. |
36 std::string InstallExtension( | 40 std::string InstallExtension(Profile* profile, |
37 Profile* profile, const std::string& name, Extension::Type type); | 41 const std::string& name, |
| 42 extensions::Extension::Type type); |
38 | 43 |
39 // Uninstalls the extension with the given name from |profile|. | 44 // Uninstalls the extension with the given name from |profile|. |
40 void UninstallExtension(Profile* profile, const std::string& name); | 45 void UninstallExtension(Profile* profile, const std::string& name); |
41 | 46 |
42 // Returns a vector containing the names of all currently installed extensions | 47 // Returns a vector containing the names of all currently installed extensions |
43 // on |profile|. | 48 // on |profile|. |
44 std::vector<std::string> GetInstalledExtensionNames(Profile* profile) const; | 49 std::vector<std::string> GetInstalledExtensionNames(Profile* profile) const; |
45 | 50 |
46 // Enables the extension with the given name on |profile|. | 51 // Enables the extension with the given name on |profile|. |
47 void EnableExtension(Profile* profile, const std::string& name); | 52 void EnableExtension(Profile* profile, const std::string& name); |
(...skipping 13 matching lines...) Expand all Loading... |
61 // Returns true iff the extension is enabled in incognito mode on |profile|. | 66 // Returns true iff the extension is enabled in incognito mode on |profile|. |
62 bool IsIncognitoEnabled(Profile* profile, const std::string& name) const; | 67 bool IsIncognitoEnabled(Profile* profile, const std::string& name) const; |
63 | 68 |
64 // Returns true iff the extension with the given id is pending | 69 // Returns true iff the extension with the given id is pending |
65 // install in |profile|. | 70 // install in |profile|. |
66 bool IsExtensionPendingInstallForSync( | 71 bool IsExtensionPendingInstallForSync( |
67 Profile* profile, const std::string& id) const; | 72 Profile* profile, const std::string& id) const; |
68 | 73 |
69 // Installs all extensions pending sync in |profile| of the given | 74 // Installs all extensions pending sync in |profile| of the given |
70 // type. | 75 // type. |
71 void InstallExtensionsPendingForSync(Profile* profile, Extension::Type type); | 76 void InstallExtensionsPendingForSync(Profile* profile, |
| 77 extensions::Extension::Type type); |
72 | 78 |
73 // Returns true iff |profile1| and |profile2| have the same extensions and | 79 // Returns true iff |profile1| and |profile2| have the same extensions and |
74 // they are all in the same state. | 80 // they are all in the same state. |
75 static bool ExtensionStatesMatch(Profile* profile1, Profile* profile2); | 81 static bool ExtensionStatesMatch(Profile* profile1, Profile* profile2); |
76 | 82 |
77 private: | 83 private: |
78 struct ExtensionState { | 84 struct ExtensionState { |
79 enum EnabledState { DISABLED, PENDING, ENABLED }; | 85 enum EnabledState { DISABLED, PENDING, ENABLED }; |
80 | 86 |
81 ExtensionState(); | 87 ExtensionState(); |
82 ~ExtensionState(); | 88 ~ExtensionState(); |
83 bool Equals(const ExtensionState &other) const; | 89 bool Equals(const ExtensionState &other) const; |
84 | 90 |
85 EnabledState enabled_state; | 91 EnabledState enabled_state; |
86 bool incognito_enabled; | 92 bool incognito_enabled; |
87 }; | 93 }; |
88 | 94 |
89 typedef std::map<std::string, ExtensionState> ExtensionStateMap; | 95 typedef std::map<std::string, ExtensionState> ExtensionStateMap; |
90 typedef std::map<std::string, scoped_refptr<Extension> > ExtensionNameMap; | 96 typedef std::map<std::string, scoped_refptr<extensions::Extension> > |
| 97 ExtensionNameMap; |
91 typedef std::map<Profile*, ExtensionNameMap> ProfileExtensionNameMap; | 98 typedef std::map<Profile*, ExtensionNameMap> ProfileExtensionNameMap; |
92 typedef std::map<std::string, std::string> StringMap; | 99 typedef std::map<std::string, std::string> StringMap; |
93 | 100 |
94 friend struct DefaultSingletonTraits<SyncExtensionHelper>; | 101 friend struct DefaultSingletonTraits<SyncExtensionHelper>; |
95 | 102 |
96 SyncExtensionHelper(); | 103 SyncExtensionHelper(); |
97 ~SyncExtensionHelper(); | 104 ~SyncExtensionHelper(); |
98 | 105 |
99 // Returns a map from |profile|'s installed extensions to their state. | 106 // Returns a map from |profile|'s installed extensions to their state. |
100 static ExtensionStateMap GetExtensionStates(Profile* profile); | 107 static ExtensionStateMap GetExtensionStates(Profile* profile); |
101 | 108 |
102 // Initializes extensions for |profile| and creates an entry in | 109 // Initializes extensions for |profile| and creates an entry in |
103 // |profile_extensions_| for it. | 110 // |profile_extensions_| for it. |
104 void SetupProfile(Profile* profile); | 111 void SetupProfile(Profile* profile); |
105 | 112 |
106 // Returns an extension for the given name in |profile|. type and | 113 // Returns an extension for the given name in |profile|. type and |
107 // index. Two extensions with the name but different profiles will | 114 // index. Two extensions with the name but different profiles will |
108 // have the same id. | 115 // have the same id. |
109 scoped_refptr<Extension> GetExtension( | 116 scoped_refptr<extensions::Extension> GetExtension( |
110 Profile* profile, const std::string& name, | 117 Profile* profile, const std::string& name, |
111 Extension::Type type) WARN_UNUSED_RESULT; | 118 extensions::Extension::Type type) WARN_UNUSED_RESULT; |
112 | 119 |
113 ProfileExtensionNameMap profile_extensions_; | 120 ProfileExtensionNameMap profile_extensions_; |
114 StringMap id_to_name_; | 121 StringMap id_to_name_; |
115 bool setup_completed_; | 122 bool setup_completed_; |
116 | 123 |
117 DISALLOW_COPY_AND_ASSIGN(SyncExtensionHelper); | 124 DISALLOW_COPY_AND_ASSIGN(SyncExtensionHelper); |
118 }; | 125 }; |
119 | 126 |
120 #endif // CHROME_BROWSER_SYNC_TEST_INTEGRATION_SYNC_EXTENSION_HELPER_H_ | 127 #endif // CHROME_BROWSER_SYNC_TEST_INTEGRATION_SYNC_EXTENSION_HELPER_H_ |
OLD | NEW |