Chromium Code Reviews| Index: win8/metro_driver/secondary_tile.cc |
| diff --git a/win8/metro_driver/secondary_tile.cc b/win8/metro_driver/secondary_tile.cc |
| index 97109c1924b5f79de574f1f0cdba58f3fef33e1f..287ce08ff46a3dc1d2575ab7fba4cd07607a0f48 100644 |
| --- a/win8/metro_driver/secondary_tile.cc |
| +++ b/win8/metro_driver/secondary_tile.cc |
| @@ -16,7 +16,75 @@ |
| namespace { |
| -void DeleteTileFromStartScreen(const string16& tile_id) { |
| +// Callback for asynchronous pin requests. |
| +class TileRequestDone { |
| + public: |
| + enum PinType { |
| + PIN, |
| + UNPIN |
| + }; |
| + TileRequestDone(PinType type, win8::MetroPinResultCallback callback) |
| + : type_(type), callback_(callback) {} |
| + |
| + void Complete(mswr::ComPtr<winfoundtn::IAsyncOperation<bool>>& completion); |
| + |
| + private: |
| + HRESULT Respond(winfoundtn::IAsyncOperation<bool>* async, |
| + AsyncStatus status); |
| + |
| + PinType type_; |
| + win8::MetroPinResultCallback callback_; |
| +}; |
| + |
| +void TileRequestDone::Complete( |
| + mswr::ComPtr<winfoundtn::IAsyncOperation<bool>>& completion) { |
| + typedef winfoundtn::IAsyncOperationCompletedHandler<bool> RequestDoneType; |
| + mswr::ComPtr<RequestDoneType> handler(mswr::Callback<RequestDoneType>( |
| + this, &TileRequestDone::Respond)); |
| + DCHECK(handler.Get() != NULL); |
| + HRESULT hr = completion->put_Completed(handler.Get()); |
| + CheckHR(hr, "Failed to put_Completed"); |
| +} |
| + |
| +HRESULT TileRequestDone::Respond(winfoundtn::IAsyncOperation<bool>* async, |
| + AsyncStatus status) { |
| + win8::MetroSecondaryTilePinState pin_state = win8::METRO_PIN_STATE_NONE; |
| + |
| + if (status == Completed) { |
| + unsigned char result; |
| + CheckHR(async->GetResults(&result)); |
| + LOG(INFO) << __FUNCTION__ << " result " << static_cast<int>(result); |
| + switch (result) { |
| + case 0: |
| + pin_state = type_ == PIN ? |
| + win8::METRO_PIN_RESULT_CANCEL : |
| + win8::METRO_UNPIN_RESULT_CANCEL; |
| + break; |
| + case 1: |
| + pin_state = type_ == PIN ? |
| + win8::METRO_PIN_RESULT_OK : |
| + win8::METRO_UNPIN_RESULT_OK; |
| + break; |
| + default: |
| + pin_state = type_ == PIN ? |
| + win8::METRO_PIN_RESULT_OTHER : |
| + win8::METRO_UNPIN_RESULT_OTHER; |
| + break; |
| + } |
| + } else { |
| + LOG(ERROR) << __FUNCTION__ << " Unexpected async status " << status; |
| + pin_state = type_ == PIN ? |
| + win8::METRO_PIN_RESULT_ERROR : |
| + win8::METRO_UNPIN_RESULT_ERROR; |
| + } |
| + callback_.Run(pin_state); |
| + |
| + delete this; |
| + return S_OK; |
| +} |
| + |
| +void DeleteTileFromStartScreen(const string16& tile_id, |
| + win8::MetroPinResultCallback callback) { |
| DVLOG(1) << __FUNCTION__; |
| mswr::ComPtr<winui::StartScreen::ISecondaryTileFactory> tile_factory; |
| HRESULT hr = winrt_utils::CreateActivationFactory( |
| @@ -35,18 +103,21 @@ void DeleteTileFromStartScreen(const string16& tile_id) { |
| hr = tile->RequestDeleteAsync(completion.GetAddressOf()); |
| CheckHR(hr, "RequestDeleteAsync failed"); |
| - typedef winfoundtn::IAsyncOperationCompletedHandler<bool> RequestDoneType; |
| - mswr::ComPtr<RequestDoneType> handler(mswr::Callback<RequestDoneType>( |
| - globals.view, &ChromeAppView::TileRequestCreateDone)); |
| - DCHECK(handler.Get() != NULL); |
| - hr = completion->put_Completed(handler.Get()); |
| - CheckHR(hr, "Failed to put_Completed"); |
| + if (FAILED(hr)) { |
| + callback.Run(win8::METRO_UNPIN_REQUEST_SHOW_ERROR); |
| + return; |
| + } |
| + |
| + // Deleted in TileRequestDone::Respond when the async operation completes. |
| + (new TileRequestDone(TileRequestDone::UNPIN, |
| + callback))->Complete(completion); |
| } |
| void CreateTileOnStartScreen(const string16& tile_id, |
| const string16& title_str, |
| const string16& url_str, |
| - const FilePath& logo_path) { |
| + const FilePath& logo_path, |
| + win8::MetroPinResultCallback callback) { |
| VLOG(1) << __FUNCTION__; |
| mswr::ComPtr<winui::StartScreen::ISecondaryTileFactory> tile_factory; |
| @@ -99,12 +170,14 @@ void CreateTileOnStartScreen(const string16& tile_id, |
| hr = tile->RequestCreateAsync(completion.GetAddressOf()); |
| CheckHR(hr, "RequestCreateAsync failed"); |
| - typedef winfoundtn::IAsyncOperationCompletedHandler<bool> RequestDoneType; |
| - mswr::ComPtr<RequestDoneType> handler(mswr::Callback<RequestDoneType>( |
| - globals.view, &ChromeAppView::TileRequestCreateDone)); |
| - DCHECK(handler.Get() != NULL); |
| - hr = completion->put_Completed(handler.Get()); |
| - CheckHR(hr, "Failed to put_Completed"); |
| + if (FAILED(hr)) { |
| + callback.Run(win8::METRO_PIN_REQUEST_SHOW_ERROR); |
| + return; |
| + } |
| + |
| + // Deleted in TileRequestDone::Respond when the async operation completes. |
| + (new TileRequestDone(TileRequestDone::PIN, |
| + callback))->Complete(completion); |
| } |
| } // namespace |
| @@ -122,19 +195,25 @@ BOOL MetroIsPinnedToStartScreen(const string16& tile_id) { |
| return exists; |
| } |
| -void MetroUnPinFromStartScreen(const string16& tile_id) { |
| +void MetroUnPinFromStartScreen(const string16& tile_id, |
| + win8::MetroPinResultCallback callback) { |
| + // Ensure function signature is correct. |
|
MAD
2012/11/29 15:26:18
I don't understand this comment...
tapted
2012/11/30 00:30:31
Sorry - thanks for catching it - that was a stray
|
| globals.appview_msg_loop->PostTask( |
| - FROM_HERE, base::Bind(&DeleteTileFromStartScreen, tile_id)); |
| + FROM_HERE, base::Bind(&DeleteTileFromStartScreen, |
| + tile_id, |
| + callback)); |
| } |
| void MetroPinToStartScreen(const string16& tile_id, |
| const string16& title, |
| const string16& url, |
| - const FilePath& logo_path) { |
| + const FilePath& logo_path, |
| + win8::MetroPinResultCallback callback) { |
| globals.appview_msg_loop->PostTask( |
| FROM_HERE, base::Bind(&CreateTileOnStartScreen, |
| tile_id, |
| title, |
| url, |
| - logo_path)); |
| + logo_path, |
| + callback)); |
| } |