- add sources.
[platform/framework/web/crosswalk.git] / src / chrome / browser / extensions / pending_extension_info.h
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.
4
5 #ifndef CHROME_BROWSER_EXTENSIONS_PENDING_EXTENSION_INFO_H_
6 #define CHROME_BROWSER_EXTENSIONS_PENDING_EXTENSION_INFO_H_
7
8 #include <string>
9
10 #include "base/version.h"
11 #include "chrome/common/extensions/extension.h"
12 #include "extensions/common/manifest.h"
13 #include "url/gurl.h"
14
15 FORWARD_DECLARE_TEST(ExtensionServiceTest, AddPendingExtensionFromSync);
16
17 namespace extensions {
18
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 {
26  public:
27   typedef bool (*ShouldAllowInstallPredicate)(const Extension*);
28
29   PendingExtensionInfo(
30       const std::string& id,
31       const GURL& update_url,
32       const Version& version,
33       ShouldAllowInstallPredicate should_allow_install,
34       bool is_from_sync,
35       bool install_silently,
36       Manifest::Location install_source,
37       int creation_flags,
38       bool mark_acknowledged);
39
40   // Required for STL container membership.  Should not be used directly.
41   PendingExtensionInfo();
42
43   // Consider two PendingExtensionInfos equal if their ids are equal.
44   bool operator==(const PendingExtensionInfo& rhs) const;
45
46   const std::string& id() const { return id_; }
47   const GURL& update_url() const { return update_url_; }
48   const Version& version() const { return version_; }
49
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);
58   }
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_; }
64
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;
71
72  private:
73   std::string id_;
74
75   GURL update_url_;
76   Version version_;
77
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_;
82
83   bool is_from_sync_;  // This update check was initiated from sync.
84   bool install_silently_;
85   Manifest::Location install_source_;
86   int creation_flags_;
87   bool mark_acknowledged_;
88
89   FRIEND_TEST_ALL_PREFIXES(::ExtensionServiceTest, AddPendingExtensionFromSync);
90 };
91
92 }  // namespace extensions
93
94 #endif  // CHROME_BROWSER_EXTENSIONS_PENDING_EXTENSION_INFO_H_