Skip to content

Commit

Permalink
chore: address review feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
deepak1556 committed Mar 10, 2022
1 parent 13a0ee4 commit a57159b
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 8 deletions.
9 changes: 4 additions & 5 deletions docs/api/session.md
Expand Up @@ -870,16 +870,15 @@ registered.

#### `ses.setCodeCachePath(path)`

* `path` String - The Code cache location.
* `path` String - Absolute path to store the v8 generated JS code cache from the renderer.

Sets code cache directory. By default, the directory will be `Code Cache` under the
Sets the directory to store the generated JS [code cache](https://v8.dev/blog/code-caching-for-devs) for this session. The directory is not required to be created by the user before this call, the runtime will create if it does not exit otherwise will use the existing directory. If directory cannot be created, then code cache will not be used and all operations related to code cache will fail silently inside the runtime. By default, the directory will be `Code Cache` under the
respective user data folder.

#### `ses.clearCodeCaches()`
#### `ses.clearCodeCaches(options)`

* `options` Object
* `urls` String[] (optional) - An array of url corresponding to the resource that needs to
be removed. If the list is empty then all entries in the cache will be removed.
* `urls` String[] (optional) - An array of url corresponding to the resource whose generated code cache needs to be removed. If the list is empty then all entries in the cache directory will be removed.

Returns `Promise<void>` - resolves when the code cache clear operation is complete.

Expand Down
10 changes: 8 additions & 2 deletions shell/browser/api/electron_api_session.cc
Expand Up @@ -977,10 +977,16 @@ v8::Local<v8::Value> Session::GetPath(v8::Isolate* isolate) {
return gin::ConvertToV8(isolate, browser_context_->GetPath());
}

void Session::SetCodeCachePath(const base::FilePath& code_cache_path) {
void Session::SetCodeCachePath(gin::Arguments* args) {
base::FilePath code_cache_path;
auto* storage_partition = browser_context_->GetDefaultStoragePartition();
auto* code_cache_context = storage_partition->GetGeneratedCodeCacheContext();
if (code_cache_context && !code_cache_path.empty()) {
if (code_cache_context) {
if (!args->GetNext(&code_cache_path) || !code_cache_path.IsAbsolute()) {
args->ThrowTypeError(
"Absolute path must be provided to store code cache.");
return;
}
code_cache_context->Initialize(
code_cache_path, 0 /* allows disk_cache to choose the size */);
}
Expand Down
2 changes: 1 addition & 1 deletion shell/browser/api/electron_api_session.h
Expand Up @@ -127,7 +127,7 @@ class Session : public gin::Wrappable<Session>,
void Preconnect(const gin_helper::Dictionary& options, gin::Arguments* args);
v8::Local<v8::Promise> CloseAllConnections();
v8::Local<v8::Value> GetPath(v8::Isolate* isolate);
void SetCodeCachePath(const base::FilePath& code_cache_path);
void SetCodeCachePath(gin::Arguments* args);
v8::Local<v8::Promise> ClearCodeCaches(const gin_helper::Dictionary& options);
#if BUILDFLAG(ENABLE_BUILTIN_SPELLCHECKER)
base::Value GetSpellCheckerLanguages();
Expand Down
14 changes: 14 additions & 0 deletions spec-main/api-session-spec.ts
Expand Up @@ -1121,6 +1121,20 @@ describe('session module', () => {
});
});

describe('session.setCodeCachePath()', () => {
it('throws when relative or empty path is provided', () => {
expect(() => {
session.defaultSession.setCodeCachePath('../fixtures');
}).to.throw('Absolute path must be provided to store code cache.');
expect(() => {
session.defaultSession.setCodeCachePath('');
}).to.throw('Absolute path must be provided to store code cache.');
expect(() => {
session.defaultSession.setCodeCachePath(path.join(app.getPath('userData'), 'test-code-cache'));
}).to.not.throw();
});
});

describe('ses.setSSLConfig()', () => {
it('can disable cipher suites', async () => {
const ses = session.fromPartition('' + Math.random());
Expand Down

0 comments on commit a57159b

Please sign in to comment.