OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 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_TEST_LIVE_SYNC_LIVE_SYNC_EXTENSION_HELPER_H_ | 5 #ifndef CHROME_TEST_LIVE_SYNC_LIVE_SYNC_EXTENSION_HELPER_H_ |
6 #define CHROME_TEST_LIVE_SYNC_LIVE_SYNC_EXTENSION_HELPER_H_ | 6 #define CHROME_TEST_LIVE_SYNC_LIVE_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 | 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 "chrome/common/extensions/extension.h" | 15 #include "chrome/common/extensions/extension.h" |
16 | 16 |
17 class Extension; | 17 class Extension; |
18 class LiveSyncTest; | 18 class LiveSyncTest; |
19 class Profile; | 19 class Profile; |
20 | 20 |
21 class LiveSyncExtensionHelper { | 21 class LiveSyncExtensionHelper { |
22 public: | 22 public: |
23 enum ExtensionState { DISABLED, PENDING, ENABLED }; | |
24 | |
25 typedef std::map<std::string, ExtensionState> ExtensionStateMap; | |
26 | |
27 LiveSyncExtensionHelper(); | 23 LiveSyncExtensionHelper(); |
28 ~LiveSyncExtensionHelper(); | 24 ~LiveSyncExtensionHelper(); |
29 | 25 |
30 // Returns a generated extension ID for the given name. | 26 // Returns a generated extension ID for the given name. |
31 static std::string NameToId(const std::string& name); | 27 static std::string NameToId(const std::string& name); |
32 | 28 |
33 // Initializes the profiles in |test| and registers them with | 29 // Initializes the profiles in |test| and registers them with |
34 // internal data structures. | 30 // internal data structures. |
35 void Setup(LiveSyncTest* test); | 31 void Setup(LiveSyncTest* test); |
36 | 32 |
37 // Installs the extension with the given name to |profile|. | 33 // Installs the extension with the given name to |profile|. |
38 void InstallExtension( | 34 void InstallExtension( |
39 Profile* profile, const std::string& name, Extension::Type type); | 35 Profile* profile, const std::string& name, Extension::Type type); |
40 | 36 |
41 // Uninstalls the extension with the given name from |profile|. | 37 // Uninstalls the extension with the given name from |profile|. |
42 void UninstallExtension(Profile* profile, const std::string& name); | 38 void UninstallExtension(Profile* profile, const std::string& name); |
43 | 39 |
40 // Enables the extension with the given name on |profile|. | |
41 void EnableExtension(Profile* profile, const std::string& name); | |
42 | |
43 // Disables the extension with the given name on |profile|. | |
44 void DisableExtension(Profile* profile, const std::string& name); | |
45 | |
46 // Enables the extension with the given name to run in incognito mode | |
47 void IncognitoEnableExtension(Profile* profile, const std::string& name); | |
48 | |
49 // Disables the extension with the given name from running in incognito mode | |
50 void IncognitoDisableExtension(Profile* profile, const std::string& name); | |
51 | |
44 // Returns true iff the extension with the given id is pending | 52 // Returns true iff the extension with the given id is pending |
45 // install in |profile|. | 53 // install in |profile|. |
46 bool IsExtensionPendingInstallForSync( | 54 bool IsExtensionPendingInstallForSync( |
47 Profile* profile, const std::string& id) const; | 55 Profile* profile, const std::string& id) const; |
48 | 56 |
49 // Installs all extensions pending sync in |profile| of the given | 57 // Installs all extensions pending sync in |profile| of the given |
50 // type. | 58 // type. |
51 void InstallExtensionsPendingForSync(Profile* profile, Extension::Type type); | 59 void InstallExtensionsPendingForSync(Profile* profile, Extension::Type type); |
52 | 60 |
53 // Returns a map from |profile|'s installed extensions to their | 61 // Returns true iff |profile1| and |profile2| have the same extensions and |
54 // state. | 62 // they are all in the same state. |
55 ExtensionStateMap GetExtensionStates(Profile* profile) const; | 63 bool ExtensionStatesMatch(Profile* profile1, Profile* profile2) const; |
akalin
2011/06/10 01:56:44
I think this can be static
braffert
2011/06/10 16:49:17
Done. This required making the function non-const
| |
56 | 64 |
57 private: | 65 private: |
66 struct ExtensionState { | |
67 ExtensionState(); | |
68 ~ExtensionState(); | |
69 enum EnabledState { DISABLED, PENDING, ENABLED }; | |
akalin
2011/06/10 01:56:44
Put types first, then blank line, then functions,
braffert
2011/06/10 16:49:17
Done.
| |
70 bool Equals(const ExtensionState &other) const; | |
71 EnabledState enabled_state; | |
72 bool incognito_enabled; | |
73 }; | |
74 typedef std::map<std::string, ExtensionState> ExtensionStateMap; | |
58 typedef std::map<std::string, scoped_refptr<Extension> > ExtensionNameMap; | 75 typedef std::map<std::string, scoped_refptr<Extension> > ExtensionNameMap; |
59 typedef std::map<Profile*, ExtensionNameMap> ProfileExtensionNameMap; | 76 typedef std::map<Profile*, ExtensionNameMap> ProfileExtensionNameMap; |
60 typedef std::map<std::string, std::string> StringMap; | 77 typedef std::map<std::string, std::string> StringMap; |
61 | 78 |
79 // Returns a map from |profile|'s installed extensions to their state. | |
80 ExtensionStateMap GetExtensionStates(Profile* profile) const; | |
akalin
2011/06/10 01:56:44
I think this can be static
braffert
2011/06/10 16:49:17
Done.
| |
81 | |
62 // Initializes extensions for |profile| and creates an entry in | 82 // Initializes extensions for |profile| and creates an entry in |
63 // |profile_extensions_| for it. | 83 // |profile_extensions_| for it. |
64 void SetupProfile(Profile* profile); | 84 void SetupProfile(Profile* profile); |
65 | 85 |
66 // Returns an extension for the given name in |profile|. type and | 86 // Returns an extension for the given name in |profile|. type and |
67 // index. Two extensions with the name but different profiles will | 87 // index. Two extensions with the name but different profiles will |
68 // have the same id. | 88 // have the same id. |
69 scoped_refptr<Extension> GetExtension( | 89 scoped_refptr<Extension> GetExtension( |
70 Profile* profile, const std::string& name, | 90 Profile* profile, const std::string& name, |
71 Extension::Type type) WARN_UNUSED_RESULT; | 91 Extension::Type type) WARN_UNUSED_RESULT; |
72 | 92 |
73 ProfileExtensionNameMap profile_extensions_; | 93 ProfileExtensionNameMap profile_extensions_; |
74 StringMap id_to_name_; | 94 StringMap id_to_name_; |
75 | 95 |
76 DISALLOW_COPY_AND_ASSIGN(LiveSyncExtensionHelper); | 96 DISALLOW_COPY_AND_ASSIGN(LiveSyncExtensionHelper); |
77 }; | 97 }; |
78 | 98 |
79 #endif // CHROME_TEST_LIVE_SYNC_LIVE_SYNC_EXTENSION_HELPER_H_ | 99 #endif // CHROME_TEST_LIVE_SYNC_LIVE_SYNC_EXTENSION_HELPER_H_ |
OLD | NEW |