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

Side by Side 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: types back to base/win/metro.h, pass callback by const-reference, Uma, reviewer comments Created 8 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "stdafx.h" 5 #include "stdafx.h"
6 #include "secondary_tile.h" 6 #include "secondary_tile.h"
7 7
8 #include <windows.ui.startscreen.h> 8 #include <windows.ui.startscreen.h>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/utf_string_conversions.h" 12 #include "base/utf_string_conversions.h"
13 #include "googleurl/src/gurl.h" 13 #include "googleurl/src/gurl.h"
14 #include "win8/metro_driver/chrome_app_view.h" 14 #include "win8/metro_driver/chrome_app_view.h"
15 #include "win8/metro_driver/winrt_utils.h" 15 #include "win8/metro_driver/winrt_utils.h"
16 16
17 namespace { 17 namespace {
18 18
19 void DeleteTileFromStartScreen(const string16& tile_id) { 19 using base::win::MetroPinUmaResultCallback;
20
21 // Callback for asynchronous pin requests.
22 class TileRequestDone {
benwells 2012/11/30 01:16:47 Can you rename this class to TileRequestCompletedH
tapted 2012/11/30 05:54:19 Done. Went for TileRequestCompleter .. since it `C
23 public:
24 enum PinType {
25 PIN,
26 UNPIN
27 };
28 TileRequestDone(PinType type, const MetroPinUmaResultCallback& callback)
29 : type_(type), callback_(callback) {}
30
31 void Complete(mswr::ComPtr<winfoundtn::IAsyncOperation<bool>>& completion);
32
33 private:
34 HRESULT Respond(winfoundtn::IAsyncOperation<bool>* async,
35 AsyncStatus status);
36
37 PinType type_;
38 MetroPinUmaResultCallback callback_;
39 };
40
41 void TileRequestDone::Complete(
42 mswr::ComPtr<winfoundtn::IAsyncOperation<bool>>& completion) {
43 typedef winfoundtn::IAsyncOperationCompletedHandler<bool> RequestDoneType;
44 mswr::ComPtr<RequestDoneType> handler(mswr::Callback<RequestDoneType>(
45 this, &TileRequestDone::Respond));
46 DCHECK(handler.Get() != NULL);
47 HRESULT hr = completion->put_Completed(handler.Get());
48 CheckHR(hr, "Failed to put_Completed");
49 }
50
51 HRESULT TileRequestDone::Respond(winfoundtn::IAsyncOperation<bool>* async,
52 AsyncStatus status) {
53 base::win::MetroSecondaryTilePinUmaResult pin_state =
54 base::win::METRO_PIN_STATE_NONE;
55
56 if (status == Completed) {
57 unsigned char result;
58 CheckHR(async->GetResults(&result));
59 LOG(INFO) << __FUNCTION__ << " result " << static_cast<int>(result);
60 switch (result) {
61 case 0:
62 pin_state = type_ == PIN ?
63 base::win::METRO_PIN_RESULT_CANCEL :
64 base::win::METRO_UNPIN_RESULT_CANCEL;
65 break;
66 case 1:
67 pin_state = type_ == PIN ?
68 base::win::METRO_PIN_RESULT_OK :
69 base::win::METRO_UNPIN_RESULT_OK;
70 break;
71 default:
72 pin_state = type_ == PIN ?
73 base::win::METRO_PIN_RESULT_OTHER :
74 base::win::METRO_UNPIN_RESULT_OTHER;
75 break;
76 }
77 } else {
78 LOG(ERROR) << __FUNCTION__ << " Unexpected async status " << status;
79 pin_state = type_ == PIN ?
80 base::win::METRO_PIN_RESULT_ERROR :
81 base::win::METRO_UNPIN_RESULT_ERROR;
82 }
83 callback_.Run(pin_state);
84
85 delete this;
86 return S_OK;
87 }
88
89 void DeleteTileFromStartScreen(const string16& tile_id,
90 const MetroPinUmaResultCallback& callback) {
20 DVLOG(1) << __FUNCTION__; 91 DVLOG(1) << __FUNCTION__;
21 mswr::ComPtr<winui::StartScreen::ISecondaryTileFactory> tile_factory; 92 mswr::ComPtr<winui::StartScreen::ISecondaryTileFactory> tile_factory;
22 HRESULT hr = winrt_utils::CreateActivationFactory( 93 HRESULT hr = winrt_utils::CreateActivationFactory(
23 RuntimeClass_Windows_UI_StartScreen_SecondaryTile, 94 RuntimeClass_Windows_UI_StartScreen_SecondaryTile,
24 tile_factory.GetAddressOf()); 95 tile_factory.GetAddressOf());
25 CheckHR(hr, "Failed to create instance of ISecondaryTileFactory"); 96 CheckHR(hr, "Failed to create instance of ISecondaryTileFactory");
26 97
27 mswrw::HString id; 98 mswrw::HString id;
28 id.Attach(MakeHString(tile_id)); 99 id.Attach(MakeHString(tile_id));
29 100
30 mswr::ComPtr<winui::StartScreen::ISecondaryTile> tile; 101 mswr::ComPtr<winui::StartScreen::ISecondaryTile> tile;
31 hr = tile_factory->CreateWithId(id.Get(), tile.GetAddressOf()); 102 hr = tile_factory->CreateWithId(id.Get(), tile.GetAddressOf());
32 CheckHR(hr, "Failed to create tile"); 103 CheckHR(hr, "Failed to create tile");
33 104
34 mswr::ComPtr<winfoundtn::IAsyncOperation<bool>> completion; 105 mswr::ComPtr<winfoundtn::IAsyncOperation<bool>> completion;
35 hr = tile->RequestDeleteAsync(completion.GetAddressOf()); 106 hr = tile->RequestDeleteAsync(completion.GetAddressOf());
36 CheckHR(hr, "RequestDeleteAsync failed"); 107 CheckHR(hr, "RequestDeleteAsync failed");
37 108
38 typedef winfoundtn::IAsyncOperationCompletedHandler<bool> RequestDoneType; 109 if (FAILED(hr)) {
39 mswr::ComPtr<RequestDoneType> handler(mswr::Callback<RequestDoneType>( 110 callback.Run(base::win::METRO_UNPIN_REQUEST_SHOW_ERROR);
40 globals.view, &ChromeAppView::TileRequestCreateDone)); 111 return;
41 DCHECK(handler.Get() != NULL); 112 }
42 hr = completion->put_Completed(handler.Get()); 113
43 CheckHR(hr, "Failed to put_Completed"); 114 // Deleted in TileRequestDone::Respond when the async operation completes.
115 (new TileRequestDone(TileRequestDone::UNPIN,
116 callback))->Complete(completion);
44 } 117 }
45 118
46 void CreateTileOnStartScreen(const string16& tile_id, 119 void CreateTileOnStartScreen(const string16& tile_id,
47 const string16& title_str, 120 const string16& title_str,
48 const string16& url_str, 121 const string16& url_str,
49 const FilePath& logo_path) { 122 const FilePath& logo_path,
123 const MetroPinUmaResultCallback& callback) {
50 VLOG(1) << __FUNCTION__; 124 VLOG(1) << __FUNCTION__;
51 125
52 mswr::ComPtr<winui::StartScreen::ISecondaryTileFactory> tile_factory; 126 mswr::ComPtr<winui::StartScreen::ISecondaryTileFactory> tile_factory;
53 HRESULT hr = winrt_utils::CreateActivationFactory( 127 HRESULT hr = winrt_utils::CreateActivationFactory(
54 RuntimeClass_Windows_UI_StartScreen_SecondaryTile, 128 RuntimeClass_Windows_UI_StartScreen_SecondaryTile,
55 tile_factory.GetAddressOf()); 129 tile_factory.GetAddressOf());
56 CheckHR(hr, "Failed to create instance of ISecondaryTileFactory"); 130 CheckHR(hr, "Failed to create instance of ISecondaryTileFactory");
57 131
58 winui::StartScreen::TileOptions options = 132 winui::StartScreen::TileOptions options =
59 winui::StartScreen::TileOptions_ShowNameOnLogo; 133 winui::StartScreen::TileOptions_ShowNameOnLogo;
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 tile.GetAddressOf()); 166 tile.GetAddressOf());
93 CheckHR(hr, "Failed to create tile"); 167 CheckHR(hr, "Failed to create tile");
94 168
95 hr = tile->put_ForegroundText(winui::StartScreen::ForegroundText_Light); 169 hr = tile->put_ForegroundText(winui::StartScreen::ForegroundText_Light);
96 CheckHR(hr, "Failed to change foreground text color"); 170 CheckHR(hr, "Failed to change foreground text color");
97 171
98 mswr::ComPtr<winfoundtn::IAsyncOperation<bool>> completion; 172 mswr::ComPtr<winfoundtn::IAsyncOperation<bool>> completion;
99 hr = tile->RequestCreateAsync(completion.GetAddressOf()); 173 hr = tile->RequestCreateAsync(completion.GetAddressOf());
100 CheckHR(hr, "RequestCreateAsync failed"); 174 CheckHR(hr, "RequestCreateAsync failed");
101 175
102 typedef winfoundtn::IAsyncOperationCompletedHandler<bool> RequestDoneType; 176 if (FAILED(hr)) {
103 mswr::ComPtr<RequestDoneType> handler(mswr::Callback<RequestDoneType>( 177 callback.Run(base::win::METRO_PIN_REQUEST_SHOW_ERROR);
104 globals.view, &ChromeAppView::TileRequestCreateDone)); 178 return;
105 DCHECK(handler.Get() != NULL); 179 }
106 hr = completion->put_Completed(handler.Get()); 180
107 CheckHR(hr, "Failed to put_Completed"); 181 // Deleted in TileRequestDone::Respond when the async operation completes.
182 (new TileRequestDone(TileRequestDone::PIN,
benwells 2012/11/30 01:16:47 Since this is over two lines anyway, can you intro
tapted 2012/11/30 05:54:19 Done.
183 callback))->Complete(completion);
108 } 184 }
109 185
110 } // namespace 186 } // namespace
111 187
112 BOOL MetroIsPinnedToStartScreen(const string16& tile_id) { 188 BOOL MetroIsPinnedToStartScreen(const string16& tile_id) {
113 mswr::ComPtr<winui::StartScreen::ISecondaryTileStatics> tile_statics; 189 mswr::ComPtr<winui::StartScreen::ISecondaryTileStatics> tile_statics;
114 HRESULT hr = winrt_utils::CreateActivationFactory( 190 HRESULT hr = winrt_utils::CreateActivationFactory(
115 RuntimeClass_Windows_UI_StartScreen_SecondaryTile, 191 RuntimeClass_Windows_UI_StartScreen_SecondaryTile,
116 tile_statics.GetAddressOf()); 192 tile_statics.GetAddressOf());
117 CheckHR(hr, "Failed to create instance of ISecondaryTileStatics"); 193 CheckHR(hr, "Failed to create instance of ISecondaryTileStatics");
118 194
119 boolean exists; 195 boolean exists;
120 hr = tile_statics->Exists(MakeHString(tile_id), &exists); 196 hr = tile_statics->Exists(MakeHString(tile_id), &exists);
121 CheckHR(hr, "ISecondaryTileStatics.Exists failed"); 197 CheckHR(hr, "ISecondaryTileStatics.Exists failed");
122 return exists; 198 return exists;
123 } 199 }
124 200
125 void MetroUnPinFromStartScreen(const string16& tile_id) { 201 void MetroUnPinFromStartScreen(const string16& tile_id,
202 const MetroPinUmaResultCallback& callback) {
126 globals.appview_msg_loop->PostTask( 203 globals.appview_msg_loop->PostTask(
127 FROM_HERE, base::Bind(&DeleteTileFromStartScreen, tile_id)); 204 FROM_HERE, base::Bind(&DeleteTileFromStartScreen,
205 tile_id,
206 callback));
128 } 207 }
129 208
130 void MetroPinToStartScreen(const string16& tile_id, 209 void MetroPinToStartScreen(const string16& tile_id,
131 const string16& title, 210 const string16& title,
132 const string16& url, 211 const string16& url,
133 const FilePath& logo_path) { 212 const FilePath& logo_path,
213 const MetroPinUmaResultCallback& callback) {
134 globals.appview_msg_loop->PostTask( 214 globals.appview_msg_loop->PostTask(
135 FROM_HERE, base::Bind(&CreateTileOnStartScreen, 215 FROM_HERE, base::Bind(&CreateTileOnStartScreen,
136 tile_id, 216 tile_id,
137 title, 217 title,
138 url, 218 url,
139 logo_path)); 219 logo_path,
220 callback));
140 } 221 }
OLDNEW
« win8/metro_driver/chrome_app_view.cc ('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