blob: e66b2079707ecf4da982bdff038c758b15f2c400 [file] [log] [blame]
[email protected]f3d3b382014-03-14 21:19:281// Copyright 2014 The Chromium Authors. All rights reserved.
[email protected]483d1ff2011-03-03 17:12:022// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]f3d3b382014-03-14 21:19:285#ifndef CHROME_BROWSER_EXTENSIONS_PENDING_EXTENSION_INFO_H_
6#define CHROME_BROWSER_EXTENSIONS_PENDING_EXTENSION_INFO_H_
[email protected]483d1ff2011-03-03 17:12:027
[email protected]4ec0f4b2012-12-07 09:41:468#include <string>
9
[email protected]b52f8ca2013-11-28 08:25:2210#include "base/gtest_prod_util.h"
[email protected]e3987852012-05-04 10:06:3011#include "base/version.h"
[email protected]d42c11152013-08-22 19:36:3212#include "extensions/common/manifest.h"
[email protected]a6483d22013-07-03 22:11:0013#include "url/gurl.h"
[email protected]483d1ff2011-03-03 17:12:0214
Devlin Cronineea1b7a2018-05-26 02:46:2115namespace extensions {
[email protected]3f213ad2012-07-26 23:39:4116FORWARD_DECLARE_TEST(ExtensionServiceTest, AddPendingExtensionFromSync);
17
[email protected]b52f8ca2013-11-28 08:25:2218class Extension;
[email protected]3f213ad2012-07-26 23:39:4119
[email protected]483d1ff2011-03-03 17:12:0220// 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]b2907fd2011-03-25 16:43:3724// TODO(skerner): Make this class an implementation detail of
25// PendingExtensionManager, and remove all other users.
[email protected]483d1ff2011-03-03 17:12:0226class PendingExtensionInfo {
27 public:
[email protected]8f3bcbd2013-06-05 08:42:4028 typedef bool (*ShouldAllowInstallPredicate)(const Extension*);
[email protected]483d1ff2011-03-03 17:12:0229
[email protected]d8fd0fd2014-03-24 13:16:0630 PendingExtensionInfo(const std::string& id,
31 const std::string& install_parameter,
32 const GURL& update_url,
pwnallcbd73192016-08-22 18:59:1733 const base::Version& version,
[email protected]d8fd0fd2014-03-24 13:16:0634 ShouldAllowInstallPredicate should_allow_install,
35 bool is_from_sync,
[email protected]d8fd0fd2014-03-24 13:16:0636 Manifest::Location install_source,
mamir0128d5a2016-07-15 20:55:4837 int creation_flags,
[email protected]21db9ef2014-05-16 02:06:2738 bool mark_acknowledged,
39 bool remote_install);
[email protected]483d1ff2011-03-03 17:12:0240
[email protected]b2907fd2011-03-25 16:43:3741 // Required for STL container membership. Should not be used directly.
[email protected]483d1ff2011-03-03 17:12:0242 PendingExtensionInfo();
43
vmpstrb8aacbe2016-02-26 02:00:4844 PendingExtensionInfo(const PendingExtensionInfo& other);
45
[email protected]d8fd0fd2014-03-24 13:16:0646 ~PendingExtensionInfo();
47
[email protected]51a3bf8b2012-06-08 22:53:0648 // 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]483d1ff2011-03-03 17:12:0252 const GURL& update_url() const { return update_url_; }
pwnallcbd73192016-08-22 18:59:1753 const base::Version& version() const { return version_; }
[email protected]d8fd0fd2014-03-24 13:16:0654 const std::string& install_parameter() const { return install_parameter_; }
[email protected]483d1ff2011-03-03 17:12:0255
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]8f3bcbd2013-06-05 08:42:4062 bool ShouldAllowInstall(const Extension* extension) const {
[email protected]483d1ff2011-03-03 17:12:0263 return should_allow_install_(extension);
64 }
65 bool is_from_sync() const { return is_from_sync_; }
[email protected]1d5e58b2013-01-31 08:41:4066 Manifest::Location install_source() const { return install_source_; }
mamir0128d5a2016-07-15 20:55:4867 int creation_flags() const { return creation_flags_; }
[email protected]464213a2013-10-15 01:06:4868 bool mark_acknowledged() const { return mark_acknowledged_; }
[email protected]21db9ef2014-05-16 02:06:2769 bool remote_install() const { return remote_install_; }
[email protected]483d1ff2011-03-03 17:12:0270
[email protected]4ec0f4b2012-12-07 09:41:4671 // 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]483d1ff2011-03-03 17:12:0278 private:
[email protected]51a3bf8b2012-06-08 22:53:0679 std::string id_;
80
[email protected]483d1ff2011-03-03 17:12:0281 GURL update_url_;
pwnallcbd73192016-08-22 18:59:1782 base::Version version_;
[email protected]d8fd0fd2014-03-24 13:16:0683 std::string install_parameter_;
[email protected]483d1ff2011-03-03 17:12:0284
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]1d5e58b2013-01-31 08:41:4091 Manifest::Location install_source_;
mamir0128d5a2016-07-15 20:55:4892 int creation_flags_;
[email protected]464213a2013-10-15 01:06:4893 bool mark_acknowledged_;
[email protected]21db9ef2014-05-16 02:06:2794 bool remote_install_;
[email protected]483d1ff2011-03-03 17:12:0295
Devlin Cronineea1b7a2018-05-26 02:46:2196 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest, AddPendingExtensionFromSync);
[email protected]483d1ff2011-03-03 17:12:0297};
98
[email protected]3f213ad2012-07-26 23:39:4199} // namespace extensions
100
[email protected]f3d3b382014-03-14 21:19:28101#endif // CHROME_BROWSER_EXTENSIONS_PENDING_EXTENSION_INFO_H_