Skip to content

Commit

Permalink
Store the disk cache in an app-specific location
Browse files Browse the repository at this point in the history
We deduce the name of the application from the CFBundleName of the .app bundle
and use a path based on that. Similar logic should be implementable for other
platforms.

Fixes #3.
  • Loading branch information
aroben committed Mar 13, 2013
1 parent 65dd011 commit e1b5e5e
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 9 deletions.
3 changes: 3 additions & 0 deletions brightray/brightray.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
'target_name': 'brightray',
'type': 'static_library',
'include_dirs': [
'.',
'<(libchromiumcontent_include_dir)',
],
'direct_dependent_settings': {
Expand All @@ -28,6 +29,8 @@
'browser/network_delegate.h',
'browser/url_request_context_getter.cc',
'browser/url_request_context_getter.h',
'common/application_name.h',
'common/application_name_mac.mm',
'common/main_delegate.cc',
'common/main_delegate.h',
'common/main_delegate_mac.mm',
Expand Down
5 changes: 3 additions & 2 deletions brightray/browser/browser_context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

#include "browser_context.h"

#include "common/application_name.h"

#include "base/files/file_path.h"
#include "base/path_service.h"
#include "content/public/browser/browser_thread.h"
Expand Down Expand Up @@ -53,10 +55,9 @@ net::URLRequestContextGetter* BrowserContext::CreateRequestContext(content::Prot
}

base::FilePath BrowserContext::GetPath() {
// FIXME: This should be an application-specific path.
base::FilePath path;
CHECK(PathService::Get(base::DIR_APP_DATA, &path));
return path.Append("Brightray");
return path.Append(GetApplicationName());
}

bool BrowserContext::IsOffTheRecord() const {
Expand Down
12 changes: 12 additions & 0 deletions brightray/common/application_name.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#ifndef BRIGHTRAY_COMMON_APPLICATION_NAME_H_
#define BRIGHTRAY_COMMON_APPLICATION_NAME_H_

#include <string>

namespace brightray {

std::string GetApplicationName();

}

#endif
12 changes: 12 additions & 0 deletions brightray/common/application_name_mac.mm
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#import "common/application_name.h"

#import "base/mac/bundle_locations.h"
#import "base/mac/foundation_util.h"

namespace brightray {

std::string GetApplicationName() {
return [[base::mac::OuterBundle().infoDictionary objectForKey:base::mac::CFToNSCast(kCFBundleNameKey)] UTF8String];
}

}
11 changes: 4 additions & 7 deletions brightray/common/main_delegate_mac.mm
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

#import "main_delegate.h"

#include "common/application_name.h"
#include "base/mac/bundle_locations.h"
#include "base/mac/foundation_util.h"
#include "base/path_service.h"
Expand Down Expand Up @@ -35,23 +36,19 @@
return path.Append("Frameworks");
}

std::string OuterBundleName() {
return [[base::mac::OuterBundle().infoDictionary objectForKey:base::mac::CFToNSCast(kCFBundleNameKey)] UTF8String];
}

}

void MainDelegate::OverrideFrameworkBundlePath() {
base::FilePath helper_path = GetFrameworksPath().Append(OuterBundleName() + ".framework");
base::FilePath helper_path = GetFrameworksPath().Append(GetApplicationName() + ".framework");

base::mac::SetOverrideFrameworkBundlePath(helper_path);
}

void MainDelegate::OverrideChildProcessPath() {
base::FilePath helper_path = GetFrameworksPath().Append(OuterBundleName() + " Helper.app")
base::FilePath helper_path = GetFrameworksPath().Append(GetApplicationName() + " Helper.app")
.Append("Contents")
.Append("MacOS")
.Append(OuterBundleName() + " Helper");
.Append(GetApplicationName() + " Helper");

PathService::Override(content::CHILD_PROCESS_EXE, helper_path);
}
Expand Down

0 comments on commit e1b5e5e

Please sign in to comment.