Skip to content

Commit

Permalink
Fix unitest failure due to access null browser_process object
Browse files Browse the repository at this point in the history
Also, tor-specific code for tor component is moved to tor client
updater.
  • Loading branch information
simonhong committed Nov 5, 2019
1 parent aca4e5c commit 054fd5a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
13 changes: 3 additions & 10 deletions browser/extensions/brave_extension_management.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@

#include <memory>

#include "base/command_line.h"
#include "brave/browser/brave_browser_process_impl.h"
#include "brave/browser/tor/buildflags.h"
#include "brave/common/brave_switches.h"
#include "brave/common/extensions/extension_constants.h"
#include "brave/common/pref_names.h"
#include "brave/browser/extensions/brave_extension_provider.h"
Expand All @@ -23,7 +21,6 @@

#if BUILDFLAG(ENABLE_TOR)
#include "brave/browser/extensions/brave_tor_client_updater.h"
#include "brave/browser/tor/tor_profile_service.h"
#endif

namespace extensions {
Expand All @@ -45,19 +42,15 @@ BraveExtensionManagement::~BraveExtensionManagement() {

void BraveExtensionManagement::RegisterBraveExtensions() {
#if BUILDFLAG(ENABLE_TOR)
const base::CommandLine& command_line =
*base::CommandLine::ForCurrentProcess();
if (!tor::TorProfileService::IsTorDisabled() &&
!command_line.HasSwitch(switches::kDisableTorClientUpdaterExtension) &&
!profile_->AsTestingProfile()) {
if (!profile_->AsTestingProfile())
g_brave_browser_process->tor_client_updater()->Register();
}
#endif
}

void BraveExtensionManagement::CleanupBraveExtensions() {
#if BUILDFLAG(ENABLE_TOR)
g_brave_browser_process->tor_client_updater()->Cleanup();
if (!profile_->AsTestingProfile())
g_brave_browser_process->tor_client_updater()->Cleanup();
#endif
}

Expand Down
13 changes: 10 additions & 3 deletions browser/extensions/brave_tor_client_updater.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@
#include <memory>
#include <string>

#include "base/command_line.h"
#include "base/files/file_enumerator.h"
#include "base/files/file_path.h"
#include "base/files/file_util.h"
#include "base/task/post_task.h"
#include "base/task_runner.h"
#include "base/task_runner_util.h"
#include "brave/browser/tor/tor_profile_service.h"
#include "brave/common/brave_switches.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "third_party/re2/src/re2/re2.h"
Expand Down Expand Up @@ -119,12 +121,17 @@ BraveTorClientUpdater::~BraveTorClientUpdater() {
}

void BraveTorClientUpdater::Register() {
if (registered_)
const base::CommandLine& command_line =
*base::CommandLine::ForCurrentProcess();
if (tor::TorProfileService::IsTorDisabled() ||
command_line.HasSwitch(switches::kDisableTorClientUpdaterExtension) ||
registered_) {
return;
}

BraveComponent::Register(kTorClientComponentName,
g_tor_client_component_id_,
g_tor_client_component_base64_public_key_);
g_tor_client_component_id_,
g_tor_client_component_base64_public_key_);
registered_ = true;
}

Expand Down

0 comments on commit 054fd5a

Please sign in to comment.