OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 #include "extensions/browser/pending_extension_manager.h" | 5 #include "extensions/browser/pending_extension_manager.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/version.h" | 10 #include "base/version.h" |
11 #include "chrome/browser/extensions/extension_service.h" | 11 #include "chrome/browser/extensions/extension_service.h" |
12 #include "content/public/browser/browser_thread.h" | 12 #include "content/public/browser/browser_thread.h" |
13 #include "extensions/browser/extension_prefs.h" | |
13 #include "extensions/common/extension.h" | 14 #include "extensions/common/extension.h" |
14 #include "url/gurl.h" | 15 #include "url/gurl.h" |
15 | 16 |
16 using content::BrowserThread; | 17 using content::BrowserThread; |
17 | 18 |
18 namespace { | 19 namespace { |
19 | 20 |
20 // Install predicate used by AddFromExternalUpdateUrl(). | 21 // Install predicate used by AddFromExternalUpdateUrl(). |
21 bool AlwaysInstall(const extensions::Extension* extension) { | 22 bool AlwaysInstall(const extensions::Extension* extension) { |
22 return true; | 23 return true; |
23 } | 24 } |
24 | 25 |
25 std::string GetVersionString(const Version& version) { | 26 std::string GetVersionString(const Version& version) { |
26 return version.IsValid() ? version.GetString() : "invalid"; | 27 return version.IsValid() ? version.GetString() : "invalid"; |
27 } | 28 } |
28 | 29 |
29 } // namespace | 30 } // namespace |
30 | 31 |
31 namespace extensions { | 32 namespace extensions { |
32 | 33 |
33 PendingExtensionManager::PendingExtensionManager( | 34 PendingExtensionManager::PendingExtensionManager( |
34 const ExtensionServiceInterface& service) | 35 const ExtensionServiceInterface& service, |
35 : service_(service) { | 36 content::BrowserContext* context) |
36 } | 37 : service_(service), context_(context) {} |
37 | 38 |
38 PendingExtensionManager::~PendingExtensionManager() {} | 39 PendingExtensionManager::~PendingExtensionManager() {} |
39 | 40 |
40 const PendingExtensionInfo* PendingExtensionManager::GetById( | 41 const PendingExtensionInfo* PendingExtensionManager::GetById( |
41 const std::string& id) const { | 42 const std::string& id) const { |
42 PendingExtensionList::const_iterator iter; | 43 PendingExtensionList::const_iterator iter; |
43 for (iter = pending_extension_list_.begin(); | 44 for (iter = pending_extension_list_.begin(); |
44 iter != pending_extension_list_.end(); | 45 iter != pending_extension_list_.end(); |
45 ++iter) { | 46 ++iter) { |
46 if (id == iter->id()) | 47 if (id == iter->id()) |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
141 const GURL& update_url, | 142 const GURL& update_url, |
142 Manifest::Location location, | 143 Manifest::Location location, |
143 int creation_flags, | 144 int creation_flags, |
144 bool mark_acknowledged) { | 145 bool mark_acknowledged) { |
145 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 146 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
146 | 147 |
147 const bool kIsFromSync = false; | 148 const bool kIsFromSync = false; |
148 const bool kInstallSilently = true; | 149 const bool kInstallSilently = true; |
149 | 150 |
150 const Extension* extension = service_.GetInstalledExtension(id); | 151 const Extension* extension = service_.GetInstalledExtension(id); |
151 if (extension && | 152 if (extension && location == Manifest::GetHigherPriorityLocation( |
152 location == Manifest::GetHigherPriorityLocation(location, | 153 location, extension->location())) { |
153 extension->location())) { | |
154 // If the new location has higher priority than the location of an existing | 154 // If the new location has higher priority than the location of an existing |
155 // extension, let the update process overwrite the existing extension. | 155 // extension, let the update process overwrite the existing extension. |
156 } else { | 156 } else { |
157 if (service_.IsExternalExtensionUninstalled(id)) | 157 if (ExtensionPrefs::Get(context_)->IsExternalExtensionUninstalled(id)) |
Yoyo Zhou
2014/03/18 01:23:37
Could also use service->GetBrowserContext here.
Devlin
2014/03/18 17:24:12
Actually, can't... |service_| is an ExtensionServi
Yoyo Zhou
2014/03/22 00:34:37
May as well leave it as is for now then.
| |
158 return false; | 158 return false; |
159 | 159 |
160 if (extension) { | 160 if (extension) { |
161 LOG(DFATAL) << "Trying to add extension " << id | 161 LOG(DFATAL) << "Trying to add extension " << id |
162 << " by external update, but it is already installed."; | 162 << " by external update, but it is already installed."; |
163 return false; | 163 return false; |
164 } | 164 } |
165 } | 165 } |
166 | 166 |
167 return AddExtensionImpl(id, update_url, Version(), &AlwaysInstall, | 167 return AddExtensionImpl(id, update_url, Version(), &AlwaysInstall, |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
271 | 271 |
272 return true; | 272 return true; |
273 } | 273 } |
274 | 274 |
275 void PendingExtensionManager::AddForTesting( | 275 void PendingExtensionManager::AddForTesting( |
276 const PendingExtensionInfo& pending_extension_info) { | 276 const PendingExtensionInfo& pending_extension_info) { |
277 pending_extension_list_.push_back(pending_extension_info); | 277 pending_extension_list_.push_back(pending_extension_info); |
278 } | 278 } |
279 | 279 |
280 } // namespace extensions | 280 } // namespace extensions |
OLD | NEW |