1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
|
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "base/logging.h"
#include "base/stl_util-inl.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/extensions/pending_extension_manager.h"
#include "chrome/common/extensions/extension.h"
#include "content/browser/browser_thread.h"
namespace {
// Install predicate used by AddFromExternalUpdateUrl().
bool AlwaysInstall(const Extension& extension) {
return true;
}
} // namespace
PendingExtensionManager::PendingExtensionManager(
const ExtensionServiceInterface& service)
: service_(service) {
}
PendingExtensionManager::~PendingExtensionManager() {}
bool PendingExtensionManager::GetById(
const std::string& id,
PendingExtensionInfo* out_pending_extension_info) const {
PendingExtensionMap::const_iterator it = pending_extension_map_.find(id);
if (it != pending_extension_map_.end()) {
*out_pending_extension_info = it->second;
return true;
}
return false;
}
void PendingExtensionManager::Remove(const std::string& id) {
pending_extension_map_.erase(id);
}
bool PendingExtensionManager::IsIdPending(const std::string& id) const {
return ContainsKey(pending_extension_map_, id);
}
bool PendingExtensionManager::AddFromSync(
const std::string& id,
const GURL& update_url,
PendingExtensionInfo::ShouldAllowInstallPredicate should_allow_install,
bool install_silently) {
CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
if (service_.GetInstalledExtension(id)) {
LOG(ERROR) << "Trying to add pending extension " << id
<< " which already exists";
return false;
}
const bool kIsFromSync = true;
const Extension::Location kSyncLocation = Extension::INTERNAL;
return AddExtensionImpl(id, update_url, should_allow_install,
kIsFromSync, install_silently, kSyncLocation);
}
void PendingExtensionManager::AddFromExternalUpdateUrl(
const std::string& id, const GURL& update_url,
Extension::Location location) {
CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
const bool kIsFromSync = false;
const bool kInstallSilently = true;
if (service_.IsExternalExtensionUninstalled(id))
return;
if (service_.GetInstalledExtension(id)) {
LOG(DFATAL) << "Trying to add extension " << id
<< " by external update, but it is already installed.";
return;
}
AddExtensionImpl(id, update_url, &AlwaysInstall,
kIsFromSync, kInstallSilently,
location);
}
void PendingExtensionManager::AddFromExternalFile(
const std::string& id,
Extension::Location location) {
GURL kUpdateUrl = GURL();
bool kIsFromSync = false;
bool kInstallSilently = true;
pending_extension_map_[id] =
PendingExtensionInfo(kUpdateUrl,
&AlwaysInstall,
kIsFromSync,
kInstallSilently,
location);
}
bool PendingExtensionManager::AddExtensionImpl(
const std::string& id, const GURL& update_url,
PendingExtensionInfo::ShouldAllowInstallPredicate should_allow_install,
bool is_from_sync, bool install_silently,
Extension::Location install_source) {
CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
// Will add a pending extension record unless this variable is set to false.
bool should_add_pending_record = true;
if (ContainsKey(pending_extension_map_, id)) {
// Bugs in this code will manifest as sporadic incorrect extension
// locations in situations where multiple install sources run at the
// same time. For example, on first login to a chrome os machine, an
// extension may be requested by sync sync and the default extension set.
// The following logging will help diagnose such issues.
VLOG(1) << "Extension id " << id
<< " was entered for update more than once."
<< " old location: " << pending_extension_map_[id].install_source()
<< " new location: " << install_source;
Extension::Location higher_priority_location =
Extension::GetHigherPriorityLocation(
install_source, pending_extension_map_[id].install_source());
if (higher_priority_location == install_source) {
VLOG(1) << "Overwrite existing record.";
} else {
VLOG(1) << "Keep existing record.";
should_add_pending_record = false;
}
}
if (should_add_pending_record) {
pending_extension_map_[id] = PendingExtensionInfo(
update_url,
should_allow_install,
is_from_sync,
install_silently,
install_source);
return true;
}
return false;
}
void PendingExtensionManager::AddForTesting(
const std::string& id,
const PendingExtensionInfo& pending_extension_info) {
pending_extension_map_[id] = pending_extension_info;
}
|