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_EXTENSIONS_PENDING_EXTENSION_INFO_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_PENDING_EXTENSION_INFO_H_ |
6 #define CHROME_BROWSER_EXTENSIONS_PENDING_EXTENSION_INFO_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_PENDING_EXTENSION_INFO_H_ |
7 | 7 |
8 #include "base/version.h" | 8 #include "base/version.h" |
9 #include "chrome/common/extensions/extension.h" | 9 #include "chrome/common/extensions/extension.h" |
10 #include "googleurl/src/gurl.h" | 10 #include "googleurl/src/gurl.h" |
11 | 11 |
| 12 FORWARD_DECLARE_TEST(ExtensionServiceTest, AddPendingExtensionFromSync); |
| 13 |
| 14 namespace extensions { |
| 15 |
12 // A pending extension is an extension that hasn't been installed yet | 16 // A pending extension is an extension that hasn't been installed yet |
13 // and is intended to be installed in the next auto-update cycle. The | 17 // and is intended to be installed in the next auto-update cycle. The |
14 // update URL of a pending extension may be blank, in which case a | 18 // update URL of a pending extension may be blank, in which case a |
15 // default one is assumed. | 19 // default one is assumed. |
16 // TODO(skerner): Make this class an implementation detail of | 20 // TODO(skerner): Make this class an implementation detail of |
17 // PendingExtensionManager, and remove all other users. | 21 // PendingExtensionManager, and remove all other users. |
18 class PendingExtensionInfo { | 22 class PendingExtensionInfo { |
19 public: | 23 public: |
20 typedef bool (*ShouldAllowInstallPredicate)(const extensions::Extension&); | 24 typedef bool (*ShouldAllowInstallPredicate)(const Extension&); |
21 | 25 |
22 PendingExtensionInfo( | 26 PendingExtensionInfo( |
23 const std::string& id, | 27 const std::string& id, |
24 const GURL& update_url, | 28 const GURL& update_url, |
25 const Version& version, | 29 const Version& version, |
26 ShouldAllowInstallPredicate should_allow_install, | 30 ShouldAllowInstallPredicate should_allow_install, |
27 bool is_from_sync, | 31 bool is_from_sync, |
28 bool install_silently, | 32 bool install_silently, |
29 extensions::Extension::Location install_source); | 33 Extension::Location install_source); |
30 | 34 |
31 // Required for STL container membership. Should not be used directly. | 35 // Required for STL container membership. Should not be used directly. |
32 PendingExtensionInfo(); | 36 PendingExtensionInfo(); |
33 | 37 |
34 // Consider two PendingExtensionInfos equal if their ids are equal. | 38 // Consider two PendingExtensionInfos equal if their ids are equal. |
35 bool operator==(const PendingExtensionInfo& rhs) const; | 39 bool operator==(const PendingExtensionInfo& rhs) const; |
36 | 40 |
37 const std::string& id() const { return id_; } | 41 const std::string& id() const { return id_; } |
38 const GURL& update_url() const { return update_url_; } | 42 const GURL& update_url() const { return update_url_; } |
39 const Version& version() const { return version_; } | 43 const Version& version() const { return version_; } |
40 | 44 |
41 // ShouldAllowInstall() returns the result of running constructor argument | 45 // ShouldAllowInstall() returns the result of running constructor argument |
42 // |should_allow_install| on an extension. After an extension is unpacked, | 46 // |should_allow_install| on an extension. After an extension is unpacked, |
43 // this function is run. If it returns true, the extension is installed. | 47 // this function is run. If it returns true, the extension is installed. |
44 // If not, the extension is discarded. This allows creators of | 48 // If not, the extension is discarded. This allows creators of |
45 // PendingExtensionInfo objects to ensure that extensions meet some criteria | 49 // PendingExtensionInfo objects to ensure that extensions meet some criteria |
46 // that can only be tested once the extension is unpacked. | 50 // that can only be tested once the extension is unpacked. |
47 bool ShouldAllowInstall(const extensions::Extension& extension) const { | 51 bool ShouldAllowInstall(const Extension& extension) const { |
48 return should_allow_install_(extension); | 52 return should_allow_install_(extension); |
49 } | 53 } |
50 bool is_from_sync() const { return is_from_sync_; } | 54 bool is_from_sync() const { return is_from_sync_; } |
51 bool install_silently() const { return install_silently_; } | 55 bool install_silently() const { return install_silently_; } |
52 extensions::Extension::Location install_source() const { | 56 Extension::Location install_source() const { return install_source_; } |
53 return install_source_; | |
54 } | |
55 | 57 |
56 private: | 58 private: |
57 std::string id_; | 59 std::string id_; |
58 | 60 |
59 GURL update_url_; | 61 GURL update_url_; |
60 Version version_; | 62 Version version_; |
61 | 63 |
62 // When the extension is about to be installed, this function is | 64 // When the extension is about to be installed, this function is |
63 // called. If this function returns true, the install proceeds. If | 65 // called. If this function returns true, the install proceeds. If |
64 // this function returns false, the install is aborted. | 66 // this function returns false, the install is aborted. |
65 ShouldAllowInstallPredicate should_allow_install_; | 67 ShouldAllowInstallPredicate should_allow_install_; |
66 | 68 |
67 bool is_from_sync_; // This update check was initiated from sync. | 69 bool is_from_sync_; // This update check was initiated from sync. |
68 bool install_silently_; | 70 bool install_silently_; |
69 extensions::Extension::Location install_source_; | 71 Extension::Location install_source_; |
70 | 72 |
71 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest, AddPendingExtensionFromSync); | 73 FRIEND_TEST_ALL_PREFIXES(::ExtensionServiceTest, AddPendingExtensionFromSync); |
72 }; | 74 }; |
73 | 75 |
| 76 } // namespace extensions |
| 77 |
74 #endif // CHROME_BROWSER_EXTENSIONS_PENDING_EXTENSION_INFO_H_ | 78 #endif // CHROME_BROWSER_EXTENSIONS_PENDING_EXTENSION_INFO_H_ |
OLD | NEW |