This source file includes following definitions.
- weak_factory_
- RegisterMessages
- GetFileMetadata
- GetExtensions
- DidGetFileMetadata
#include "chrome/browser/ui/webui/sync_file_system_internals/file_metadata_handler.h"
#include <map>
#include "base/bind.h"
#include "base/bind_helpers.h"
#include "base/values.h"
#include "chrome/browser/extensions/api/sync_file_system/sync_file_system_api_helpers.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 "chrome/browser/ui/webui/sync_file_system_internals/extension_statuses_handler.h"
#include "content/public/browser/web_ui.h"
#include "content/public/browser/web_ui_data_source.h"
#include "extensions/common/extension.h"
#include "grit/sync_file_system_internals_resources.h"
using sync_file_system::RemoteFileSyncService;
using sync_file_system::SyncFileSystemServiceFactory;
using sync_file_system::SyncServiceState;
namespace syncfs_internals {
FileMetadataHandler::FileMetadataHandler(Profile* profile)
: profile_(profile),
weak_factory_(this) {}
FileMetadataHandler::~FileMetadataHandler() {}
void FileMetadataHandler::RegisterMessages() {
web_ui()->RegisterMessageCallback(
"getExtensions",
base::Bind(&FileMetadataHandler::GetExtensions,
base::Unretained(this)));
web_ui()->RegisterMessageCallback(
"getFileMetadata",
base::Bind(&FileMetadataHandler::GetFileMetadata,
base::Unretained(this)));
}
void FileMetadataHandler::GetFileMetadata(
const base::ListValue* args) {
std::string extension_id;
if (!args->GetString(0, &extension_id) || extension_id.empty()) {
LOG(WARNING) << "GetFileMetadata() Extension ID wasn't given";
return;
}
const GURL origin = extensions::Extension::GetBaseURLFromExtensionId(
extension_id);
sync_file_system::SyncFileSystemService* sync_service =
SyncFileSystemServiceFactory::GetForProfile(profile_);
if (!sync_service)
return;
sync_service->DumpFiles(origin,
base::Bind(&FileMetadataHandler::DidGetFileMetadata,
weak_factory_.GetWeakPtr()));
}
void FileMetadataHandler::GetExtensions(const base::ListValue* args) {
DCHECK(args);
base::ListValue list;
ExtensionStatusesHandler::GetExtensionStatusesAsDictionary(profile_, &list);
web_ui()->CallJavascriptFunction("FileMetadata.onGetExtensions", list);
}
void FileMetadataHandler::DidGetFileMetadata(const base::ListValue* files) {
DCHECK(files);
web_ui()->CallJavascriptFunction("FileMetadata.onGetFileMetadata", *files);
}
}