Skip to content

Commit

Permalink
For Tor profile, return early for profile created and destroyed notif…
Browse files Browse the repository at this point in the history
…ications in

ExtensionAppShimHandler::Observe like off-the-record profiles since we're sharing
AppLifetimeMonitor with its parent profile.

Without this commit, we will hit DCHECK because it will try to add
ExtensionAppShimHandler as the observer of AppLifetimeMonitor multiple times.
  • Loading branch information
yrliou committed Aug 31, 2019
1 parent 5a37c74 commit bb3440b
Show file tree
Hide file tree
Showing 5 changed files with 98 additions and 0 deletions.
6 changes: 6 additions & 0 deletions browser/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,12 @@ source_set("browser_process") {
"//google_update",
]
}

if (is_mac) {
deps += [
"//brave/browser/apps/app_shim",
]
}
}

buildflag_header("sparkle_buildflags") {
Expand Down
9 changes: 9 additions & 0 deletions browser/apps/app_shim/BUILD.gn
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
source_set("app_shim") {
sources = [
"brave_extension_app_shim_handler_mac.cc",
"brave_extension_app_shim_handler_mac.h",
]
deps = [
"//content/public/browser",
]
}
43 changes: 43 additions & 0 deletions browser/apps/app_shim/brave_extension_app_shim_handler_mac.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/* Copyright (c) 2019 The Brave Authors. All rights reserved.
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at https://mozilla.org/MPL/2.0/. */

#include "brave/browser/apps/app_shim/brave_extension_app_shim_handler_mac.h"

#include "brave/browser/profiles/profile_util.h"
#include "chrome/browser/chrome_notification_types.h"
#include "content/public/browser/notification_source.h"

namespace apps {

// Same as off-the-record profiles, we return early for Tor profile for
// NOTIFICATION_PROFILE_CREATED and NOTIFICATION_PROFILE_DESTROYED cases
// since ExtensionAppShimHandler is observing AppLifetimeMonitorFactory through
// parent profiles.
void BraveExtensionAppShimHandler::Observe(
int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) {
switch (type) {
case chrome::NOTIFICATION_PROFILE_CREATED: {
Profile* profile = content::Source<Profile>(source).ptr();
if (brave::IsTorProfile(profile))
return;
break;
}
case chrome::NOTIFICATION_PROFILE_DESTROYED: {
Profile* profile = content::Source<Profile>(source).ptr();
if (brave::IsTorProfile(profile))
return;
break;
}
default: {
break;
}
}

return ExtensionAppShimHandler::Observe(type, source, details);
}

} // namespace apps
30 changes: 30 additions & 0 deletions browser/apps/app_shim/brave_extension_app_shim_handler_mac.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/* Copyright (c) 2019 The Brave Authors. All rights reserved.
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at https://mozilla.org/MPL/2.0/. */

#ifndef BRAVE_BROWSER_APPS_APP_SHIM_BRAVE_EXTENSION_APP_SHIM_HANDLER_MAC_H_
#define BRAVE_BROWSER_APPS_APP_SHIM_BRAVE_EXTENSION_APP_SHIM_HANDLER_MAC_H_

#include "chrome/browser/apps/app_shim/extension_app_shim_handler_mac.h"

#include "content/public/browser/notification_observer.h"

namespace apps {

class BraveExtensionAppShimHandler : public ExtensionAppShimHandler {
public:
BraveExtensionAppShimHandler() = default;
~BraveExtensionAppShimHandler() override = default;

// content::NotificationObserver overrides:
void Observe(int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) override;

DISALLOW_COPY_AND_ASSIGN(BraveExtensionAppShimHandler);
};

} // namespace apps

#endif // BRAVE_BROWSER_APPS_APP_SHIM_BRAVE_EXTENSION_APP_SHIM_HANDLER_MAC_H_
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/* Copyright (c) 2019 The Brave Authors. All rights reserved.
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at https://mozilla.org/MPL/2.0/. */

#include "brave/browser/apps/app_shim/brave_extension_app_shim_handler_mac.h"

#define ExtensionAppShimHandler BraveExtensionAppShimHandler
#include "../../../../../../chrome/browser/apps/app_shim/app_shim_host_manager_mac.mm"
#undef ExtensionAppShimHandler

0 comments on commit bb3440b

Please sign in to comment.