diff --git a/browser/BUILD.gn b/browser/BUILD.gn index 8a3849d7f93..eb73ba8f970 100644 --- a/browser/BUILD.gn +++ b/browser/BUILD.gn @@ -4,6 +4,8 @@ source_set("browser_process") { sources = [ "autocomplete/brave_autocomplete_scheme_classifier.cc", "autocomplete/brave_autocomplete_scheme_classifier.h", + "brave_app_controller_mac.mm", + "brave_app_controller_mac.h", "brave_browser_main_extra_parts.cc", "brave_browser_main_extra_parts.h", "brave_browser_process_impl.cc", @@ -27,10 +29,10 @@ source_set("browser_process") { "importer/brave_profile_writer.h", "importer/chrome_profile_lock.cc", "importer/chrome_profile_lock.h", - "brave_app_controller_mac.mm", - "brave_app_controller_mac.h", "sparkle_glue_mac.mm", "sparkle_glue_mac.h", + "update_util.cc", + "update_util.h", ] deps = [ diff --git a/browser/brave_app_controller_mac.mm b/browser/brave_app_controller_mac.mm index f8f0dd5fd4d..97c0bf2a282 100644 --- a/browser/brave_app_controller_mac.mm +++ b/browser/brave_app_controller_mac.mm @@ -6,18 +6,12 @@ #include -#import "brave/browser/sparkle_glue_mac.h" -#include "base/command_line.h" #include "base/strings/sys_string_conversions.h" -#include "brave/common/brave_switches.h" +#import "brave/browser/sparkle_glue_mac.h" +#include "brave/browser/update_util.h" namespace { -BOOL UpdateEnabled() { - return base::CommandLine::ForCurrentProcess()->HasSwitch( - switches::kEnableBraveUpdateTest); -} - std::string GetDescriptionFromAppcastItem(id item) { return [SparkleGlue descriptionFromAppcastItem:item]; } @@ -32,7 +26,7 @@ std::string GetDescriptionFromAppcastItem(id item) { - (void)applicationWillFinishLaunching:(NSNotification*)notification { [super applicationWillFinishLaunching:notification]; - if (!UpdateEnabled()) + if (!brave::UpdateEnabled()) return; [self initializeBraveUpdater]; @@ -42,17 +36,18 @@ std::string GetDescriptionFromAppcastItem(id item) { if ([super validateUserInterfaceItem:item]) return YES; - return [item action] == @selector(updateBrave:) ? UpdateEnabled() : NO; + return [item action] == @selector(updateBrave:) ? brave::UpdateEnabled() + : NO; } - (IBAction)updateBrave:(id)sender { - DCHECK(UpdateEnabled()); + DCHECK(brave::UpdateEnabled()); [sparkle_glue_ checkForUpdates:sender]; } - (void)initializeBraveUpdater { - DCHECK(UpdateEnabled()); + DCHECK(brave::UpdateEnabled()); sparkle_glue_ = [SparkleGlue sharedSparkleGlue]; [sparkle_glue_ setDelegate:self]; diff --git a/browser/sparkle_glue_mac.h b/browser/sparkle_glue_mac.h index 558096a5a27..166951a7bd1 100644 --- a/browser/sparkle_glue_mac.h +++ b/browser/sparkle_glue_mac.h @@ -21,6 +21,7 @@ - (void)setDelegate:(id)delegate; - (void)checkForUpdates:(id)sender; +- (void)checkForUpdatesInBackground; @end // @interface SparkleGlue diff --git a/browser/sparkle_glue_mac.mm b/browser/sparkle_glue_mac.mm index 06da2a48c2b..8cc9906bd38 100644 --- a/browser/sparkle_glue_mac.mm +++ b/browser/sparkle_glue_mac.mm @@ -59,4 +59,8 @@ id GetSUUpdater() { [su_updater_ checkForUpdates:sender]; } +- (void)checkForUpdatesInBackground { + [su_updater_ checkForUpdatesInBackground]; +} + @end diff --git a/browser/update_util.cc b/browser/update_util.cc new file mode 100644 index 00000000000..7329dc354d6 --- /dev/null +++ b/browser/update_util.cc @@ -0,0 +1,18 @@ +/* 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 http://mozilla.org/MPL/2.0/. */ + +#include "brave/browser/update_util.h" + +#include "base/command_line.h" +#include "brave/common/brave_switches.h" + +namespace brave { + +bool UpdateEnabled() { + // TODO(simonhong): Remove this flag and enable update only in official build. + return base::CommandLine::ForCurrentProcess()->HasSwitch( + switches::kEnableBraveUpdateTest); +} + +} //namespace brave diff --git a/browser/update_util.h b/browser/update_util.h new file mode 100644 index 00000000000..66dadc942b9 --- /dev/null +++ b/browser/update_util.h @@ -0,0 +1,14 @@ +/* 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 http://mozilla.org/MPL/2.0/. */ + +#ifndef BRAVE_BROWSER_UPDATE_UTIL_H_ +#define BRAVE_BROWSER_UPDATE_UTIL_H_ + +namespace brave { + +bool UpdateEnabled(); + +} // namespace brave + +#endif // BRAVE_BROWSER_UPDATE_UTIL_MAC_H_ diff --git a/chromium_src/chrome/browser/ui/webui/help/version_updater_mac.h b/chromium_src/chrome/browser/ui/webui/help/version_updater_mac.h new file mode 100644 index 00000000000..b77592cbfbd --- /dev/null +++ b/chromium_src/chrome/browser/ui/webui/help/version_updater_mac.h @@ -0,0 +1,32 @@ +/* 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 http://mozilla.org/MPL/2.0/. */ + +#ifndef CHROME_BROWSER_UI_WEBUI_HELP_VERSION_UPDATER_MAC_H_ +#define CHROME_BROWSER_UI_WEBUI_HELP_VERSION_UPDATER_MAC_H_ + +#include "base/macros.h" +#include "chrome/browser/ui/webui/help/version_updater.h" + +// OS X implementation of version update functionality, used by the WebUI +// About/Help page. +class VersionUpdaterMac : public VersionUpdater { + public: + // VersionUpdater implementation. + void CheckForUpdate(const StatusCallback& status_callback, + const PromoteCallback& promote_callback) override; + void PromoteUpdater() const override; + + protected: + friend class VersionUpdater; + + // Clients must use VersionUpdater::Create(). + VersionUpdaterMac(); + ~VersionUpdaterMac() override; + + private: + DISALLOW_COPY_AND_ASSIGN(VersionUpdaterMac); +}; + +#endif // CHROME_BROWSER_UI_WEBUI_HELP_VERSION_UPDATER_MAC_H_ + diff --git a/chromium_src/chrome/browser/ui/webui/help/version_updater_mac.mm b/chromium_src/chrome/browser/ui/webui/help/version_updater_mac.mm new file mode 100644 index 00000000000..1a7b29757bc --- /dev/null +++ b/chromium_src/chrome/browser/ui/webui/help/version_updater_mac.mm @@ -0,0 +1,36 @@ +/* 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 http://mozilla.org/MPL/2.0/. */ + +#include "chrome/browser/ui/webui/help/version_updater_mac.h" + +#import "brave/browser/sparkle_glue_mac.h" +#include "brave/browser/update_util.h" + +VersionUpdater* VersionUpdater::Create( + content::WebContents* web_contents) { + return new VersionUpdaterMac; +} + +VersionUpdaterMac::VersionUpdaterMac() { +} + +VersionUpdaterMac::~VersionUpdaterMac() { +} + +void VersionUpdaterMac::CheckForUpdate( + const StatusCallback& status_callback, + const PromoteCallback& promote_callback) { + if (brave::UpdateEnabled()) { + [[SparkleGlue sharedSparkleGlue] checkForUpdatesInBackground]; + // TODO(simonhong): Update status from sparkle. + status_callback.Run(DISABLED, 0, std::string(), 0, base::string16()); + NOTIMPLEMENTED(); + } else { + status_callback.Run(DISABLED, 0, std::string(), 0, base::string16()); + } +} + +void VersionUpdaterMac::PromoteUpdater() const { + NOTIMPLEMENTED(); +}