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

Commit

Permalink
Fix map index key by SiteInstance and add callback
Browse files Browse the repository at this point in the history
  • Loading branch information
darkdh committed Feb 6, 2018
1 parent 1af566a commit c3d6769
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 10 deletions.
5 changes: 3 additions & 2 deletions atom/browser/api/atom_api_session.cc
Original file line number Diff line number Diff line change
Expand Up @@ -602,12 +602,13 @@ bool Session::IsOffTheRecord() const {
return false;
}

void Session::SetTorNewIdentity(const GURL& origin) const {
void Session::SetTorNewIdentity(const GURL& url,
const base::Closure& callback) const {
brave::BraveBrowserContext* brave_browser_context =
brave::BraveBrowserContext::FromBrowserContext(profile_);
if (!brave_browser_context->IsIsolatedStorage())
return;
brave_browser_context->SetTorNewIdentity(origin);
brave_browser_context->SetTorNewIdentity(url, callback);
}

// static
Expand Down
3 changes: 2 additions & 1 deletion atom/browser/api/atom_api_session.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ class Session: public mate::TrackableObject<Session>,
v8::Local<v8::Value> Extensions(v8::Isolate* isolate);
bool Equal(Session* session) const;
bool IsOffTheRecord() const;
void SetTorNewIdentity(const GURL& origin) const;
void SetTorNewIdentity(const GURL& url,
const base::Closure& callback) const;

protected:
Session(v8::Isolate* isolate, Profile* browser_context);
Expand Down
16 changes: 11 additions & 5 deletions brave/browser/brave_browser_context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
#include "content/public/browser/notification_source.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/dom_storage_context.h"
#include "content/public/browser/site_instance.h"
#include "content/public/browser/storage_partition.h"
#include "crypto/random.h"
#include "extensions/browser/pref_names.h"
Expand Down Expand Up @@ -345,7 +346,8 @@ BraveBrowserContext::CreateRequestContextForStoragePartition(
std::move(request_interceptors));
StoragePartitionDescriptor descriptor(partition_path, in_memory);
url_request_context_getter_map_[descriptor] = url_request_context_getter;
TorSetProxy(url_request_context_getter, partition_path);
TorSetProxy(url_request_context_getter, partition_path,
base::Bind(&base::DoNothing));
return url_request_context_getter;
} else {
return nullptr;
Expand Down Expand Up @@ -429,7 +431,7 @@ void BraveBrowserContext::UpdateDefaultZoomLevel() {

void BraveBrowserContext::TorSetProxy(
brightray::URLRequestContextGetter* url_request_context_getter,
const base::FilePath partition_path) {
const base::FilePath partition_path, const base::Closure& callback) {
if (!url_request_context_getter || !isolated_storage_)
return;
if (!tor_proxy_.empty() && GURL(tor_proxy_).is_valid()) {
Expand All @@ -452,6 +454,8 @@ void BraveBrowserContext::TorSetProxy(
proxy_service->ResetConfigService(base::WrapUnique(
new net::ProxyConfigServiceFixed(config)));
proxy_service->ForceReloadProxyConfig();
if (callback)
callback.Run();
}
}

Expand Down Expand Up @@ -740,8 +744,10 @@ void BraveBrowserContext::SetExitType(ExitType exit_type) {
}
}

void BraveBrowserContext::SetTorNewIdentity(const GURL& origin) {
const std::string host = origin.host();
void BraveBrowserContext::SetTorNewIdentity(const GURL& url,
const base::Closure& callback) {
GURL site_url(content::SiteInstance::GetSiteForURL(this, url));
const std::string host = site_url.host();
base::FilePath partition_path = this->GetPath().Append(
content::StoragePartitionImplMap::GetStoragePartitionPath(host, host));
brightray::URLRequestContextGetter* url_request_context_getter;
Expand All @@ -752,7 +758,7 @@ void BraveBrowserContext::SetTorNewIdentity(const GURL& origin) {
url_request_context_getter = (iter->second).get();
else
return;
TorSetProxy(url_request_context_getter, partition_path);
TorSetProxy(url_request_context_getter, partition_path, callback);
}

scoped_refptr<base::SequencedTaskRunner>
Expand Down
5 changes: 3 additions & 2 deletions brave/browser/brave_browser_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ class BraveBrowserContext : public Profile {

bool IsIsolatedStorage() const { return isolated_storage_; }

void SetTorNewIdentity(const GURL& origin);
void SetTorNewIdentity(const GURL& url, const base::Closure& callback);

private:
typedef std::map<StoragePartitionDescriptor,
Expand All @@ -156,7 +156,8 @@ class BraveBrowserContext : public Profile {

void TorSetProxy(
brightray::URLRequestContextGetter* url_request_context_getter,
const base::FilePath partition_path);
const base::FilePath partition_path,
const base::Closure& callback);

scoped_refptr<user_prefs::PrefRegistrySyncable> pref_registry_;
std::unique_ptr<sync_preferences::PrefServiceSyncable> user_prefs_;
Expand Down

0 comments on commit c3d6769

Please sign in to comment.