Merge pull request #6766 from miniak/set-user-tasks-result

Report app.setUserTasks success/failure
This commit is contained in:
Cheng Zhao 2016-08-08 17:43:08 +09:00 committed by GitHub
commit a432fb0c34
3 changed files with 17 additions and 11 deletions

View file

@ -156,7 +156,7 @@ class Browser : public WindowListObserver {
};
// Add a custom task to jump list.
void SetUserTasks(const std::vector<UserTask>& tasks);
bool SetUserTasks(const std::vector<UserTask>& tasks);
// Returns the application user model ID, if there isn't one, then create
// one from app's name.

View file

@ -79,22 +79,22 @@ void Browser::SetAppUserModelID(const base::string16& name) {
SetCurrentProcessExplicitAppUserModelID(app_user_model_id_.c_str());
}
void Browser::SetUserTasks(const std::vector<UserTask>& tasks) {
bool Browser::SetUserTasks(const std::vector<UserTask>& tasks) {
CComPtr<ICustomDestinationList> destinations;
if (FAILED(destinations.CoCreateInstance(CLSID_DestinationList)))
return;
return false;
if (FAILED(destinations->SetAppID(GetAppUserModelID())))
return;
return false;
// Start a transaction that updates the JumpList of this application.
UINT max_slots;
CComPtr<IObjectArray> removed;
if (FAILED(destinations->BeginList(&max_slots, IID_PPV_ARGS(&removed))))
return;
return false;
CComPtr<IObjectCollection> collection;
if (FAILED(collection.CoCreateInstance(CLSID_EnumerableObjectCollection)))
return;
return false;
for (auto& task : tasks) {
CComPtr<IShellLink> link;
@ -102,27 +102,27 @@ void Browser::SetUserTasks(const std::vector<UserTask>& tasks) {
FAILED(link->SetPath(task.program.value().c_str())) ||
FAILED(link->SetArguments(task.arguments.c_str())) ||
FAILED(link->SetDescription(task.description.c_str())))
return;
return false;
if (!task.icon_path.empty() &&
FAILED(link->SetIconLocation(task.icon_path.value().c_str(),
task.icon_index)))
return;
return false;
CComQIPtr<IPropertyStore> property_store = link;
if (!base::win::SetStringValueForPropertyStore(property_store, PKEY_Title,
task.title.c_str()))
return;
return false;
if (FAILED(collection->AddObject(link)))
return;
return false;
}
// When the list is empty "AddUserTasks" could fail, so we don't check return
// value for it.
CComQIPtr<IObjectArray> task_array = collection;
destinations->AddUserTasks(task_array);
destinations->CommitList();
return SUCCEEDED(destinations->CommitList());
}
bool Browser::RemoveAsDefaultProtocolClient(const std::string& protocol) {