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
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_EXTENSIONS_PENDING_EXTENSION_INFO_H_
6 #define CHROME_BROWSER_EXTENSIONS_PENDING_EXTENSION_INFO_H_
10 #include "base/version.h"
11 #include "chrome/common/extensions/extension.h"
12 #include "extensions/common/manifest.h"
15 FORWARD_DECLARE_TEST(ExtensionServiceTest, AddPendingExtensionFromSync);
17 namespace extensions {
19 // A pending extension is an extension that hasn't been installed yet
20 // and is intended to be installed in the next auto-update cycle. The
21 // update URL of a pending extension may be blank, in which case a
22 // default one is assumed.
23 // TODO(skerner): Make this class an implementation detail of
24 // PendingExtensionManager, and remove all other users.
25 class PendingExtensionInfo {
27 typedef bool (*ShouldAllowInstallPredicate)(const Extension*);
30 const std::string& id,
31 const GURL& update_url,
32 const Version& version,
33 ShouldAllowInstallPredicate should_allow_install,
35 bool install_silently,
36 Manifest::Location install_source,
38 bool mark_acknowledged);
40 // Required for STL container membership. Should not be used directly.
41 PendingExtensionInfo();
43 // Consider two PendingExtensionInfos equal if their ids are equal.
44 bool operator==(const PendingExtensionInfo& rhs) const;
46 const std::string& id() const { return id_; }
47 const GURL& update_url() const { return update_url_; }
48 const Version& version() const { return version_; }
50 // ShouldAllowInstall() returns the result of running constructor argument
51 // |should_allow_install| on an extension. After an extension is unpacked,
52 // this function is run. If it returns true, the extension is installed.
53 // If not, the extension is discarded. This allows creators of
54 // PendingExtensionInfo objects to ensure that extensions meet some criteria
55 // that can only be tested once the extension is unpacked.
56 bool ShouldAllowInstall(const Extension* extension) const {
57 return should_allow_install_(extension);
59 bool is_from_sync() const { return is_from_sync_; }
60 bool install_silently() const { return install_silently_; }
61 Manifest::Location install_source() const { return install_source_; }
62 int creation_flags() const { return creation_flags_; }
63 bool mark_acknowledged() const { return mark_acknowledged_; }
65 // Returns -1, 0 or 1 if |this| has lower, equal or higher precedence than
66 // |other|, respectively. "Equal" precedence means that the version and the
67 // install source match. "Higher" precedence means that the version is newer,
68 // or the version matches but the install source has higher priority.
69 // It is only valid to invoke this when the ids match.
70 int CompareTo(const PendingExtensionInfo& other) const;
78 // When the extension is about to be installed, this function is
79 // called. If this function returns true, the install proceeds. If
80 // this function returns false, the install is aborted.
81 ShouldAllowInstallPredicate should_allow_install_;
83 bool is_from_sync_; // This update check was initiated from sync.
84 bool install_silently_;
85 Manifest::Location install_source_;
87 bool mark_acknowledged_;
89 FRIEND_TEST_ALL_PREFIXES(::ExtensionServiceTest, AddPendingExtensionFromSync);
92 } // namespace extensions
94 #endif // CHROME_BROWSER_EXTENSIONS_PENDING_EXTENSION_INFO_H_