Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / chrome / browser / extensions / pending_extension_info.cc
blob94a5608cfd03f249ad2c82b1917e19894544b5fe
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 #include "chrome/browser/extensions/pending_extension_info.h"
7 #include "base/logging.h"
9 namespace extensions {
11 PendingExtensionInfo::PendingExtensionInfo(
12 const std::string& id,
13 const std::string& install_parameter,
14 const GURL& update_url,
15 const Version& version,
16 ShouldAllowInstallPredicate should_allow_install,
17 bool is_from_sync,
18 Manifest::Location install_source,
19 int creation_flags,
20 bool mark_acknowledged,
21 bool remote_install)
22 : id_(id),
23 update_url_(update_url),
24 version_(version),
25 install_parameter_(install_parameter),
26 should_allow_install_(should_allow_install),
27 is_from_sync_(is_from_sync),
28 install_source_(install_source),
29 creation_flags_(creation_flags),
30 mark_acknowledged_(mark_acknowledged),
31 remote_install_(remote_install) {
34 PendingExtensionInfo::PendingExtensionInfo()
35 : update_url_(),
36 should_allow_install_(NULL),
37 is_from_sync_(true),
38 install_source_(Manifest::INVALID_LOCATION),
39 creation_flags_(0),
40 mark_acknowledged_(false),
41 remote_install_(false) {
44 PendingExtensionInfo::~PendingExtensionInfo() {}
46 bool PendingExtensionInfo::operator==(const PendingExtensionInfo& rhs) const {
47 return id_ == rhs.id_;
50 int PendingExtensionInfo::CompareTo(const PendingExtensionInfo& other) const {
51 DCHECK_EQ(id_, other.id_);
52 if (version_.IsValid() && other.version_.IsValid()) {
53 int comparison = version_.CompareTo(other.version_);
55 // If the versions differ then return the version comparison result.
56 if (comparison != 0)
57 return comparison;
60 // The versions aren't specified, or they are the same version. Check
61 // the install source.
62 if (install_source_ == other.install_source_) {
63 // Same install source, so |this| has the same precedence as |other|.
64 return 0;
67 // Different install sources; |this| has higher precedence if
68 // |install_source_| is the higher priority source.
69 Manifest::Location higher_priority_source =
70 Manifest::GetHigherPriorityLocation(
71 install_source_, other.install_source_);
73 return higher_priority_source == install_source_ ? 1 : -1;
76 } // namespace extensions