This source file includes following definitions.
- RegisterMessages
- GetExtensionStatusesAsDictionary
- GetExtensionStatuses
#include "chrome/browser/ui/webui/sync_file_system_internals/extension_statuses_handler.h"
#include <map>
#include "base/bind.h"
#include "base/bind_helpers.h"
#include "base/values.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/sync_file_system/sync_file_system_service.h"
#include "chrome/browser/sync_file_system/sync_file_system_service_factory.h"
#include "content/public/browser/web_ui.h"
#include "content/public/browser/web_ui_data_source.h"
#include "extensions/browser/extension_system.h"
#include "extensions/common/extension.h"
#include "grit/sync_file_system_internals_resources.h"
using sync_file_system::SyncFileSystemServiceFactory;
using sync_file_system::SyncServiceState;
namespace syncfs_internals {
ExtensionStatusesHandler::ExtensionStatusesHandler(Profile* profile)
: profile_(profile) {}
ExtensionStatusesHandler::~ExtensionStatusesHandler() {}
void ExtensionStatusesHandler::RegisterMessages() {
web_ui()->RegisterMessageCallback(
"getExtensionStatuses",
base::Bind(&ExtensionStatusesHandler::GetExtensionStatuses,
base::Unretained(this)));
}
void ExtensionStatusesHandler::GetExtensionStatusesAsDictionary(
Profile* profile,
base::ListValue* values) {
DCHECK(profile);
DCHECK(values);
sync_file_system::SyncFileSystemService* sync_service =
SyncFileSystemServiceFactory::GetForProfile(profile);
ExtensionService* extension_service =
extensions::ExtensionSystem::Get(profile)->extension_service();
if (!sync_service || !extension_service)
return;
std::map<GURL, std::string> status_map;
sync_service->GetExtensionStatusMap(&status_map);
for (std::map<GURL, std::string>::const_iterator itr = status_map.begin();
itr != status_map.end();
++itr) {
std::string extension_id = itr->first.HostNoBrackets();
const extensions::Extension* extension =
extension_service->GetExtensionById(extension_id, true);
if (!extension)
continue;
base::DictionaryValue* dict = new base::DictionaryValue;
dict->SetString("extensionID", extension_id);
dict->SetString("extensionName", extension->name());
dict->SetString("status", itr->second);
values->Append(dict);
}
}
void ExtensionStatusesHandler::GetExtensionStatuses(
const base::ListValue* args) {
DCHECK(args);
base::ListValue list;
GetExtensionStatusesAsDictionary(profile_, &list);
web_ui()->CallJavascriptFunction("ExtensionStatuses.onGetExtensionStatuses",
list);
}
}