Skip to content

Commit

Permalink
Fix clang tidy comments and format in runtime api.
Browse files Browse the repository at this point in the history
Removed unused includes, made default ctor/dtor.
Applied clang format to runtime api related file.

Change-Id: Ie31b418a9e939ce33d5bb1573b048ee16be8fd5a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4259797
Reviewed-by: Finnur Thorarinsson <finnur@chromium.org>
Commit-Queue: Sergii Bykov <sbykov@google.com>
Cr-Commit-Position: refs/heads/main@{#1107659}
  • Loading branch information
sbykov-g authored and Chromium LUCI CQ committed Feb 21, 2023
1 parent 23067a5 commit f28e526
Show file tree
Hide file tree
Showing 9 changed files with 89 additions and 79 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@
#include "chrome/browser/extensions/updater/extension_updater.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profiles_state.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_finder.h"
#include "chrome/browser/ui/browser_navigator.h"
#include "chrome/browser/ui/browser_navigator_params.h"
#include "chrome/browser/ui/browser_window.h"
#include "components/update_client/update_query_params.h"
#include "content/public/browser/notification_service.h"
#include "extensions/browser/extension_system.h"
Expand Down Expand Up @@ -104,7 +104,7 @@ BackoffPolicy::BackoffPolicy() {
};
}

BackoffPolicy::~BackoffPolicy() {}
BackoffPolicy::~BackoffPolicy() = default;

// static
const net::BackoffEntry::Policy* BackoffPolicy::Get() {
Expand All @@ -128,8 +128,7 @@ ChromeRuntimeAPIDelegate::ChromeRuntimeAPIDelegate(
extensions::ExtensionRegistry::Get(browser_context_));
}

ChromeRuntimeAPIDelegate::~ChromeRuntimeAPIDelegate() {
}
ChromeRuntimeAPIDelegate::~ChromeRuntimeAPIDelegate() = default;

