Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(99)

Unified Diff: chrome/browser/chromeos/extensions/file_manager/event_router.cc

Issue 107813005: Files.app: Use types and constants generated by the IDL compiler in the event router. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | chrome/browser/extensions/event_names.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/chromeos/extensions/file_manager/event_router.cc
diff --git a/chrome/browser/chromeos/extensions/file_manager/event_router.cc b/chrome/browser/chromeos/extensions/file_manager/event_router.cc
index b5f153dbdc656f41233ab1377273d3769cf9d4cc..72de6b11cdaa242aeb65d123b7c75b7fe03760de 100644
--- a/chrome/browser/chromeos/extensions/file_manager/event_router.cc
+++ b/chrome/browser/chromeos/extensions/file_manager/event_router.cc
@@ -94,26 +94,29 @@ bool IsUploadJob(drive::JobType type) {
}
// Converts the job info to its JSON (Value) form.
mtomasz 2013/12/25 01:19:56 nit: Please update the comment.
hirono 2013/12/25 02:06:55 Done.
-scoped_ptr<base::DictionaryValue> JobInfoToDictionaryValue(
+void JobInfoToDictionaryValue(
const std::string& extension_id,
const std::string& job_status,
- const drive::JobInfo& job_info) {
+ const drive::JobInfo& job_info,
+ file_browser_private::FileTransferStatus* status) {
DCHECK(IsActiveFileTransferJobInfo(job_info));
scoped_ptr<base::DictionaryValue> result(new base::DictionaryValue);
GURL url = util::ConvertRelativeFilePathToFileSystemUrl(
job_info.file_path, extension_id);
- result->SetString("fileUrl", url.spec());
- result->SetString("transferState", job_status);
- result->SetString("transferType",
- IsUploadJob(job_info.job_type) ? "upload" : "download");
+ status->file_url = url.spec();
+ status->transfer_state = file_browser_private::ParseTransferState(job_status);
+ status->transfer_type =
+ 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
// is in IEEE 754 formant and accurate up to 52-bits in JS, and in practice
// in C++. Larger values are rounded.
- result->SetDouble("processed",
- static_cast<double>(job_info.num_completed_bytes));
- result->SetDouble("total", static_cast<double>(job_info.num_total_bytes));
- return result.Pass();
+ status->processed.reset(
+ new double(static_cast<double>(job_info.num_completed_bytes)));
+ status->total.reset(
+ new double(static_cast<double>(job_info.num_total_bytes)));
}
// Checks for availability of the Google+ Photos app.
@@ -226,7 +229,7 @@ void BroadcastMountCompletedEvent(
BroadcastEvent(
profile,
- extensions::event_names::kOnFileBrowserMountCompleted,
+ file_browser_private::OnMountCompleted::kEventName,
file_browser_private::OnMountCompleted::Create(event));
}
@@ -429,7 +432,7 @@ void EventRouter::OnCopyCompleted(int copy_id,
BroadcastEvent(
profile_,
- extensions::event_names::kOnFileBrowserCopyProgress,
+ file_browser_private::OnCopyProgress::kEventName,
file_browser_private::OnCopyProgress::Create(copy_id, status));
}
@@ -451,7 +454,7 @@ void EventRouter::OnCopyProgress(
BroadcastEvent(
profile_,
- extensions::event_names::kOnFileBrowserCopyProgress,
+ file_browser_private::OnCopyProgress::kEventName,
file_browser_private::OnCopyProgress::Create(copy_id, status));
}
@@ -464,8 +467,8 @@ void EventRouter::DefaultNetworkChanged(const chromeos::NetworkState* network) {
BroadcastEvent(
profile_,
- extensions::event_names::kOnFileBrowserDriveConnectionStatusChanged,
- make_scoped_ptr(new base::ListValue));
+ file_browser_private::OnDriveConnectionStatusChanged::kEventName,
+ file_browser_private::OnDriveConnectionStatusChanged::Create());
}
void EventRouter::OnFileManagerPrefsChanged() {
@@ -477,8 +480,8 @@ void EventRouter::OnFileManagerPrefsChanged() {
BroadcastEvent(
profile_,
- extensions::event_names::kOnFileBrowserPreferencesChanged,
- make_scoped_ptr(new base::ListValue));
+ file_browser_private::OnPreferencesChanged::kEventName,
+ file_browser_private::OnPreferencesChanged::Create());
}
void EventRouter::OnJobAdded(const drive::JobInfo& job_info) {
@@ -539,25 +542,23 @@ void EventRouter::SendDriveFileTransferEvent(bool always) {
return;
}
- // Convert the current |drive_jobs_| to a JSON value.
- scoped_ptr<base::ListValue> event_list(new base::ListValue);
+ // Convert the current |drive_jobs_| to IDL type.
+ std::vector<linked_ptr<file_browser_private::FileTransferStatus> >
mtomasz 2013/12/25 01:19:56 How about ScopedVector? https://groups.google.com
hirono 2013/12/25 02:06:55 Because IDL generated methods takes std::vector<li
+ status_list;
+ status_list.resize(drive_jobs_.size());
+ size_t i = 0;
for (std::map<drive::JobID, DriveJobInfoWithStatus>::iterator
iter = drive_jobs_.begin(); iter != drive_jobs_.end(); ++iter) {
-
- scoped_ptr<base::DictionaryValue> job_info_dict(
- JobInfoToDictionaryValue(kFileManagerAppId,
- iter->second.status,
- iter->second.job_info));
- event_list->Append(job_info_dict.release());
+ JobInfoToDictionaryValue(kFileManagerAppId,
+ iter->second.status,
+ iter->second.job_info,
+ status_list[i++].get());
}
- scoped_ptr<base::ListValue> args(new base::ListValue());
- args->Append(event_list.release());
- scoped_ptr<extensions::Event> event(new extensions::Event(
- extensions::event_names::kOnFileTransfersUpdated, args.Pass()));
- extensions::ExtensionSystem::Get(profile_)->event_router()->
- DispatchEventToExtension(kFileManagerAppId, event.Pass());
-
+ BroadcastEvent(
+ profile_,
+ file_browser_private::OnFileTransfersUpdated::kEventName,
+ file_browser_private::OnFileTransfersUpdated::Create(status_list));
last_file_transfer_event_ = now;
}
@@ -571,8 +572,8 @@ void EventRouter::OnRefreshTokenInvalid() {
// Raise a DriveConnectionStatusChanged event to notify the status offline.
BroadcastEvent(
profile_,
- extensions::event_names::kOnFileBrowserDriveConnectionStatusChanged,
- make_scoped_ptr(new base::ListValue));
+ file_browser_private::OnDriveConnectionStatusChanged::kEventName,
+ file_browser_private::OnDriveConnectionStatusChanged::Create());
}
void EventRouter::HandleFileWatchNotification(const base::FilePath& local_path,
@@ -616,10 +617,10 @@ void EventRouter::DispatchDirectoryChangeEvent(
watch_info->Set("entry", entry);
watch_info->SetString("eventType",
got_error ? kPathWatchError : kPathChanged);
- scoped_ptr<extensions::Event> event(new extensions::Event(
- extensions::event_names::kOnDirectoryChanged, args.Pass()));
- extensions::ExtensionSystem::Get(profile_)->event_router()->
- DispatchEventToExtension(extension_id, event.Pass());
+ BroadcastEvent(
+ profile_,
+ file_browser_private::OnDirectoryChanged::kEventName,
+ args.Pass());
}
}
« no previous file with comments | « no previous file | chrome/browser/extensions/event_names.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698