| 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 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
| 13 #include "base/compiler_specific.h" | 13 #include "base/compiler_specific.h" |
| 14 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
| 15 #include "base/memory/singleton.h" | 15 #include "base/memory/singleton.h" |
| 16 #include "chrome/common/extensions/extension.h" | 16 #include "chrome/common/extensions/manifest.h" |
| 17 | 17 |
| 18 class Profile; | 18 class Profile; |
| 19 class SyncTest; | 19 class SyncTest; |
| 20 | 20 |
| 21 namespace extensions { | 21 namespace extensions { |
| 22 class Extension; | 22 class Extension; |
| 23 } | 23 } |
| 24 | 24 |
| 25 class SyncExtensionHelper { | 25 class SyncExtensionHelper { |
| 26 public: | 26 public: |
| 27 // Singleton implementation. | 27 // Singleton implementation. |
| 28 static SyncExtensionHelper* GetInstance(); | 28 static SyncExtensionHelper* GetInstance(); |
| 29 | 29 |
| 30 // Returns a generated extension ID for the given name. | 30 // Returns a generated extension ID for the given name. |
| 31 static std::string NameToId(const std::string& name); | 31 static std::string NameToId(const std::string& name); |
| 32 | 32 |
| 33 // Initializes the profiles in |test| and registers them with | 33 // Initializes the profiles in |test| and registers them with |
| 34 // internal data structures. | 34 // internal data structures. |
| 35 void SetupIfNecessary(SyncTest* test); | 35 void SetupIfNecessary(SyncTest* test); |
| 36 | 36 |
| 37 // Installs the extension with the given name to |profile|, and returns the | 37 // Installs the extension with the given name to |profile|, and returns the |
| 38 // extension ID of the new extension. | 38 // extension ID of the new extension. |
| 39 std::string InstallExtension(Profile* profile, | 39 std::string InstallExtension(Profile* profile, |
| 40 const std::string& name, | 40 const std::string& name, |
| 41 extensions::Extension::Type type); | 41 extensions::Manifest::Type type); |
| 42 | 42 |
| 43 // Uninstalls the extension with the given name from |profile|. | 43 // Uninstalls the extension with the given name from |profile|. |
| 44 void UninstallExtension(Profile* profile, const std::string& name); | 44 void UninstallExtension(Profile* profile, const std::string& name); |
| 45 | 45 |
| 46 // Returns a vector containing the names of all currently installed extensions | 46 // Returns a vector containing the names of all currently installed extensions |
| 47 // on |profile|. | 47 // on |profile|. |
| 48 std::vector<std::string> GetInstalledExtensionNames(Profile* profile) const; | 48 std::vector<std::string> GetInstalledExtensionNames(Profile* profile) const; |
| 49 | 49 |
| 50 // Enables the extension with the given name on |profile|. | 50 // Enables the extension with the given name on |profile|. |
| 51 void EnableExtension(Profile* profile, const std::string& name); | 51 void EnableExtension(Profile* profile, const std::string& name); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 | 88 |
| 89 EnabledState enabled_state; | 89 EnabledState enabled_state; |
| 90 bool incognito_enabled; | 90 bool incognito_enabled; |
| 91 }; | 91 }; |
| 92 | 92 |
| 93 typedef std::map<std::string, ExtensionState> ExtensionStateMap; | 93 typedef std::map<std::string, ExtensionState> ExtensionStateMap; |
| 94 typedef std::map<std::string, scoped_refptr<extensions::Extension> > | 94 typedef std::map<std::string, scoped_refptr<extensions::Extension> > |
| 95 ExtensionNameMap; | 95 ExtensionNameMap; |
| 96 typedef std::map<Profile*, ExtensionNameMap> ProfileExtensionNameMap; | 96 typedef std::map<Profile*, ExtensionNameMap> ProfileExtensionNameMap; |
| 97 typedef std::map<std::string, std::string> StringMap; | 97 typedef std::map<std::string, std::string> StringMap; |
| 98 typedef std::map<std::string, extensions::Extension::Type> TypeMap; | 98 typedef std::map<std::string, extensions::Manifest::Type> TypeMap; |
| 99 | 99 |
| 100 friend struct DefaultSingletonTraits<SyncExtensionHelper>; | 100 friend struct DefaultSingletonTraits<SyncExtensionHelper>; |
| 101 | 101 |
| 102 SyncExtensionHelper(); | 102 SyncExtensionHelper(); |
| 103 ~SyncExtensionHelper(); | 103 ~SyncExtensionHelper(); |
| 104 | 104 |
| 105 // Returns a map from |profile|'s installed extensions to their state. | 105 // Returns a map from |profile|'s installed extensions to their state. |
| 106 static ExtensionStateMap GetExtensionStates(Profile* profile); | 106 static ExtensionStateMap GetExtensionStates(Profile* profile); |
| 107 | 107 |
| 108 // Initializes extensions for |profile| and creates an entry in | 108 // Initializes extensions for |profile| and creates an entry in |
| 109 // |profile_extensions_| for it. | 109 // |profile_extensions_| for it. |
| 110 void SetupProfile(Profile* profile); | 110 void SetupProfile(Profile* profile); |
| 111 | 111 |
| 112 // Returns an extension for the given name in |profile|. type and | 112 // Returns an extension for the given name in |profile|. type and |
| 113 // index. Two extensions with the name but different profiles will | 113 // index. Two extensions with the name but different profiles will |
| 114 // have the same id. | 114 // have the same id. |
| 115 scoped_refptr<extensions::Extension> GetExtension( | 115 scoped_refptr<extensions::Extension> GetExtension( |
| 116 Profile* profile, const std::string& name, | 116 Profile* profile, const std::string& name, |
| 117 extensions::Extension::Type type) WARN_UNUSED_RESULT; | 117 extensions::Manifest::Type type) WARN_UNUSED_RESULT; |
| 118 | 118 |
| 119 ProfileExtensionNameMap profile_extensions_; | 119 ProfileExtensionNameMap profile_extensions_; |
| 120 StringMap id_to_name_; | 120 StringMap id_to_name_; |
| 121 TypeMap id_to_type_; | 121 TypeMap id_to_type_; |
| 122 bool setup_completed_; | 122 bool setup_completed_; |
| 123 | 123 |
| 124 DISALLOW_COPY_AND_ASSIGN(SyncExtensionHelper); | 124 DISALLOW_COPY_AND_ASSIGN(SyncExtensionHelper); |
| 125 }; | 125 }; |
| 126 | 126 |
| 127 #endif // CHROME_BROWSER_SYNC_TEST_INTEGRATION_SYNC_EXTENSION_HELPER_H_ | 127 #endif // CHROME_BROWSER_SYNC_TEST_INTEGRATION_SYNC_EXTENSION_HELPER_H_ |
| OLD | NEW |