Revert 285173 "Removed InProcessBrowserTest::CleanUpOnMainThread()"
[chromium-blink-merge.git] / chrome / browser / extensions / pending_extension_info.h
blob11c159aafa15adcf69564394787ba7c6dcb91291
1 // Copyright 2014 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_
8 #include <string>
10 #include "base/gtest_prod_util.h"
11 #include "base/version.h"
12 #include "extensions/common/manifest.h"
13 #include "url/gurl.h"
15 FORWARD_DECLARE_TEST(ExtensionServiceTest, AddPendingExtensionFromSync);
17 namespace extensions {
18 class Extension;
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.
24 // TODO(skerner): Make this class an implementation detail of
25 // PendingExtensionManager, and remove all other users.
26 class PendingExtensionInfo {
27 public:
28 typedef bool (*ShouldAllowInstallPredicate)(const Extension*);
30 PendingExtensionInfo(const std::string& id,
31 const std::string& install_parameter,
32 const GURL& update_url,
33 const Version& version,
34 ShouldAllowInstallPredicate should_allow_install,
35 bool is_from_sync,
36 bool install_silently,
37 Manifest::Location install_source,
38 int creation_flags,
39 bool mark_acknowledged,
40 bool remote_install);
42 // Required for STL container membership. Should not be used directly.
43 PendingExtensionInfo();
45 ~PendingExtensionInfo();
47 // Consider two PendingExtensionInfos equal if their ids are equal.
48 bool operator==(const PendingExtensionInfo& rhs) const;
50 const std::string& id() const { return id_; }
51 const GURL& update_url() const { return update_url_; }
52 const Version& version() const { return version_; }
53 const std::string& install_parameter() const { return install_parameter_; }
55 // ShouldAllowInstall() returns the result of running constructor argument
56 // |should_allow_install| on an extension. After an extension is unpacked,
57 // this function is run. If it returns true, the extension is installed.
58 // If not, the extension is discarded. This allows creators of
59 // PendingExtensionInfo objects to ensure that extensions meet some criteria
60 // that can only be tested once the extension is unpacked.
61 bool ShouldAllowInstall(const Extension* extension) const {
62 return should_allow_install_(extension);
64 bool is_from_sync() const { return is_from_sync_; }
65 bool install_silently() const { return install_silently_; }
66 Manifest::Location install_source() const { return install_source_; }
67 int creation_flags() const { return creation_flags_; }
68 bool mark_acknowledged() const { return mark_acknowledged_; }
69 bool remote_install() const { return remote_install_; }
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;
78 private:
79 std::string id_;
81 GURL update_url_;
82 Version version_;
83 std::string install_parameter_;
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_;
90 bool is_from_sync_; // This update check was initiated from sync.
91 bool install_silently_;
92 Manifest::Location install_source_;
93 int creation_flags_;
94 bool mark_acknowledged_;
95 bool remote_install_;
97 FRIEND_TEST_ALL_PREFIXES(::ExtensionServiceTest, AddPendingExtensionFromSync);
100 } // namespace extensions
102 #endif // CHROME_BROWSER_EXTENSIONS_PENDING_EXTENSION_INFO_H_