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