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

Unified Diff: win8/metro_driver/secondary_tile.cc

Issue 11280112: UMA for Windows 8 Secondary Tile pinning/unpinning user actions (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: reviewer comments Created 8 years, 1 month 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
« base/win/metro.h ('K') | « win8/metro_driver/secondary_tile.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..dd9018cbc5af7eaa7302966231d88bb78180c6a0 100644
--- a/win8/metro_driver/secondary_tile.cc
+++ b/win8/metro_driver/secondary_tile.cc
@@ -16,7 +16,77 @@
namespace {
-void DeleteTileFromStartScreen(const string16& tile_id) {
+// Callback for asynchronous pin requests.
+class TileRequestDone {
+ public:
+ enum PinType {
+ PIN,
+ UNPIN
+ };
+ TileRequestDone(PinType type, base::win::MetroPinResultCallback callback)
+ : type_(type), callback_(callback) {
+ }
benwells 2012/11/29 04:19:46 Blank line after. Can have {} on one line.
tapted 2012/11/29 07:19:27 Done.
+ void Complete(mswr::ComPtr<winfoundtn::IAsyncOperation<bool>>& completion);
+
+ private:
+ HRESULT Respond(winfoundtn::IAsyncOperation<bool>* async,
+ AsyncStatus status);
+
+ PinType type_;
+ base::win::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) {
+ base::win::MetroSecondaryTilePinState pin_state =
+ base::win::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 ?
+ base::win::METRO_PIN_RESULT_CANCEL :
+ base::win::METRO_UNPIN_RESULT_CANCEL;
+ break;
+ case 1:
+ pin_state = type_ == PIN ?
+ base::win::METRO_PIN_RESULT_OK :
+ base::win::METRO_UNPIN_RESULT_OK;
+ break;
+ default:
+ pin_state = type_ == PIN ?
+ base::win::METRO_PIN_RESULT_OTHER :
+ base::win::METRO_UNPIN_RESULT_OTHER;
+ break;
+ }
+ } else {
+ LOG(ERROR) << __FUNCTION__ << " Unexpected async status " << status;
+ pin_state = type_ == PIN ?
+ base::win::METRO_PIN_RESULT_ERROR :
+ base::win::METRO_UNPIN_RESULT_ERROR;
+ }
+ if (callback_)
+ callback_(pin_state);
+
+ delete this;
+ return S_OK;
+}
+
+void DeleteTileFromStartScreen(const string16& tile_id,
+ base::win::MetroPinResultCallback callback) {
DVLOG(1) << __FUNCTION__;
mswr::ComPtr<winui::StartScreen::ISecondaryTileFactory> tile_factory;
HRESULT hr = winrt_utils::CreateActivationFactory(
@@ -35,18 +105,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)) {
+ if (callback)
+ callback(base::win::METRO_UNPIN_REQUEST_SHOW_ERROR);
+ return;
+ }
+
+ (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,
+ base::win::MetroPinResultCallback callback) {
VLOG(1) << __FUNCTION__;
mswr::ComPtr<winui::StartScreen::ISecondaryTileFactory> tile_factory;
@@ -99,12 +172,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)) {
+ if (callback)
+ callback(base::win::METRO_PIN_REQUEST_SHOW_ERROR);
+ return;
+ }
+
+ (new TileRequestDone(TileRequestDone::PIN,
benwells 2012/11/29 04:19:46 Please add a comment here about this object's life
tapted 2012/11/29 07:19:27 Done.
+ callback))->Complete(completion);
}
} // namespace
@@ -122,19 +197,25 @@ BOOL MetroIsPinnedToStartScreen(const string16& tile_id) {
return exists;
}
-void MetroUnPinFromStartScreen(const string16& tile_id) {
+void MetroUnPinFromStartScreen(const string16& tile_id,
+ base::win::MetroPinResultCallback callback) {
+ // Ensure function signature is correct.
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,
+ base::win::MetroPinResultCallback callback) {
globals.appview_msg_loop->PostTask(
FROM_HERE, base::Bind(&CreateTileOnStartScreen,
tile_id,
title,
url,
- logo_path));
+ logo_path,
+ callback));
}
« base/win/metro.h ('K') | « win8/metro_driver/secondary_tile.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698