diff --git a/browser/resources/settings/brave_ipfs_page/p2p_keys_subpage.js b/browser/resources/settings/brave_ipfs_page/p2p_keys_subpage.js
index 246dff61e0c2..79fc9af74aff 100644
--- a/browser/resources/settings/brave_ipfs_page/p2p_keys_subpage.js
+++ b/browser/resources/settings/brave_ipfs_page/p2p_keys_subpage.js
@@ -47,6 +47,10 @@ Polymer({
type: Boolean,
value: false,
},
+ importKeysError_: {
+ type: Boolean,
+ value: false,
+ },
showAddp2pKeyDialog_: {
type: Boolean,
value: false,
@@ -61,16 +65,33 @@ Polymer({
this.addWebUIListener('brave-ipfs-node-status-changed', (launched) => {
this.onServiceLaunched(launched)
})
- this.addWebUIListener('brave-ipfs-keys-loaded', (launched) => {
+ this.addWebUIListener('brave-ipfs-keys-loaded', (success) => {
this.updateKeys()
})
+ this.addWebUIListener('brave-ipfs-key-imported', (key, value, success) => {
+ this.importKeysError_ = !success
+ if (this.importKeysError_ ) {
+ const errorLabel = (this.$$('#key-import-error'));
+ errorLabel.textContent = this.i18n('ipfsImporKeysError', key)
+ return;
+ }
+ this.keys_.push({ "name" : key, "value" : value});
+ this.notifyKeylist();
+ })
+ },
+ notifyKeylist: function() {
+ const keysList =
+ /** @type {IronListElement} */ (this.$$('#keysList'));
+ if (keysList) {
+ keysList.notifyResize();
+ }
},
-
toggleUILayout: function(launched) {
this.launchNodeButtonEnabled_ = !launched;
this.localNodeLaunched = launched
+ this.importKeysError_ = false
if (launched) {
- this.localNodeLaunchError_ = false;
+ this.localNodeLaunchError_ = false
} else {
this.showAddp2pKeyDialog_ = false
}
@@ -78,6 +99,9 @@ Polymer({
onServiceLaunched: function(success) {
this.toggleUILayout(success)
+ if (success) {
+ this.updateKeys();
+ }
},
onStartNodeKeyTap_: function() {
@@ -91,12 +115,7 @@ Polymer({
/*++++++
* @override */
ready: function() {
- this.onServiceLaunched(this.localNodeLaunched)
- window.addEventListener('load', this.onLoad_.bind(this));
- },
-
- onLoad_: function() {
- this.updateKeys();
+ this.browserProxy_.notifyIpfsNodeStatus();
},
isDefaultKey_: function(name) {
@@ -113,6 +132,7 @@ Polymer({
return;
this.keys_ = JSON.parse(keys);
this.toggleUILayout(true)
+ this.notifyKeylist();
});
},
diff --git a/browser/ui/webui/settings/brave_default_extensions_handler.cc b/browser/ui/webui/settings/brave_default_extensions_handler.cc
index 774cc75d79da..90444aaecfa4 100644
--- a/browser/ui/webui/settings/brave_default_extensions_handler.cc
+++ b/browser/ui/webui/settings/brave_default_extensions_handler.cc
@@ -5,6 +5,7 @@
#include "brave/browser/ui/webui/settings/brave_default_extensions_handler.h"
+#include
#include
#include "base/bind.h"
@@ -25,6 +26,7 @@
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_finder.h"
#include "chrome/browser/ui/browser_window.h"
+#include "chrome/browser/ui/chrome_select_file_policy.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/pref_names.h"
#include "components/flags_ui/flags_ui_constants.h"
@@ -57,6 +59,7 @@
#if BUILDFLAG(IPFS_ENABLED)
#include "brave/browser/ipfs/ipfs_service_factory.h"
#include "brave/components/ipfs/ipfs_service.h"
+#include "brave/components/ipfs/keys/ipns_keys_manager.h"
#include "brave/components/ipfs/pref_names.h"
#endif
@@ -77,6 +80,26 @@ void BraveDefaultExtensionsHandler::RegisterMessages() {
if (service) {
ipfs_service_observer_.Observe(service);
}
+ web_ui()->RegisterMessageCallback(
+ "notifyIpfsNodeStatus",
+ base::BindRepeating(&BraveDefaultExtensionsHandler::CheckIpfsNodeStatus,
+ base::Unretained(this)));
+ web_ui()->RegisterMessageCallback(
+ "setIPFSStorageMax",
+ base::BindRepeating(&BraveDefaultExtensionsHandler::SetIPFSStorageMax,
+ base::Unretained(this)));
+ web_ui()->RegisterMessageCallback(
+ "importIpnsKey",
+ base::BindRepeating(&BraveDefaultExtensionsHandler::ImportIpnsKey,
+ base::Unretained(this)));
+ web_ui()->RegisterMessageCallback(
+ "launchIPFSService",
+ base::BindRepeating(&BraveDefaultExtensionsHandler::LaunchIPFSService,
+ base::Unretained(this)));
+ web_ui()->RegisterMessageCallback(
+ "shutdownIPFSService",
+ base::BindRepeating(&BraveDefaultExtensionsHandler::ShutdownIPFSService,
+ base::Unretained(this)));
#endif
web_ui()->RegisterMessageCallback(
@@ -102,19 +125,6 @@ void BraveDefaultExtensionsHandler::RegisterMessages() {
"setMediaRouterEnabled",
base::BindRepeating(&BraveDefaultExtensionsHandler::SetMediaRouterEnabled,
base::Unretained(this)));
- web_ui()->RegisterMessageCallback(
- "setIPFSStorageMax",
- base::BindRepeating(&BraveDefaultExtensionsHandler::SetIPFSStorageMax,
- base::Unretained(this)));
- web_ui()->RegisterMessageCallback(
- "launchIPFSService",
- base::BindRepeating(&BraveDefaultExtensionsHandler::LaunchIPFSService,
- base::Unretained(this)));
- web_ui()->RegisterMessageCallback(
- "shutdownIPFSService",
- base::BindRepeating(&BraveDefaultExtensionsHandler::ShutdownIPFSService,
- base::Unretained(this)));
-
// TODO(petemill): If anything outside this handler is responsible for causing
// restart-neccessary actions, then this should be moved to a generic handler
// and the flag should be moved to somewhere more static / singleton-like.
@@ -509,21 +519,79 @@ void BraveDefaultExtensionsHandler::GetDecentralizedDnsResolveMethodList(
}
#if BUILDFLAG(IPFS_ENABLED)
-void BraveDefaultExtensionsHandler::OnIpfsLaunched(bool result, int64_t pid) {
- if (!IsJavascriptAllowed())
+void BraveDefaultExtensionsHandler::FileSelected(const base::FilePath& path,
+ int index,
+ void* params) {
+ ipfs::IpfsService* service =
+ ipfs::IpfsServiceFactory::GetForContext(profile_);
+ if (!service)
return;
+ service->GetIpnsKeysManager()->ImportKey(
+ path, dialog_key_,
+ base::BindOnce(&BraveDefaultExtensionsHandler::OnKeyImported,
+ base::Unretained(this)));
+ select_file_dialog_.reset();
+ dialog_key_.clear();
+}
+
+void BraveDefaultExtensionsHandler::OnKeyImported(const std::string& key,
+ const std::string& value,
+ bool success) {
+ FireWebUIListener("brave-ipfs-key-imported", base::Value(key),
+ base::Value(value), base::Value(success));
+}
+
+void BraveDefaultExtensionsHandler::FileSelectionCanceled(void* params) {
+ select_file_dialog_.reset();
+ dialog_key_.clear();
+}
+
+void BraveDefaultExtensionsHandler::ImportIpnsKey(const base::ListValue* args) {
+ CHECK_EQ(args->GetSize(), 1U);
+ CHECK(profile_);
+ std::string key_name;
+ args->GetString(0, &key_name);
+ auto* web_contents = web_ui()->GetWebContents();
+ select_file_dialog_ = ui::SelectFileDialog::Create(
+ this, std::make_unique(web_contents));
+ if (!select_file_dialog_) {
+ VLOG(1) << "Export already in progress";
+ return;
+ }
+ Profile* profile =
+ Profile::FromBrowserContext(web_contents->GetBrowserContext());
+ const base::FilePath directory = profile->last_selected_directory();
+ gfx::NativeWindow parent_window = web_contents->GetTopLevelNativeWindow();
+ ui::SelectFileDialog::FileTypeInfo file_types;
+ file_types.allowed_paths = ui::SelectFileDialog::FileTypeInfo::NATIVE_PATH;
+ dialog_key_ = key_name;
+ select_file_dialog_->SelectFile(
+ ui::SelectFileDialog::SELECT_OPEN_FILE, std::u16string(), directory,
+ &file_types, 0, FILE_PATH_LITERAL("key"), parent_window, nullptr);
+}
+
+void BraveDefaultExtensionsHandler::CheckIpfsNodeStatus(
+ const base::ListValue* args) {
+ NotifyNodeStatus();
+}
+
+void BraveDefaultExtensionsHandler::NotifyNodeStatus() {
ipfs::IpfsService* service =
ipfs::IpfsServiceFactory::GetForContext(profile_);
bool launched = service && service->IsDaemonLaunched();
FireWebUIListener("brave-ipfs-node-status-changed", base::Value(launched));
}
+
+void BraveDefaultExtensionsHandler::OnIpfsLaunched(bool result, int64_t pid) {
+ if (!IsJavascriptAllowed())
+ return;
+ NotifyNodeStatus();
+}
+
void BraveDefaultExtensionsHandler::OnIpfsShutdown() {
if (!IsJavascriptAllowed())
return;
- ipfs::IpfsService* service =
- ipfs::IpfsServiceFactory::GetForContext(profile_);
- bool launched = service && service->IsDaemonLaunched();
- FireWebUIListener("brave-ipfs-node-status-changed", base::Value(launched));
+ NotifyNodeStatus();
}
void BraveDefaultExtensionsHandler::OnIpnsKeysLoaded(bool success) {
if (!IsJavascriptAllowed())
diff --git a/browser/ui/webui/settings/brave_default_extensions_handler.h b/browser/ui/webui/settings/brave_default_extensions_handler.h
index 529b8e7cf3f2..aca34bcf1b6c 100644
--- a/browser/ui/webui/settings/brave_default_extensions_handler.h
+++ b/browser/ui/webui/settings/brave_default_extensions_handler.h
@@ -20,6 +20,7 @@
#if BUILDFLAG(IPFS_ENABLED)
#include "brave/components/ipfs/ipfs_service.h"
#include "brave/components/ipfs/ipfs_service_observer.h"
+#include "ui/shell_dialogs/select_file_dialog.h"
#endif
class Profile;
@@ -27,7 +28,8 @@ class Profile;
class BraveDefaultExtensionsHandler : public settings::SettingsPageUIHandler
#if BUILDFLAG(IPFS_ENABLED)
,
- ipfs::IpfsServiceObserver
+ ipfs::IpfsServiceObserver,
+ public ui::SelectFileDialog::Listener
#endif
{
public:
@@ -46,6 +48,7 @@ class BraveDefaultExtensionsHandler : public settings::SettingsPageUIHandler
void SetIPFSCompanionEnabled(const base::ListValue* args);
void SetMediaRouterEnabled(const base::ListValue* args);
void SetIPFSStorageMax(const base::ListValue* args);
+ void ImportIpnsKey(const base::ListValue* args);
void LaunchIPFSService(const base::ListValue* args);
void ShutdownIPFSService(const base::ListValue* args);
#if BUILDFLAG(BRAVE_WALLET_ENABLED)
@@ -74,10 +77,24 @@ class BraveDefaultExtensionsHandler : public settings::SettingsPageUIHandler
bool IsRestartNeeded();
#if BUILDFLAG(IPFS_ENABLED)
+ // ui::SelectFileDialog::Listener
+ void FileSelected(const base::FilePath& path,
+ int index,
+ void* params) override;
+ void FileSelectionCanceled(void* params) override;
+
+ void OnKeyImported(const std::string& key,
+ const std::string& value,
+ bool success);
// ipfs::IpfsServiceObserver
void OnIpfsLaunched(bool result, int64_t pid) override;
void OnIpfsShutdown() override;
void OnIpnsKeysLoaded(bool success) override;
+ void CheckIpfsNodeStatus(const base::ListValue* args);
+ void NotifyNodeStatus();
+
+ std::string dialog_key_;
+ scoped_refptr select_file_dialog_;
#endif
#if BUILDFLAG(ENABLE_WIDEVINE)
diff --git a/chromium_src/chrome/browser/ui/webui/settings/settings_localized_strings_provider.cc b/chromium_src/chrome/browser/ui/webui/settings/settings_localized_strings_provider.cc
index 5d53330878d9..bc129c70c50f 100644
--- a/chromium_src/chrome/browser/ui/webui/settings/settings_localized_strings_provider.cc
+++ b/chromium_src/chrome/browser/ui/webui/settings/settings_localized_strings_provider.cc
@@ -282,6 +282,9 @@ void BraveAddCommonStrings(content::WebUIDataSource* html_source,
{"ipfsKeysNodeNotLaunched", IDS_SETTINGS_IPNS_KEYS_NODE_NOT_LAUNCHED},
{"ipfsKeysStartNode", IDS_SETTINGS_IPNS_KEYS_START_NODE},
{"ipfsKeysNodeLaunchError", IDS_SETTINGS_IPNS_KEYS_START_NODE_ERROR},
+ {"ipfsKeyImport", IDS_SETTINGS_IPNS_KEYS_IMPORT_BUTTON_TITLE},
+ {"ipfsKeyGenerate", IDS_SETTINGS_IPNS_KEYS_GENERATE_BUTTON_TITLE},
+ {"ipfsImporKeysError", IDS_SETTINGS_IPNS_KEYS_IMPORT_ERROR},
};
html_source->AddLocalizedStrings(localized_strings);
html_source->AddString("webRTCLearnMoreURL",
diff --git a/components/ipfs/ipfs_network_utils.cc b/components/ipfs/ipfs_network_utils.cc
index 39c7e61e7b85..f448d44db357 100644
--- a/components/ipfs/ipfs_network_utils.cc
+++ b/components/ipfs/ipfs_network_utils.cc
@@ -164,10 +164,6 @@ std::unique_ptr BuildBlobWithFolder(
namespace ipfs {
-<<<<<<< HEAD
-=======
-
->>>>>>> 8ba05e73c8 (Implemented IPFS import refactoring)
std::unique_ptr CreateURLLoader(
const GURL& gurl,
const std::string& method,
@@ -252,13 +248,8 @@ void CreateRequestForFile(const base::FilePath& upload_file_path,
size_t file_size) {
std::string mime_boundary = net::GenerateMimeMultipartBoundary();
auto blob_builder_callback =
-<<<<<<< HEAD
base::BindOnce(&BuildBlobWithFile, upload_file_path, mime_type, filename,
mime_boundary, file_size);
-=======
- base::BindOnce(&BuildBlobWithFile, upload_file_path, mime_type,
- filename, mime_boundary, file_size);
->>>>>>> 8ba05e73c8 (Implemented IPFS import refactoring)
std::string content_type = ipfs::kIPFSImportMultipartContentType;
content_type += " boundary=";
content_type += mime_boundary;
@@ -266,20 +257,11 @@ void CreateRequestForFile(const base::FilePath& upload_file_path,
base::PostTaskAndReplyWithResult(
FROM_HERE, {base::MayBlock(), content::BrowserThread::IO},
base::BindOnce(&CreateResourceRequest, std::move(blob_builder_callback),
-<<<<<<< HEAD
content_type, std::move(storage)),
std::move(request_callback));
}
std::vector EnumerateDirectoryFiles(base::FilePath dir_path) {
-=======
- content_type, std::move(storage)),
- std::move(request_callback));
-}
-
-std::vector EnumerateDirectoryFiles(
- base::FilePath dir_path) {
->>>>>>> 8ba05e73c8 (Implemented IPFS import refactoring)
std::vector files;
base::FileEnumerator file_enum(
dir_path, true,
diff --git a/components/ipfs/ipfs_network_utils_unittest.cc b/components/ipfs/ipfs_network_utils_unittest.cc
index 093702f23b2c..23db54c4edd8 100644
--- a/components/ipfs/ipfs_network_utils_unittest.cc
+++ b/components/ipfs/ipfs_network_utils_unittest.cc
@@ -16,13 +16,11 @@
#include "services/network/public/cpp/data_element.h"
#include "storage/browser/blob/blob_data_builder.h"
#include "storage/browser/blob/blob_data_item.h"
-
-#include "services/network/public/cpp/data_element.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace ipfs {
-class IpfsNetwrokUtilsUnitTest : public ChromeRenderViewHostTestHarness {
+class IpfsNetwrokUtilsUnitTest : public testing::Test {
public:
IpfsNetwrokUtilsUnitTest() {}
~IpfsNetwrokUtilsUnitTest() override = default;
diff --git a/components/ipfs/keys/ipns_keys_manager.cc b/components/ipfs/keys/ipns_keys_manager.cc
index 58398c3aefcc..97b99f3fa831 100644
--- a/components/ipfs/keys/ipns_keys_manager.cc
+++ b/components/ipfs/keys/ipns_keys_manager.cc
@@ -9,15 +9,22 @@
#include
#include
+#include "base/task/post_task.h"
+#include "base/task/thread_pool.h"
#include "brave/components/ipfs/ipfs_constants.h"
#include "brave/components/ipfs/ipfs_json_parser.h"
#include "brave/components/ipfs/ipfs_network_utils.h"
#include "content/public/browser/browser_context.h"
+#include "content/public/browser/browser_task_traits.h"
#include "content/public/browser/storage_partition.h"
+#include "net/base/mime_util.h"
#include "net/base/url_util.h"
#include "net/http/http_status_code.h"
+#include "services/network/public/cpp/resource_request.h"
#include "services/network/public/cpp/shared_url_loader_factory.h"
#include "services/network/public/cpp/simple_url_loader.h"
+#include "storage/browser/blob/blob_data_builder.h"
+#include "storage/browser/blob/blob_data_handle.h"
namespace ipfs {
@@ -32,6 +39,26 @@ IpnsKeysManager::IpnsKeysManager(content::BrowserContext* context,
IpnsKeysManager::~IpnsKeysManager() {}
+void IpnsKeysManager::ImportKey(const base::FilePath& upload_file_path,
+ const std::string& name,
+ ImportKeyCallback callback) {
+ auto blob_storage_context_getter =
+ content::BrowserContext::GetBlobStorageContext(context_);
+
+ auto upload_callback =
+ base::BindOnce(&IpnsKeysManager::UploadData, weak_factory_.GetWeakPtr(),
+ std::move(callback), name);
+ auto filename = upload_file_path.BaseName().MaybeAsASCII();
+ auto file_request_callback =
+ base::BindOnce(&CreateRequestForFile, upload_file_path,
+ std::move(blob_storage_context_getter),
+ ipfs::kFileMimeType, filename, std::move(upload_callback));
+ base::ThreadPool::PostTaskAndReplyWithResult(
+ FROM_HERE, {base::MayBlock()},
+ base::BindOnce(&CalculateFileSize, upload_file_path),
+ std::move(file_request_callback));
+}
+
bool IpnsKeysManager::KeyExists(const std::string& name) const {
return keys_.count(name);
}
@@ -49,12 +76,12 @@ void IpnsKeysManager::RemoveKey(const std::string& name,
GURL gurl =
net::AppendQueryParameter(generate_endpoint, kArgQueryParam, name);
- auto url_loader = CreateURLLoader(gurl, "POST");
+ auto url_loader = ipfs::CreateURLLoader(gurl, "POST");
auto iter = url_loaders_.insert(url_loaders_.begin(), std::move(url_loader));
iter->get()->DownloadToStringOfUnboundedSizeUntilCrashAndDie(
url_loader_factory_.get(),
- base::BindOnce(&IpnsKeysManager::OnKeyRemoved, base::Unretained(this),
+ base::BindOnce(&IpnsKeysManager::OnKeyRemoved, weak_factory_.GetWeakPtr(),
iter, name, std::move(callback)));
}
@@ -69,8 +96,6 @@ void IpnsKeysManager::OnKeyRemoved(SimpleURLLoaderList::iterator iter,
response_code = url_loader->ResponseInfo()->headers->response_code();
url_loaders_.erase(iter);
- std::string name;
- std::string value;
bool success = (error_code == net::OK && response_code == net::HTTP_OK);
std::unordered_map removed_keys;
success = success &&
@@ -104,7 +129,7 @@ void IpnsKeysManager::GenerateNewKey(const std::string& name,
auto iter = url_loaders_.insert(url_loaders_.begin(), std::move(url_loader));
iter->get()->DownloadToStringOfUnboundedSizeUntilCrashAndDie(
url_loader_factory_.get(),
- base::BindOnce(&IpnsKeysManager::OnKeyCreated, base::Unretained(this),
+ base::BindOnce(&IpnsKeysManager::OnKeyCreated, weak_factory_.GetWeakPtr(),
iter, std::move(callback)));
}
@@ -147,8 +172,58 @@ void IpnsKeysManager::LoadKeys(LoadKeysCallback callback) {
auto iter = url_loaders_.insert(url_loaders_.begin(), std::move(url_loader));
iter->get()->DownloadToStringOfUnboundedSizeUntilCrashAndDie(
- url_loader_factory_.get(), base::BindOnce(&IpnsKeysManager::OnKeysLoaded,
- base::Unretained(this), iter));
+ url_loader_factory_.get(),
+ base::BindOnce(&IpnsKeysManager::OnKeysLoaded, weak_factory_.GetWeakPtr(),
+ iter));
+}
+
+void IpnsKeysManager::UploadData(
+ ImportKeyCallback callback,
+ const std::string& name,
+ std::unique_ptr request) {
+ DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
+ if (!request)
+ return;
+
+ auto generate_endpoint = server_endpoint_.Resolve(kAPIKeyImportEndpoint);
+ GURL url = net::AppendQueryParameter(generate_endpoint, kArgQueryParam, name);
+
+ auto url_loader = CreateURLLoader(url, "POST", std::move(request));
+ auto iter = url_loaders_.insert(url_loaders_.begin(), std::move(url_loader));
+ iter->get()->DownloadToStringOfUnboundedSizeUntilCrashAndDie(
+ url_loader_factory_.get(),
+ base::BindOnce(&IpnsKeysManager::OnKeyImported,
+ weak_factory_.GetWeakPtr(), iter, std::move(callback),
+ name));
+}
+
+void IpnsKeysManager::OnKeyImported(
+ SimpleURLLoaderList::iterator iter,
+ ImportKeyCallback callback,
+ const std::string& key_name,
+ std::unique_ptr response_body) {
+ auto* url_loader = iter->get();
+ int error_code = url_loader->NetError();
+ int response_code = -1;
+ if (url_loader->ResponseInfo() && url_loader->ResponseInfo()->headers)
+ response_code = url_loader->ResponseInfo()->headers->response_code();
+ url_loaders_.erase(iter);
+
+ bool success = (error_code == net::OK && response_code == net::HTTP_OK);
+ std::string name;
+ std::string value;
+ std::unordered_map new_keys;
+ success = success && IPFSJSONParser::GetParseSingleKeyFromJSON(*response_body,
+ &name, &value);
+ if (success) {
+ DCHECK_EQ(key_name, name) << "Key names should be equal";
+ keys_[name] = value;
+ } else {
+ VLOG(1) << "Fail to import key, error_code = " << error_code
+ << " response_code = " << response_code;
+ }
+ if (callback)
+ std::move(callback).Run(key_name, value, success);
}
void IpnsKeysManager::OnIpfsShutdown() {
diff --git a/components/ipfs/keys/ipns_keys_manager.h b/components/ipfs/keys/ipns_keys_manager.h
index 19975f31d36e..08c73260daa7 100644
--- a/components/ipfs/keys/ipns_keys_manager.h
+++ b/components/ipfs/keys/ipns_keys_manager.h
@@ -14,7 +14,9 @@
#include "base/callback.h"
#include "base/containers/queue.h"
#include "base/memory/scoped_refptr.h"
+#include "brave/components/ipfs/ipfs_network_utils.h"
#include "brave/components/ipfs/ipfs_service_observer.h"
+#include "services/network/public/cpp/resource_request.h"
#include "url/gurl.h"
namespace content {
@@ -24,6 +26,7 @@ class BrowserContext;
namespace network {
class SharedURLLoaderFactory;
class SimpleURLLoader;
+struct ResourceRequest;
} // namespace network
namespace ipfs {
@@ -43,6 +46,8 @@ class IpnsKeysManager : public IpfsServiceObserver {
using GenerateKeyCallback =
base::OnceCallback;
using RemoveKeyCallback = base::OnceCallback;
+ using ImportKeyCallback =
+ base::OnceCallback;
using KeysMap = std::unordered_map;
void LoadKeys(LoadKeysCallback callback);
void GenerateNewKey(const std::string& name, GenerateKeyCallback callback);
@@ -52,6 +57,9 @@ class IpnsKeysManager : public IpfsServiceObserver {
const KeysMap& GetKeys() const { return keys_; }
const std::string FindKey(const std::string& name) const;
+ void ImportKey(const base::FilePath& paths,
+ const std::string& name,
+ ImportKeyCallback callback);
void SetServerEndpointForTest(const GURL& gurl);
void SetLoadCallbackForTest(LoadKeysCallback callback);
@@ -61,7 +69,10 @@ class IpnsKeysManager : public IpfsServiceObserver {
// ipfs::IpfsServiceObserver
void OnIpfsShutdown() override;
-
+ void OnKeyImported(SimpleURLLoaderList::iterator iter,
+ ImportKeyCallback callback,
+ const std::string& key_name,
+ std::unique_ptr response_body);
void OnKeyCreated(SimpleURLLoaderList::iterator iter,
GenerateKeyCallback callback,
std::unique_ptr response_body);
@@ -69,18 +80,22 @@ class IpnsKeysManager : public IpfsServiceObserver {
const std::string& key_to_remove,
RemoveKeyCallback callback,
std::unique_ptr response_body);
-
void OnKeysLoaded(SimpleURLLoaderList::iterator iter,
std::unique_ptr response_body);
void NotifyKeysLoaded(bool result);
+ void UploadData(ImportKeyCallback callback,
+ const std::string& name,
+ std::unique_ptr request);
+
scoped_refptr url_loader_factory_;
SimpleURLLoaderList url_loaders_;
std::unordered_map keys_;
base::queue pending_load_callbacks_;
content::BrowserContext* context_ = nullptr;
GURL server_endpoint_;
+ base::WeakPtrFactory weak_factory_{this};
};
} // namespace ipfs