Skip to content
This repository was archived by the owner on Jan 4, 2019. It is now read-only.

Commit c3d6769

Browse files
committed
Fix map index key by SiteInstance and add callback
1 parent 1af566a commit c3d6769

File tree

4 files changed

+19
-10
lines changed

4 files changed

+19
-10
lines changed

atom/browser/api/atom_api_session.cc

+3-2
Original file line numberDiff line numberDiff line change
@@ -602,12 +602,13 @@ bool Session::IsOffTheRecord() const {
602602
return false;
603603
}
604604

605-
void Session::SetTorNewIdentity(const GURL& origin) const {
605+
void Session::SetTorNewIdentity(const GURL& url,
606+
const base::Closure& callback) const {
606607
brave::BraveBrowserContext* brave_browser_context =
607608
brave::BraveBrowserContext::FromBrowserContext(profile_);
608609
if (!brave_browser_context->IsIsolatedStorage())
609610
return;
610-
brave_browser_context->SetTorNewIdentity(origin);
611+
brave_browser_context->SetTorNewIdentity(url, callback);
611612
}
612613

613614
// static

atom/browser/api/atom_api_session.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,8 @@ class Session: public mate::TrackableObject<Session>,
9393
v8::Local<v8::Value> Extensions(v8::Isolate* isolate);
9494
bool Equal(Session* session) const;
9595
bool IsOffTheRecord() const;
96-
void SetTorNewIdentity(const GURL& origin) const;
96+
void SetTorNewIdentity(const GURL& url,
97+
const base::Closure& callback) const;
9798

9899
protected:
99100
Session(v8::Isolate* isolate, Profile* browser_context);

brave/browser/brave_browser_context.cc

+11-5
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
#include "content/public/browser/notification_source.h"
4747
#include "content/public/browser/browser_thread.h"
4848
#include "content/public/browser/dom_storage_context.h"
49+
#include "content/public/browser/site_instance.h"
4950
#include "content/public/browser/storage_partition.h"
5051
#include "crypto/random.h"
5152
#include "extensions/browser/pref_names.h"
@@ -345,7 +346,8 @@ BraveBrowserContext::CreateRequestContextForStoragePartition(
345346
std::move(request_interceptors));
346347
StoragePartitionDescriptor descriptor(partition_path, in_memory);
347348
url_request_context_getter_map_[descriptor] = url_request_context_getter;
348-
TorSetProxy(url_request_context_getter, partition_path);
349+
TorSetProxy(url_request_context_getter, partition_path,
350+
base::Bind(&base::DoNothing));
349351
return url_request_context_getter;
350352
} else {
351353
return nullptr;
@@ -429,7 +431,7 @@ void BraveBrowserContext::UpdateDefaultZoomLevel() {
429431

430432
void BraveBrowserContext::TorSetProxy(
431433
brightray::URLRequestContextGetter* url_request_context_getter,
432-
const base::FilePath partition_path) {
434+
const base::FilePath partition_path, const base::Closure& callback) {
433435
if (!url_request_context_getter || !isolated_storage_)
434436
return;
435437
if (!tor_proxy_.empty() && GURL(tor_proxy_).is_valid()) {
@@ -452,6 +454,8 @@ void BraveBrowserContext::TorSetProxy(
452454
proxy_service->ResetConfigService(base::WrapUnique(
453455
new net::ProxyConfigServiceFixed(config)));
454456
proxy_service->ForceReloadProxyConfig();
457+
if (callback)
458+
callback.Run();
455459
}
456460
}
457461

@@ -740,8 +744,10 @@ void BraveBrowserContext::SetExitType(ExitType exit_type) {
740744
}
741745
}
742746

743-
void BraveBrowserContext::SetTorNewIdentity(const GURL& origin) {
744-
const std::string host = origin.host();
747+
void BraveBrowserContext::SetTorNewIdentity(const GURL& url,
748+
const base::Closure& callback) {
749+
GURL site_url(content::SiteInstance::GetSiteForURL(this, url));
750+
const std::string host = site_url.host();
745751
base::FilePath partition_path = this->GetPath().Append(
746752
content::StoragePartitionImplMap::GetStoragePartitionPath(host, host));
747753
brightray::URLRequestContextGetter* url_request_context_getter;
@@ -752,7 +758,7 @@ void BraveBrowserContext::SetTorNewIdentity(const GURL& origin) {
752758
url_request_context_getter = (iter->second).get();
753759
else
754760
return;
755-
TorSetProxy(url_request_context_getter, partition_path);
761+
TorSetProxy(url_request_context_getter, partition_path, callback);
756762
}
757763

758764
scoped_refptr<base::SequencedTaskRunner>

brave/browser/brave_browser_context.h

+3-2
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ class BraveBrowserContext : public Profile {
141141

142142
bool IsIsolatedStorage() const { return isolated_storage_; }
143143

144-
void SetTorNewIdentity(const GURL& origin);
144+
void SetTorNewIdentity(const GURL& url, const base::Closure& callback);
145145

146146
private:
147147
typedef std::map<StoragePartitionDescriptor,
@@ -156,7 +156,8 @@ class BraveBrowserContext : public Profile {
156156

157157
void TorSetProxy(
158158
brightray::URLRequestContextGetter* url_request_context_getter,
159-
const base::FilePath partition_path);
159+
const base::FilePath partition_path,
160+
const base::Closure& callback);
160161

161162
scoped_refptr<user_prefs::PrefRegistrySyncable> pref_registry_;
162163
std::unique_ptr<sync_preferences::PrefServiceSyncable> user_prefs_;

0 commit comments

Comments
 (0)