Commit f8864cb2 authored by hirono@chromium.org's avatar hirono@chromium.org

Files.app: Use types and constants generated by the IDL compiler in the event router.

Event names and dictionary values in the event router of Files.app can be
replaced with constants and types generated by the IDL compiler.

BUG=330638
TEST=none

Review URL: https://codereview.chromium.org/107813005

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@243525 0039d316-1c4b-4281-b951-d872f2087c98
parent 8ebd46c1
...@@ -51,9 +51,6 @@ namespace file_browser_private = extensions::api::file_browser_private; ...@@ -51,9 +51,6 @@ namespace file_browser_private = extensions::api::file_browser_private;
namespace file_manager { namespace file_manager {
namespace { namespace {
const char kPathChanged[] = "changed";
const char kPathWatchError[] = "error";
void DirectoryExistsOnBlockingPool(const base::FilePath& directory_path, void DirectoryExistsOnBlockingPool(const base::FilePath& directory_path,
const base::Closure& success_callback, const base::Closure& success_callback,
const base::Closure& failure_callback) { const base::Closure& failure_callback) {
...@@ -93,27 +90,30 @@ bool IsUploadJob(drive::JobType type) { ...@@ -93,27 +90,30 @@ bool IsUploadJob(drive::JobType type) {
type == drive::TYPE_UPLOAD_EXISTING_FILE); type == drive::TYPE_UPLOAD_EXISTING_FILE);
} }
// Converts the job info to its JSON (Value) form. // Converts the job info to a IDL generated type.
scoped_ptr<base::DictionaryValue> JobInfoToDictionaryValue( void JobInfoToTransferStatus(
const std::string& extension_id, const std::string& extension_id,
const std::string& job_status, const std::string& job_status,
const drive::JobInfo& job_info) { const drive::JobInfo& job_info,
file_browser_private::FileTransferStatus* status) {
DCHECK(IsActiveFileTransferJobInfo(job_info)); DCHECK(IsActiveFileTransferJobInfo(job_info));
scoped_ptr<base::DictionaryValue> result(new base::DictionaryValue); scoped_ptr<base::DictionaryValue> result(new base::DictionaryValue);
GURL url = util::ConvertRelativeFilePathToFileSystemUrl( GURL url = util::ConvertRelativeFilePathToFileSystemUrl(
job_info.file_path, extension_id); job_info.file_path, extension_id);
result->SetString("fileUrl", url.spec()); status->file_url = url.spec();
result->SetString("transferState", job_status); status->transfer_state = file_browser_private::ParseTransferState(job_status);
result->SetString("transferType", status->transfer_type =
IsUploadJob(job_info.job_type) ? "upload" : "download"); IsUploadJob(job_info.job_type) ?
file_browser_private::TRANSFER_TYPE_UPLOAD :
file_browser_private::TRANSFER_TYPE_DOWNLOAD;
// JavaScript does not have 64-bit integers. Instead we use double, which // JavaScript does not have 64-bit integers. Instead we use double, which
// is in IEEE 754 formant and accurate up to 52-bits in JS, and in practice // is in IEEE 754 formant and accurate up to 52-bits in JS, and in practice
// in C++. Larger values are rounded. // in C++. Larger values are rounded.
result->SetDouble("processed", status->processed.reset(
static_cast<double>(job_info.num_completed_bytes)); new double(static_cast<double>(job_info.num_completed_bytes)));
result->SetDouble("total", static_cast<double>(job_info.num_total_bytes)); status->total.reset(
return result.Pass(); new double(static_cast<double>(job_info.num_total_bytes)));
} }
// Checks for availability of the Google+ Photos app. // Checks for availability of the Google+ Photos app.
...@@ -226,7 +226,7 @@ void BroadcastMountCompletedEvent( ...@@ -226,7 +226,7 @@ void BroadcastMountCompletedEvent(
BroadcastEvent( BroadcastEvent(
profile, profile,
extensions::event_names::kOnFileBrowserMountCompleted, file_browser_private::OnMountCompleted::kEventName,
file_browser_private::OnMountCompleted::Create(event)); file_browser_private::OnMountCompleted::Create(event));
} }
...@@ -429,7 +429,7 @@ void EventRouter::OnCopyCompleted(int copy_id, ...@@ -429,7 +429,7 @@ void EventRouter::OnCopyCompleted(int copy_id,
BroadcastEvent( BroadcastEvent(
profile_, profile_,
extensions::event_names::kOnFileBrowserCopyProgress, file_browser_private::OnCopyProgress::kEventName,
file_browser_private::OnCopyProgress::Create(copy_id, status)); file_browser_private::OnCopyProgress::Create(copy_id, status));
} }
...@@ -451,7 +451,7 @@ void EventRouter::OnCopyProgress( ...@@ -451,7 +451,7 @@ void EventRouter::OnCopyProgress(
BroadcastEvent( BroadcastEvent(
profile_, profile_,
extensions::event_names::kOnFileBrowserCopyProgress, file_browser_private::OnCopyProgress::kEventName,
file_browser_private::OnCopyProgress::Create(copy_id, status)); file_browser_private::OnCopyProgress::Create(copy_id, status));
} }
...@@ -464,8 +464,8 @@ void EventRouter::DefaultNetworkChanged(const chromeos::NetworkState* network) { ...@@ -464,8 +464,8 @@ void EventRouter::DefaultNetworkChanged(const chromeos::NetworkState* network) {
BroadcastEvent( BroadcastEvent(
profile_, profile_,
extensions::event_names::kOnFileBrowserDriveConnectionStatusChanged, file_browser_private::OnDriveConnectionStatusChanged::kEventName,
make_scoped_ptr(new base::ListValue)); file_browser_private::OnDriveConnectionStatusChanged::Create());
} }
void EventRouter::OnFileManagerPrefsChanged() { void EventRouter::OnFileManagerPrefsChanged() {
...@@ -477,8 +477,8 @@ void EventRouter::OnFileManagerPrefsChanged() { ...@@ -477,8 +477,8 @@ void EventRouter::OnFileManagerPrefsChanged() {
BroadcastEvent( BroadcastEvent(
profile_, profile_,
extensions::event_names::kOnFileBrowserPreferencesChanged, file_browser_private::OnPreferencesChanged::kEventName,
make_scoped_ptr(new base::ListValue)); file_browser_private::OnPreferencesChanged::Create());
} }
void EventRouter::OnJobAdded(const drive::JobInfo& job_info) { void EventRouter::OnJobAdded(const drive::JobInfo& job_info) {
...@@ -539,25 +539,23 @@ void EventRouter::SendDriveFileTransferEvent(bool always) { ...@@ -539,25 +539,23 @@ void EventRouter::SendDriveFileTransferEvent(bool always) {
return; return;
} }
// Convert the current |drive_jobs_| to a JSON value. // Convert the current |drive_jobs_| to IDL type.
scoped_ptr<base::ListValue> event_list(new base::ListValue); std::vector<linked_ptr<file_browser_private::FileTransferStatus> >
status_list;
for (std::map<drive::JobID, DriveJobInfoWithStatus>::iterator for (std::map<drive::JobID, DriveJobInfoWithStatus>::iterator
iter = drive_jobs_.begin(); iter != drive_jobs_.end(); ++iter) { iter = drive_jobs_.begin(); iter != drive_jobs_.end(); ++iter) {
linked_ptr<file_browser_private::FileTransferStatus> status(
scoped_ptr<base::DictionaryValue> job_info_dict( new file_browser_private::FileTransferStatus());
JobInfoToDictionaryValue(kFileManagerAppId, JobInfoToTransferStatus(kFileManagerAppId,
iter->second.status, iter->second.status,
iter->second.job_info)); iter->second.job_info,
event_list->Append(job_info_dict.release()); status.get());
status_list.push_back(status);
} }
BroadcastEvent(
scoped_ptr<base::ListValue> args(new base::ListValue()); profile_,
args->Append(event_list.release()); file_browser_private::OnFileTransfersUpdated::kEventName,
scoped_ptr<extensions::Event> event(new extensions::Event( file_browser_private::OnFileTransfersUpdated::Create(status_list));
extensions::event_names::kOnFileTransfersUpdated, args.Pass()));
extensions::ExtensionSystem::Get(profile_)->event_router()->
DispatchEventToExtension(kFileManagerAppId, event.Pass());
last_file_transfer_event_ = now; last_file_transfer_event_ = now;
} }
...@@ -571,8 +569,8 @@ void EventRouter::OnRefreshTokenInvalid() { ...@@ -571,8 +569,8 @@ void EventRouter::OnRefreshTokenInvalid() {
// Raise a DriveConnectionStatusChanged event to notify the status offline. // Raise a DriveConnectionStatusChanged event to notify the status offline.
BroadcastEvent( BroadcastEvent(
profile_, profile_,
extensions::event_names::kOnFileBrowserDriveConnectionStatusChanged, file_browser_private::OnDriveConnectionStatusChanged::kEventName,
make_scoped_ptr(new base::ListValue)); file_browser_private::OnDriveConnectionStatusChanged::Create());
} }
void EventRouter::HandleFileWatchNotification(const base::FilePath& local_path, void EventRouter::HandleFileWatchNotification(const base::FilePath& local_path,
...@@ -598,28 +596,27 @@ void EventRouter::DispatchDirectoryChangeEvent( ...@@ -598,28 +596,27 @@ void EventRouter::DispatchDirectoryChangeEvent(
for (size_t i = 0; i < extension_ids.size(); ++i) { for (size_t i = 0; i < extension_ids.size(); ++i) {
const std::string& extension_id = extension_ids[i]; const std::string& extension_id = extension_ids[i];
const GURL target_origin_url(
GURL target_origin_url(extensions::Extension::GetBaseURLFromExtensionId( extensions::Extension::GetBaseURLFromExtensionId(extension_id));
extension_id));
scoped_ptr<base::ListValue> args(new base::ListValue());
base::DictionaryValue* watch_info = new base::DictionaryValue();
args->Append(watch_info);
// This will be replaced with a real Entry in custom bindings. // This will be replaced with a real Entry in custom bindings.
fileapi::FileSystemInfo info = const fileapi::FileSystemInfo info =
fileapi::GetFileSystemInfoForChromeOS(target_origin_url.GetOrigin()); fileapi::GetFileSystemInfoForChromeOS(target_origin_url.GetOrigin());
base::DictionaryValue* entry = new base::DictionaryValue();
entry->SetString("fileSystemName", info.name); file_browser_private::FileWatchEvent event;
entry->SetString("fileSystemRoot", info.root_url.spec()); event.event_type = got_error ?
entry->SetString("fileFullPath", "/" + virtual_path.value()); file_browser_private::FILE_WATCH_EVENT_TYPE_ERROR :
entry->SetBoolean("fileIsDirectory", true); file_browser_private::FILE_WATCH_EVENT_TYPE_CHANGED;
watch_info->Set("entry", entry); event.entry.additional_properties.SetString("fileSystemName", info.name);
watch_info->SetString("eventType", event.entry.additional_properties.SetString("fileSystemRoot",
got_error ? kPathWatchError : kPathChanged); info.root_url.spec());
scoped_ptr<extensions::Event> event(new extensions::Event( event.entry.additional_properties.SetString("fileFullPath",
extensions::event_names::kOnDirectoryChanged, args.Pass())); "/" + virtual_path.value());
extensions::ExtensionSystem::Get(profile_)->event_router()-> event.entry.additional_properties.SetBoolean("fileIsDirectory", true);
DispatchEventToExtension(extension_id, event.Pass());
BroadcastEvent(
profile_,
file_browser_private::OnDirectoryChanged::kEventName,
file_browser_private::OnDirectoryChanged::Create(event));
} }
} }
......
...@@ -8,17 +8,6 @@ namespace extensions { ...@@ -8,17 +8,6 @@ namespace extensions {
namespace event_names { namespace event_names {
const char kOnDirectoryChanged[] = "fileBrowserPrivate.onDirectoryChanged";
const char kOnFileBrowserMountCompleted[] =
"fileBrowserPrivate.onMountCompleted";
const char kOnFileTransfersUpdated[] =
"fileBrowserPrivate.onFileTransfersUpdated";
const char kOnFileBrowserPreferencesChanged[] =
"fileBrowserPrivate.onPreferencesChanged";
const char kOnFileBrowserDriveConnectionStatusChanged[] =
"fileBrowserPrivate.onDriveConnectionStatusChanged";
const char kOnFileBrowserCopyProgress[] = "fileBrowserPrivate.onCopyProgress";
const char kOnInputMethodChanged[] = "inputMethodPrivate.onChanged"; const char kOnInputMethodChanged[] = "inputMethodPrivate.onChanged";
const char kOnContextMenus[] = "contextMenus"; const char kOnContextMenus[] = "contextMenus";
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment