Skip to content

Commit

Permalink
[Extensions] Add the keepalive data to the extensions-internals page.
Browse files Browse the repository at this point in the history
This CL integrates the new enhanced keepalive data into the JSON output for the chrome://extensions-internals page.

Bug: 695711
Change-Id: I7cc3b09dbccd2fef9379f2cb68939f4e029136cf
Reviewed-on: https://chromium-review.googlesource.com/1196169
Commit-Queue: David Bertoni <dbertoni@chromium.org>
Reviewed-by: Devlin <rdevlin.cronin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#587763}
  • Loading branch information
David Bertoni authored and Commit Bot committed Aug 30, 2018
1 parent 5029997 commit 2cb53ba
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 2 deletions.
19 changes: 17 additions & 2 deletions chrome/browser/ui/webui/extensions/extensions_internals_source.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "chrome/common/webui_url_constants.h"
#include "components/prefs/pref_service.h"
#include "content/public/browser/browser_thread.h"
#include "extensions/browser/activity.h"
#include "extensions/browser/extension_registry.h"
#include "extensions/browser/process_manager.h"

Expand Down Expand Up @@ -78,8 +79,22 @@ const char* LocationToString(extensions::Manifest::Location loc) {

base::Value FormatKeepaliveData(extensions::ProcessManager* process_manager,
const extensions::Extension* extension) {
// TODO(dbertoni): Expand this when enhanced keepalive data is implemented.
return base::Value(process_manager->GetLazyKeepaliveCount(extension));
base::Value keepalive_data(base::Value::Type::DICTIONARY);
keepalive_data.SetKey(
"count", base::Value(process_manager->GetLazyKeepaliveCount(extension)));
const extensions::ProcessManager::ActivitiesMultiset activities =
process_manager->GetLazyKeepaliveActivities(extension);
base::Value activities_data(base::Value::Type::LIST);
activities_data.GetList().reserve(activities.size());
for (const auto& activity : activities) {
base::Value activities_entry(base::Value::Type::DICTIONARY);
activities_entry.SetKey(
"type", base::Value(extensions::Activity::ToString(activity.first)));
activities_entry.SetKey("extra_data", base::Value(activity.second));
activities_data.GetList().push_back(std::move(activities_entry));
}
keepalive_data.SetKey("activites", std::move(activities_data));
return keepalive_data;
}

} // namespace
Expand Down
31 changes: 31 additions & 0 deletions extensions/browser/activity.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

#include "extensions/browser/activity.h"

#include "base/logging.h"

namespace extensions {

const char Activity::kCancelSuspend[] = "cancel-suspend";
Expand All @@ -12,4 +14,33 @@ const char Activity::kIPC[] = "IPC";
const char Activity::kPictureInPicture[] = "picture-in-picture";
const char Activity::kRenderFrame[] = "render-frame";

const char* Activity::ToString(Type type) {
switch (type) {
case API_FUNCTION:
return "API_FUNCTION";
case DEV_TOOLS:
return "DEV_TOOLS";
case EVENT:
return "EVENT";
case LIFECYCLE_MANAGEMENT:
return "LIFECYCLE_MANAGEMENT";
case MEDIA:
return "MEDIA";
case MESSAGE_PORT:
return "MESSAGE_PORT";
case MODAL_DIALOG:
return "MODAL_DIALOG";
case MOJO:
return "MOJO";
case NETWORK:
return "NETWORK";
case PEPPER_API:
return "PEPPER_API";
case PROCESS_MANAGER:
return "PROCESS_MANAGER";
}
NOTREACHED();
return "";
}

} // namespace extensions
2 changes: 2 additions & 0 deletions extensions/browser/activity.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ struct Activity {
PROCESS_MANAGER,
};

static const char* ToString(Type type);

static const char kCancelSuspend[];
static const char kCreatePage[];
static const char kIPC[];
Expand Down

0 comments on commit 2cb53ba

Please sign in to comment.