| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2017 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 #include "extensions/browser/mock_external_provider.h" |
| 6 |
| 7 #include "base/memory/ptr_util.h" |
| 8 #include "base/version.h" |
| 9 #include "extensions/browser/external_install_info.h" |
| 10 #include "extensions/common/extension.h" |
| 11 |
| 12 namespace extensions { |
| 13 |
| 14 MockExternalProvider::MockExternalProvider(VisitorInterface* visitor, |
| 15 Manifest::Location location) |
| 16 : location_(location), visitor_(visitor), visit_count_(0) {} |
| 17 |
| 18 MockExternalProvider::~MockExternalProvider() {} |
| 19 |
| 20 void MockExternalProvider::UpdateOrAddExtension(const ExtensionId& id, |
| 21 const std::string& version, |
| 22 const base::FilePath& path) { |
| 23 extension_map_[id] = std::make_pair(version, path); |
| 24 } |
| 25 |
| 26 void MockExternalProvider::RemoveExtension(const ExtensionId& id) { |
| 27 extension_map_.erase(id); |
| 28 } |
| 29 |
| 30 void MockExternalProvider::VisitRegisteredExtension() { |
| 31 visit_count_++; |
| 32 for (const auto& extension_kv : extension_map_) { |
| 33 std::unique_ptr<base::Version> version = |
| 34 base::MakeUnique<base::Version>(extension_kv.second.first); |
| 35 std::unique_ptr<ExternalInstallInfoFile> info = |
| 36 base::MakeUnique<ExternalInstallInfoFile>( |
| 37 extension_kv.first, std::move(version), extension_kv.second.second, |
| 38 location_, Extension::NO_FLAGS, false, false); |
| 39 visitor_->OnExternalExtensionFileFound(*info); |
| 40 } |
| 41 visitor_->OnExternalProviderReady(this); |
| 42 } |
| 43 |
| 44 bool MockExternalProvider::HasExtension(const std::string& id) const { |
| 45 return extension_map_.find(id) != extension_map_.end(); |
| 46 } |
| 47 |
| 48 bool MockExternalProvider::GetExtensionDetails( |
| 49 const std::string& id, |
| 50 Manifest::Location* location, |
| 51 std::unique_ptr<base::Version>* version) const { |
| 52 DataMap::const_iterator it = extension_map_.find(id); |
| 53 if (it == extension_map_.end()) |
| 54 return false; |
| 55 |
| 56 if (version) |
| 57 version->reset(new base::Version(it->second.first)); |
| 58 |
| 59 if (location) |
| 60 *location = location_; |
| 61 |
| 62 return true; |
| 63 } |
| 64 |
| 65 bool MockExternalProvider::IsReady() const { |
| 66 return true; |
| 67 } |
| 68 |
| 69 } // namespace extensions |
| OLD | NEW |