[email protected] | f3d3b38 | 2014-03-14 21:19:28 | [diff] [blame] | 1 | // Copyright 2014 The Chromium Authors. All rights reserved. |
[email protected] | 483d1ff | 2011-03-03 17:12:02 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
[email protected] | f3d3b38 | 2014-03-14 21:19:28 | [diff] [blame] | 5 | #ifndef CHROME_BROWSER_EXTENSIONS_PENDING_EXTENSION_INFO_H_ |
| 6 | #define CHROME_BROWSER_EXTENSIONS_PENDING_EXTENSION_INFO_H_ |
[email protected] | 483d1ff | 2011-03-03 17:12:02 | [diff] [blame] | 7 | |
[email protected] | 4ec0f4b | 2012-12-07 09:41:46 | [diff] [blame] | 8 | #include <string> |
| 9 | |
[email protected] | b52f8ca | 2013-11-28 08:25:22 | [diff] [blame] | 10 | #include "base/gtest_prod_util.h" |
[email protected] | e398785 | 2012-05-04 10:06:30 | [diff] [blame] | 11 | #include "base/version.h" |
[email protected] | d42c1115 | 2013-08-22 19:36:32 | [diff] [blame] | 12 | #include "extensions/common/manifest.h" |
[email protected] | a6483d2 | 2013-07-03 22:11:00 | [diff] [blame] | 13 | #include "url/gurl.h" |
[email protected] | 483d1ff | 2011-03-03 17:12:02 | [diff] [blame] | 14 | |
Devlin Cronin | eea1b7a | 2018-05-26 02:46:21 | [diff] [blame] | 15 | namespace extensions { |
[email protected] | 3f213ad | 2012-07-26 23:39:41 | [diff] [blame] | 16 | FORWARD_DECLARE_TEST(ExtensionServiceTest, AddPendingExtensionFromSync); |
| 17 | |
[email protected] | b52f8ca | 2013-11-28 08:25:22 | [diff] [blame] | 18 | class Extension; |
[email protected] | 3f213ad | 2012-07-26 23:39:41 | [diff] [blame] | 19 | |
[email protected] | 483d1ff | 2011-03-03 17:12:02 | [diff] [blame] | 20 | // A pending extension is an extension that hasn't been installed yet |
| 21 | // and is intended to be installed in the next auto-update cycle. The |
| 22 | // update URL of a pending extension may be blank, in which case a |
| 23 | // default one is assumed. |
[email protected] | b2907fd | 2011-03-25 16:43:37 | [diff] [blame] | 24 | // TODO(skerner): Make this class an implementation detail of |
| 25 | // PendingExtensionManager, and remove all other users. |
[email protected] | 483d1ff | 2011-03-03 17:12:02 | [diff] [blame] | 26 | class PendingExtensionInfo { |
| 27 | public: |
[email protected] | 8f3bcbd | 2013-06-05 08:42:40 | [diff] [blame] | 28 | typedef bool (*ShouldAllowInstallPredicate)(const Extension*); |
[email protected] | 483d1ff | 2011-03-03 17:12:02 | [diff] [blame] | 29 | |
[email protected] | d8fd0fd | 2014-03-24 13:16:06 | [diff] [blame] | 30 | PendingExtensionInfo(const std::string& id, |
| 31 | const std::string& install_parameter, |
| 32 | const GURL& update_url, |
pwnall | cbd7319 | 2016-08-22 18:59:17 | [diff] [blame] | 33 | const base::Version& version, |
[email protected] | d8fd0fd | 2014-03-24 13:16:06 | [diff] [blame] | 34 | ShouldAllowInstallPredicate should_allow_install, |
| 35 | bool is_from_sync, |
[email protected] | d8fd0fd | 2014-03-24 13:16:06 | [diff] [blame] | 36 | Manifest::Location install_source, |
mamir | 0128d5a | 2016-07-15 20:55:48 | [diff] [blame] | 37 | int creation_flags, |
[email protected] | 21db9ef | 2014-05-16 02:06:27 | [diff] [blame] | 38 | bool mark_acknowledged, |
| 39 | bool remote_install); |
[email protected] | 483d1ff | 2011-03-03 17:12:02 | [diff] [blame] | 40 | |
[email protected] | b2907fd | 2011-03-25 16:43:37 | [diff] [blame] | 41 | // Required for STL container membership. Should not be used directly. |
[email protected] | 483d1ff | 2011-03-03 17:12:02 | [diff] [blame] | 42 | PendingExtensionInfo(); |
| 43 | |
vmpstr | b8aacbe | 2016-02-26 02:00:48 | [diff] [blame] | 44 | PendingExtensionInfo(const PendingExtensionInfo& other); |
| 45 | |
[email protected] | d8fd0fd | 2014-03-24 13:16:06 | [diff] [blame] | 46 | ~PendingExtensionInfo(); |
| 47 | |
[email protected] | 51a3bf8b | 2012-06-08 22:53:06 | [diff] [blame] | 48 | // Consider two PendingExtensionInfos equal if their ids are equal. |
| 49 | bool operator==(const PendingExtensionInfo& rhs) const; |
| 50 | |
| 51 | const std::string& id() const { return id_; } |
[email protected] | 483d1ff | 2011-03-03 17:12:02 | [diff] [blame] | 52 | const GURL& update_url() const { return update_url_; } |
pwnall | cbd7319 | 2016-08-22 18:59:17 | [diff] [blame] | 53 | const base::Version& version() const { return version_; } |
[email protected] | d8fd0fd | 2014-03-24 13:16:06 | [diff] [blame] | 54 | const std::string& install_parameter() const { return install_parameter_; } |
[email protected] | 483d1ff | 2011-03-03 17:12:02 | [diff] [blame] | 55 | |
| 56 | // ShouldAllowInstall() returns the result of running constructor argument |
| 57 | // |should_allow_install| on an extension. After an extension is unpacked, |
| 58 | // this function is run. If it returns true, the extension is installed. |
| 59 | // If not, the extension is discarded. This allows creators of |
| 60 | // PendingExtensionInfo objects to ensure that extensions meet some criteria |
| 61 | // that can only be tested once the extension is unpacked. |
[email protected] | 8f3bcbd | 2013-06-05 08:42:40 | [diff] [blame] | 62 | bool ShouldAllowInstall(const Extension* extension) const { |
[email protected] | 483d1ff | 2011-03-03 17:12:02 | [diff] [blame] | 63 | return should_allow_install_(extension); |
| 64 | } |
| 65 | bool is_from_sync() const { return is_from_sync_; } |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 66 | Manifest::Location install_source() const { return install_source_; } |
mamir | 0128d5a | 2016-07-15 20:55:48 | [diff] [blame] | 67 | int creation_flags() const { return creation_flags_; } |
[email protected] | 464213a | 2013-10-15 01:06:48 | [diff] [blame] | 68 | bool mark_acknowledged() const { return mark_acknowledged_; } |
[email protected] | 21db9ef | 2014-05-16 02:06:27 | [diff] [blame] | 69 | bool remote_install() const { return remote_install_; } |
[email protected] | 483d1ff | 2011-03-03 17:12:02 | [diff] [blame] | 70 | |
[email protected] | 4ec0f4b | 2012-12-07 09:41:46 | [diff] [blame] | 71 | // Returns -1, 0 or 1 if |this| has lower, equal or higher precedence than |
| 72 | // |other|, respectively. "Equal" precedence means that the version and the |
| 73 | // install source match. "Higher" precedence means that the version is newer, |
| 74 | // or the version matches but the install source has higher priority. |
| 75 | // It is only valid to invoke this when the ids match. |
| 76 | int CompareTo(const PendingExtensionInfo& other) const; |
| 77 | |
[email protected] | 483d1ff | 2011-03-03 17:12:02 | [diff] [blame] | 78 | private: |
[email protected] | 51a3bf8b | 2012-06-08 22:53:06 | [diff] [blame] | 79 | std::string id_; |
| 80 | |
[email protected] | 483d1ff | 2011-03-03 17:12:02 | [diff] [blame] | 81 | GURL update_url_; |
pwnall | cbd7319 | 2016-08-22 18:59:17 | [diff] [blame] | 82 | base::Version version_; |
[email protected] | d8fd0fd | 2014-03-24 13:16:06 | [diff] [blame] | 83 | std::string install_parameter_; |
[email protected] | 483d1ff | 2011-03-03 17:12:02 | [diff] [blame] | 84 | |
| 85 | // When the extension is about to be installed, this function is |
| 86 | // called. If this function returns true, the install proceeds. If |
| 87 | // this function returns false, the install is aborted. |
| 88 | ShouldAllowInstallPredicate should_allow_install_; |
| 89 | |
| 90 | bool is_from_sync_; // This update check was initiated from sync. |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 91 | Manifest::Location install_source_; |
mamir | 0128d5a | 2016-07-15 20:55:48 | [diff] [blame] | 92 | int creation_flags_; |
[email protected] | 464213a | 2013-10-15 01:06:48 | [diff] [blame] | 93 | bool mark_acknowledged_; |
[email protected] | 21db9ef | 2014-05-16 02:06:27 | [diff] [blame] | 94 | bool remote_install_; |
[email protected] | 483d1ff | 2011-03-03 17:12:02 | [diff] [blame] | 95 | |
Devlin Cronin | eea1b7a | 2018-05-26 02:46:21 | [diff] [blame] | 96 | FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest, AddPendingExtensionFromSync); |
[email protected] | 483d1ff | 2011-03-03 17:12:02 | [diff] [blame] | 97 | }; |
| 98 | |
[email protected] | 3f213ad | 2012-07-26 23:39:41 | [diff] [blame] | 99 | } // namespace extensions |
| 100 | |
[email protected] | f3d3b38 | 2014-03-14 21:19:28 | [diff] [blame] | 101 | #endif // CHROME_BROWSER_EXTENSIONS_PENDING_EXTENSION_INFO_H_ |