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

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: **fails presubmit** make secondary_tile_types.h, +review 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 // Callback for asynchronous pin requests.
20 class TileRequestDone {
21 public:
22 enum PinType {
23 PIN,
24 UNPIN
25 };
26 TileRequestDone(PinType type, win8::MetroPinResultCallback callback)
27 : type_(type), callback_(callback) {}
28
29 void Complete(mswr::ComPtr<winfoundtn::IAsyncOperation<bool>>& completion);
30
31 private:
32 HRESULT Respond(winfoundtn::IAsyncOperation<bool>* async,
33 AsyncStatus status);
34
35 PinType type_;
36 win8::MetroPinResultCallback callback_;
37 };
38
39 void TileRequestDone::Complete(
40 mswr::ComPtr<winfoundtn::IAsyncOperation<bool>>& completion) {
41 typedef winfoundtn::IAsyncOperationCompletedHandler<bool> RequestDoneType;
42 mswr::ComPtr<RequestDoneType> handler(mswr::Callback<RequestDoneType>(
43 this, &TileRequestDone::Respond));
44 DCHECK(handler.Get() != NULL);
45 HRESULT hr = completion->put_Completed(handler.Get());
46 CheckHR(hr, "Failed to put_Completed");
47 }
48
49 HRESULT TileRequestDone::Respond(winfoundtn::IAsyncOperation<bool>* async,
50 AsyncStatus status) {
51 win8::MetroSecondaryTilePinState pin_state = win8::METRO_PIN_STATE_NONE;
52
53 if (status == Completed) {
54 unsigned char result;
55 CheckHR(async->GetResults(&result));
56 LOG(INFO) << __FUNCTION__ << " result " << static_cast<int>(result);
57 switch (result) {
58 case 0:
59 pin_state = type_ == PIN ?
60 win8::METRO_PIN_RESULT_CANCEL :
61 win8::METRO_UNPIN_RESULT_CANCEL;
62 break;
63 case 1:
64 pin_state = type_ == PIN ?
65 win8::METRO_PIN_RESULT_OK :
66 win8::METRO_UNPIN_RESULT_OK;
67 break;
68 default:
69 pin_state = type_ == PIN ?
70 win8::METRO_PIN_RESULT_OTHER :
71 win8::METRO_UNPIN_RESULT_OTHER;
72 break;
73 }
74 } else {
75 LOG(ERROR) << __FUNCTION__ << " Unexpected async status " << status;
76 pin_state = type_ == PIN ?
77 win8::METRO_PIN_RESULT_ERROR :
78 win8::METRO_UNPIN_RESULT_ERROR;
79 }
80 callback_.Run(pin_state);
81
82 delete this;
83 return S_OK;
84 }
85
86 void DeleteTileFromStartScreen(const string16& tile_id,
87 win8::MetroPinResultCallback callback) {
20 DVLOG(1) << __FUNCTION__; 88 DVLOG(1) << __FUNCTION__;
21 mswr::ComPtr<winui::StartScreen::ISecondaryTileFactory> tile_factory; 89 mswr::ComPtr<winui::StartScreen::ISecondaryTileFactory> tile_factory;
22 HRESULT hr = winrt_utils::CreateActivationFactory( 90 HRESULT hr = winrt_utils::CreateActivationFactory(
23 RuntimeClass_Windows_UI_StartScreen_SecondaryTile, 91 RuntimeClass_Windows_UI_StartScreen_SecondaryTile,
24 tile_factory.GetAddressOf()); 92 tile_factory.GetAddressOf());
25 CheckHR(hr, "Failed to create instance of ISecondaryTileFactory"); 93 CheckHR(hr, "Failed to create instance of ISecondaryTileFactory");
26 94
27 mswrw::HString id; 95 mswrw::HString id;
28 id.Attach(MakeHString(tile_id)); 96 id.Attach(MakeHString(tile_id));
29 97
30 mswr::ComPtr<winui::StartScreen::ISecondaryTile> tile; 98 mswr::ComPtr<winui::StartScreen::ISecondaryTile> tile;
31 hr = tile_factory->CreateWithId(id.Get(), tile.GetAddressOf()); 99 hr = tile_factory->CreateWithId(id.Get(), tile.GetAddressOf());
32 CheckHR(hr, "Failed to create tile"); 100 CheckHR(hr, "Failed to create tile");
33 101
34 mswr::ComPtr<winfoundtn::IAsyncOperation<bool>> completion; 102 mswr::ComPtr<winfoundtn::IAsyncOperation<bool>> completion;
35 hr = tile->RequestDeleteAsync(completion.GetAddressOf()); 103 hr = tile->RequestDeleteAsync(completion.GetAddressOf());
36 CheckHR(hr, "RequestDeleteAsync failed"); 104 CheckHR(hr, "RequestDeleteAsync failed");
37 105
38 typedef winfoundtn::IAsyncOperationCompletedHandler<bool> RequestDoneType; 106 if (FAILED(hr)) {
39 mswr::ComPtr<RequestDoneType> handler(mswr::Callback<RequestDoneType>( 107 callback.Run(win8::METRO_UNPIN_REQUEST_SHOW_ERROR);
40 globals.view, &ChromeAppView::TileRequestCreateDone)); 108 return;
41 DCHECK(handler.Get() != NULL); 109 }
42 hr = completion->put_Completed(handler.Get()); 110
43 CheckHR(hr, "Failed to put_Completed"); 111 // Deleted in TileRequestDone::Respond when the async operation completes.
112 (new TileRequestDone(TileRequestDone::UNPIN,
113 callback))->Complete(completion);
44 } 114 }
45 115
46 void CreateTileOnStartScreen(const string16& tile_id, 116 void CreateTileOnStartScreen(const string16& tile_id,
47 const string16& title_str, 117 const string16& title_str,
48 const string16& url_str, 118 const string16& url_str,
49 const FilePath& logo_path) { 119 const FilePath& logo_path,
120 win8::MetroPinResultCallback callback) {
50 VLOG(1) << __FUNCTION__; 121 VLOG(1) << __FUNCTION__;
51 122
52 mswr::ComPtr<winui::StartScreen::ISecondaryTileFactory> tile_factory; 123 mswr::ComPtr<winui::StartScreen::ISecondaryTileFactory> tile_factory;
53 HRESULT hr = winrt_utils::CreateActivationFactory( 124 HRESULT hr = winrt_utils::CreateActivationFactory(
54 RuntimeClass_Windows_UI_StartScreen_SecondaryTile, 125 RuntimeClass_Windows_UI_StartScreen_SecondaryTile,
55 tile_factory.GetAddressOf()); 126 tile_factory.GetAddressOf());
56 CheckHR(hr, "Failed to create instance of ISecondaryTileFactory"); 127 CheckHR(hr, "Failed to create instance of ISecondaryTileFactory");
57 128
58 winui::StartScreen::TileOptions options = 129 winui::StartScreen::TileOptions options =
59 winui::StartScreen::TileOptions_ShowNameOnLogo; 130 winui::StartScreen::TileOptions_ShowNameOnLogo;
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 tile.GetAddressOf()); 163 tile.GetAddressOf());
93 CheckHR(hr, "Failed to create tile"); 164 CheckHR(hr, "Failed to create tile");
94 165
95 hr = tile->put_ForegroundText(winui::StartScreen::ForegroundText_Light); 166 hr = tile->put_ForegroundText(winui::StartScreen::ForegroundText_Light);
96 CheckHR(hr, "Failed to change foreground text color"); 167 CheckHR(hr, "Failed to change foreground text color");
97 168
98 mswr::ComPtr<winfoundtn::IAsyncOperation<bool>> completion; 169 mswr::ComPtr<winfoundtn::IAsyncOperation<bool>> completion;
99 hr = tile->RequestCreateAsync(completion.GetAddressOf()); 170 hr = tile->RequestCreateAsync(completion.GetAddressOf());
100 CheckHR(hr, "RequestCreateAsync failed"); 171 CheckHR(hr, "RequestCreateAsync failed");
101 172
102 typedef winfoundtn::IAsyncOperationCompletedHandler<bool> RequestDoneType; 173 if (FAILED(hr)) {
103 mswr::ComPtr<RequestDoneType> handler(mswr::Callback<RequestDoneType>( 174 callback.Run(win8::METRO_PIN_REQUEST_SHOW_ERROR);
104 globals.view, &ChromeAppView::TileRequestCreateDone)); 175 return;
105 DCHECK(handler.Get() != NULL); 176 }
106 hr = completion->put_Completed(handler.Get()); 177
107 CheckHR(hr, "Failed to put_Completed"); 178 // Deleted in TileRequestDone::Respond when the async operation completes.
179 (new TileRequestDone(TileRequestDone::PIN,
180 callback))->Complete(completion);
108 } 181 }
109 182
110 } // namespace 183 } // namespace
111 184
112 BOOL MetroIsPinnedToStartScreen(const string16& tile_id) { 185 BOOL MetroIsPinnedToStartScreen(const string16& tile_id) {
113 mswr::ComPtr<winui::StartScreen::ISecondaryTileStatics> tile_statics; 186 mswr::ComPtr<winui::StartScreen::ISecondaryTileStatics> tile_statics;
114 HRESULT hr = winrt_utils::CreateActivationFactory( 187 HRESULT hr = winrt_utils::CreateActivationFactory(
115 RuntimeClass_Windows_UI_StartScreen_SecondaryTile, 188 RuntimeClass_Windows_UI_StartScreen_SecondaryTile,
116 tile_statics.GetAddressOf()); 189 tile_statics.GetAddressOf());
117 CheckHR(hr, "Failed to create instance of ISecondaryTileStatics"); 190 CheckHR(hr, "Failed to create instance of ISecondaryTileStatics");
118 191
119 boolean exists; 192 boolean exists;
120 hr = tile_statics->Exists(MakeHString(tile_id), &exists); 193 hr = tile_statics->Exists(MakeHString(tile_id), &exists);
121 CheckHR(hr, "ISecondaryTileStatics.Exists failed"); 194 CheckHR(hr, "ISecondaryTileStatics.Exists failed");
122 return exists; 195 return exists;
123 } 196 }
124 197
125 void MetroUnPinFromStartScreen(const string16& tile_id) { 198 void MetroUnPinFromStartScreen(const string16& tile_id,
199 win8::MetroPinResultCallback callback) {
200 // 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
126 globals.appview_msg_loop->PostTask( 201 globals.appview_msg_loop->PostTask(
127 FROM_HERE, base::Bind(&DeleteTileFromStartScreen, tile_id)); 202 FROM_HERE, base::Bind(&DeleteTileFromStartScreen,
203 tile_id,
204 callback));
128 } 205 }
129 206
130 void MetroPinToStartScreen(const string16& tile_id, 207 void MetroPinToStartScreen(const string16& tile_id,
131 const string16& title, 208 const string16& title,
132 const string16& url, 209 const string16& url,
133 const FilePath& logo_path) { 210 const FilePath& logo_path,
211 win8::MetroPinResultCallback callback) {
134 globals.appview_msg_loop->PostTask( 212 globals.appview_msg_loop->PostTask(
135 FROM_HERE, base::Bind(&CreateTileOnStartScreen, 213 FROM_HERE, base::Bind(&CreateTileOnStartScreen,
136 tile_id, 214 tile_id,
137 title, 215 title,
138 url, 216 url,
139 logo_path)); 217 logo_path,
218 callback));
140 } 219 }
OLDNEW
« win8/metro_driver/metro_driver.gyp ('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