Pass partition name instead of path to BrowserContext
This commit is contained in:
parent
82b9ced3e0
commit
58fb166b0b
2 changed files with 19 additions and 6 deletions
|
@ -16,9 +16,11 @@
|
||||||
#include "base/prefs/pref_registry_simple.h"
|
#include "base/prefs/pref_registry_simple.h"
|
||||||
#include "base/prefs/pref_service.h"
|
#include "base/prefs/pref_service.h"
|
||||||
#include "base/prefs/pref_service_factory.h"
|
#include "base/prefs/pref_service_factory.h"
|
||||||
|
#include "base/strings/string_util.h"
|
||||||
#include "content/public/browser/browser_thread.h"
|
#include "content/public/browser/browser_thread.h"
|
||||||
#include "content/public/browser/resource_context.h"
|
#include "content/public/browser/resource_context.h"
|
||||||
#include "content/public/browser/storage_partition.h"
|
#include "content/public/browser/storage_partition.h"
|
||||||
|
#include "net/base/escape.h"
|
||||||
#include "net/ssl/client_cert_store.h"
|
#include "net/ssl/client_cert_store.h"
|
||||||
|
|
||||||
#if defined(USE_NSS_CERTS)
|
#if defined(USE_NSS_CERTS)
|
||||||
|
@ -33,6 +35,15 @@ using content::BrowserThread;
|
||||||
|
|
||||||
namespace brightray {
|
namespace brightray {
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
|
||||||
|
// Convert string to lower case and escape it.
|
||||||
|
std::string MakePartitionName(const std::string& input) {
|
||||||
|
return net::EscapePath(base::StringToLowerASCII(input));
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace
|
||||||
|
|
||||||
class BrowserContext::ResourceContext : public content::ResourceContext {
|
class BrowserContext::ResourceContext : public content::ResourceContext {
|
||||||
public:
|
public:
|
||||||
ResourceContext() : getter_(nullptr) {}
|
ResourceContext() : getter_(nullptr) {}
|
||||||
|
@ -66,19 +77,22 @@ class BrowserContext::ResourceContext : public content::ResourceContext {
|
||||||
URLRequestContextGetter* getter_;
|
URLRequestContextGetter* getter_;
|
||||||
};
|
};
|
||||||
|
|
||||||
BrowserContext::BrowserContext() : resource_context_(new ResourceContext) {
|
BrowserContext::BrowserContext()
|
||||||
|
: in_memory_(false),
|
||||||
|
resource_context_(new ResourceContext) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void BrowserContext::Initialize(const std::string& partition_path, bool in_memory) {
|
void BrowserContext::Initialize(const std::string& partition, bool in_memory) {
|
||||||
if (!PathService::Get(DIR_USER_DATA, &path_)) {
|
if (!PathService::Get(DIR_USER_DATA, &path_)) {
|
||||||
PathService::Get(DIR_APP_DATA, &path_);
|
PathService::Get(DIR_APP_DATA, &path_);
|
||||||
path_ = path_.Append(base::FilePath::FromUTF8Unsafe(GetApplicationName()));
|
path_ = path_.Append(base::FilePath::FromUTF8Unsafe(GetApplicationName()));
|
||||||
PathService::Override(DIR_USER_DATA, path_);
|
PathService::Override(DIR_USER_DATA, path_);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!partition_path.empty())
|
|
||||||
path_ = path_.Append(base::FilePath::FromUTF8Unsafe(partition_path));
|
|
||||||
in_memory_ = in_memory;
|
in_memory_ = in_memory;
|
||||||
|
if (!in_memory && !partition.empty())
|
||||||
|
path_ = path_.Append(FILE_PATH_LITERAL("Partitions"))
|
||||||
|
.Append(base::FilePath::FromUTF8Unsafe(MakePartitionName(partition)));
|
||||||
|
|
||||||
auto prefs_path = GetPath().Append(FILE_PATH_LITERAL("Preferences"));
|
auto prefs_path = GetPath().Append(FILE_PATH_LITERAL("Preferences"));
|
||||||
base::PrefServiceFactory prefs_factory;
|
base::PrefServiceFactory prefs_factory;
|
||||||
|
|
|
@ -23,8 +23,7 @@ class BrowserContext : public content::BrowserContext,
|
||||||
BrowserContext();
|
BrowserContext();
|
||||||
~BrowserContext();
|
~BrowserContext();
|
||||||
|
|
||||||
virtual void Initialize(const std::string& partition_path,
|
void Initialize(const std::string& partition, bool in_memory = false);
|
||||||
bool in_memory = false);
|
|
||||||
|
|
||||||
// content::BrowserContext:
|
// content::BrowserContext:
|
||||||
scoped_ptr<content::ZoomLevelDelegate> CreateZoomLevelDelegate(
|
scoped_ptr<content::ZoomLevelDelegate> CreateZoomLevelDelegate(
|
||||||
|
|
Loading…
Reference in a new issue