// static
void ChromeRuntimeAPIDelegate::set_tick_clock_for_tests(
Expand Down Expand Up @@ -203,8 +202,7 @@ void ChromeRuntimeAPIDelegate::ReloadExtension(
service->AsExtensionServiceWeakPtr(), extension_id));
extensions::WarningSet warnings;
warnings.insert(
extensions::Warning::CreateReloadTooFrequentWarning(
extension_id));
extensions::Warning::CreateReloadTooFrequentWarning(extension_id));
base::SingleThreadTaskRunner::GetCurrentDefault()->PostTask(
FROM_HERE,
base::BindOnce(&extensions::WarningService::NotifyWarningsOnUI,
Expand Down Expand Up @@ -257,10 +255,12 @@ bool ChromeRuntimeAPIDelegate::CheckForUpdates(const std::string& extension_id,
void ChromeRuntimeAPIDelegate::OpenURL(const GURL& uninstall_url) {
Profile* profile = Profile::FromBrowserContext(browser_context_);
Browser* browser = chrome::FindLastActiveWithProfile(profile);
if (!browser)
if (!browser) {
browser = Browser::Create(Browser::CreateParams(profile, false));
if (!browser)
}
if (!browser) {
return;
}

NavigateParams params(browser, uninstall_url,
ui::PAGE_TRANSITION_CLIENT_REDIRECT);
Expand Down Expand Up @@ -360,8 +360,9 @@ void ChromeRuntimeAPIDelegate::OnExtensionInstalled(
content::BrowserContext* browser_context,
const Extension* extension,
bool is_update) {
if (!is_update)
if (!is_update) {
return;
}
auto info = update_check_info_.find(extension->id());
if (info != update_check_info_.end()) {
info->second.backoff->Reset();
Expand Down Expand Up @@ -397,8 +398,9 @@ void ChromeRuntimeAPIDelegate::CallUpdateCallbacks(
const std::string& extension_id,
const UpdateCheckResult& result) {
auto it = update_check_info_.find(extension_id);
if (it == update_check_info_.end())
if (it == update_check_info_.end()) {
return;
}
std::vector<UpdateCheckCallback> callbacks;
it->second.callbacks.swap(callbacks);
for (auto& callback : callbacks) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,16 @@
namespace base {
class TickClock;
class TimeTicks;
}
} // namespace base

namespace content {
class BrowserContext;
}
} // namespace content

namespace extensions {
class RuntimeAPI;
class UpdateObserver;
}
} // namespace extensions

class ChromeRuntimeAPIDelegate : public extensions::RuntimeAPIDelegate,
public extensions::ExtensionRegistryObserver {
Expand Down Expand Up @@ -78,7 +78,7 @@ class ChromeRuntimeAPIDelegate : public extensions::RuntimeAPIDelegate,
// Map to prevent extensions from getting stuck in reload loops. Maps
// extension id to the last time it was reloaded and the number of times
// it was reloaded with not enough time in between reloads.
std::map<std::string, std::pair<base::TimeTicks, int> > last_reload_time_;
std::map<std::string, std::pair<base::TimeTicks, int>> last_reload_time_;

// Information about update checks, keyed by extension id.
struct UpdateCheckInfo;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
#include "base/functional/callback.h"
#include "base/location.h"
#include "base/memory/raw_ptr.h"
#include "base/memory/ref_counted.h"
#include "base/run_loop.h"
#include "base/scoped_observation.h"
#include "base/task/single_thread_task_runner.h"
Expand Down Expand Up @@ -48,7 +47,7 @@ class TestEventRouter : public EventRouter {
TestEventRouter(const TestEventRouter&) = delete;
TestEventRouter& operator=(const TestEventRouter&) = delete;

~TestEventRouter() override {}
~TestEventRouter() override = default;

// An entry in our fake event registry.
using Entry = std::pair<std::string, std::string>;
Expand Down Expand Up @@ -77,7 +76,7 @@ std::unique_ptr<KeyedService> TestEventRouterFactoryFunction(
// either no update was found, or one was (and it was downloaded).
class DownloaderTestDelegate : public ExtensionDownloaderTestDelegate {
public:
DownloaderTestDelegate() {}
DownloaderTestDelegate() = default;

DownloaderTestDelegate(const DownloaderTestDelegate&) = delete;
DownloaderTestDelegate& operator=(const DownloaderTestDelegate&) = delete;
Expand All @@ -86,17 +85,19 @@ class DownloaderTestDelegate : public ExtensionDownloaderTestDelegate {
// is available.
void AddNoUpdateResponse(const std::string& id) {
no_updates_.insert(id);
if (updates_.find(id) != updates_.end())
if (updates_.find(id) != updates_.end()) {
updates_.erase(id);
}
}

// On the next update check for extension |id|, pretend that an update to
// version |version| has been downloaded to |path|.
void AddUpdateResponse(const std::string& id,
const base::FilePath& path,
const std::string& version) {
if (no_updates_.find(id) != no_updates_.end())
if (no_updates_.find(id) != no_updates_.end()) {
no_updates_.erase(id);
}
DownloadFinishedArgs args;
args.path = path;
args.version = base::Version(version);
Expand All @@ -107,8 +108,9 @@ class DownloaderTestDelegate : public ExtensionDownloaderTestDelegate {
ExtensionDownloaderDelegate* delegate,
std::vector<ExtensionDownloaderTask> tasks) override {
std::set<int> request_ids;
for (const ExtensionDownloaderTask& task : tasks)
for (const ExtensionDownloaderTask& task : tasks) {
request_ids.insert(task.request_id);
}
// Instead of immediately firing callbacks to the delegate in matching
// cases below, we instead post a task since the delegate typically isn't
// expecting a synchronous reply (the real code has to go do at least one
Expand Down Expand Up @@ -166,7 +168,7 @@ class DownloaderTestDelegate : public ExtensionDownloaderTestDelegate {
// Helper to let test code wait for and return an update check result.
class UpdateCheckResultCatcher {
public:
UpdateCheckResultCatcher() {}
UpdateCheckResultCatcher() = default;

UpdateCheckResultCatcher(const UpdateCheckResultCatcher&) = delete;
UpdateCheckResultCatcher& operator=(const UpdateCheckResultCatcher&) = delete;
Expand All @@ -175,8 +177,9 @@ class UpdateCheckResultCatcher {
EXPECT_EQ(nullptr, result_.get());
result_ = std::make_unique<RuntimeAPIDelegate::UpdateCheckResult>(
result.status, result.version);
if (run_loop_)
if (run_loop_) {
run_loop_->Quit();
}
}

std::unique_ptr<RuntimeAPIDelegate::UpdateCheckResult> WaitForResult() {
Expand All @@ -194,7 +197,7 @@ class UpdateCheckResultCatcher {

class ChromeRuntimeAPIDelegateTest : public ExtensionServiceTestWithInstall {
public:
ChromeRuntimeAPIDelegateTest() {}
ChromeRuntimeAPIDelegateTest() = default;

ChromeRuntimeAPIDelegateTest(const ChromeRuntimeAPIDelegateTest&) = delete;
ChromeRuntimeAPIDelegateTest& operator=(const ChromeRuntimeAPIDelegateTest&) =
Expand Down Expand Up @@ -383,7 +386,7 @@ class ExtensionLoadWaiter : public ExtensionRegistryObserver {

class ChromeRuntimeAPIDelegateReloadTest : public ChromeRuntimeAPIDelegateTest {
public:
ChromeRuntimeAPIDelegateReloadTest() {}
ChromeRuntimeAPIDelegateReloadTest() = default;

ChromeRuntimeAPIDelegateReloadTest(
const ChromeRuntimeAPIDelegateReloadTest&) = delete;
Expand Down
5 changes: 3 additions & 2 deletions chrome/browser/extensions/api/runtime/runtime_apitest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ std::string GetActiveUrl(Browser* browser) {

class RuntimeAPIUpdateTest : public ExtensionApiTest {
public:
RuntimeAPIUpdateTest() {}
RuntimeAPIUpdateTest() = default;

RuntimeAPIUpdateTest(const RuntimeAPIUpdateTest&) = delete;
RuntimeAPIUpdateTest& operator=(const RuntimeAPIUpdateTest&) = delete;
Expand Down Expand Up @@ -136,8 +136,9 @@ class RuntimeAPIUpdateTest : public ExtensionApiTest {
ExtensionHost* background_host =
ProcessManager::Get(browser()->profile())
->GetBackgroundHostForExtension(extension_id);
if (!background_host)
if (!background_host) {
return false;
}
content::CrashTab(background_host->host_contents());
return true;
}
Expand Down
19 changes: 9 additions & 10 deletions extensions/browser/api/runtime/restart_after_delay_api_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@

#include <utility>

#include "base/functional/callback_helpers.h"
#include "base/memory/ptr_util.h"
#include "base/memory/raw_ptr.h"
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_refptr.h"
#include "base/run_loop.h"
#include "components/pref_registry/pref_registry_syncable.h"
Expand All @@ -18,7 +16,6 @@
#include "extensions/browser/test_extensions_browser_client.h"
#include "extensions/browser/test_runtime_api_delegate.h"
#include "extensions/common/extension_builder.h"
#include "extensions/common/manifest.h"

namespace extensions {

Expand All @@ -27,18 +24,19 @@ namespace {
// A RuntimeAPIDelegate that simulates a successful restart request every time.
class DelayedRestartTestApiDelegate : public TestRuntimeAPIDelegate {
public:
DelayedRestartTestApiDelegate() {}
DelayedRestartTestApiDelegate() = default;

DelayedRestartTestApiDelegate(const DelayedRestartTestApiDelegate&) = delete;
DelayedRestartTestApiDelegate& operator=(
const DelayedRestartTestApiDelegate&) = delete;

~DelayedRestartTestApiDelegate() override {}
~DelayedRestartTestApiDelegate() override = default;

// TestRuntimeAPIDelegate:
bool RestartDevice(std::string* error_message) override {
if (quit_closure_)
if (quit_closure_) {
std::move(quit_closure_).Run();
}

*error_message = "Success.";
restart_done_ = true;
Expand All @@ -65,15 +63,16 @@ class DelayedRestartTestApiDelegate : public TestRuntimeAPIDelegate {
class DelayedRestartExtensionsBrowserClient
: public TestExtensionsBrowserClient {
public:
DelayedRestartExtensionsBrowserClient(content::BrowserContext* context)
explicit DelayedRestartExtensionsBrowserClient(
content::BrowserContext* context)
: TestExtensionsBrowserClient(context) {}

DelayedRestartExtensionsBrowserClient(
const DelayedRestartExtensionsBrowserClient&) = delete;
DelayedRestartExtensionsBrowserClient& operator=(
const DelayedRestartExtensionsBrowserClient&) = delete;

~DelayedRestartExtensionsBrowserClient() override {}
~DelayedRestartExtensionsBrowserClient() override = default;

// TestExtensionsBrowserClient:
PrefService* GetPrefServiceForContext(
Expand Down Expand Up @@ -107,12 +106,12 @@ class DelayedRestartExtensionsBrowserClient

class RestartAfterDelayApiTest : public ApiUnitTest {
public:
RestartAfterDelayApiTest() {}
RestartAfterDelayApiTest() = default;

RestartAfterDelayApiTest(const RestartAfterDelayApiTest&) = delete;
RestartAfterDelayApiTest& operator=(const RestartAfterDelayApiTest&) = delete;

~RestartAfterDelayApiTest() override {}
~RestartAfterDelayApiTest() override = default;

void SetUp() override {
// Use our ExtensionsBrowserClient that returns our RuntimeAPIDelegate.
Expand Down

0 comments on commit f28e526

Please sign in to comment.