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

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: 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
« base/win/metro.h ('K') | « win8/metro_driver/secondary_tile.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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, base::win::MetroPinResultCallback callback)
27 : type_(type), callback_(callback) {
28 }
benwells 2012/11/29 04:19:46 Blank line after. Can have {} on one line.
tapted 2012/11/29 07:19:27 Done.
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 base::win::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 base::win::MetroSecondaryTilePinState pin_state =
52 base::win::METRO_PIN_STATE_NONE;
53
54 if (status == Completed) {
55 unsigned char result;
56 CheckHR(async->GetResults(&result));
57 LOG(INFO) << __FUNCTION__ << " result " << static_cast<int>(result);
58 switch (result) {
59 case 0:
60 pin_state = type_ == PIN ?
61 base::win::METRO_PIN_RESULT_CANCEL :
62 base::win::METRO_UNPIN_RESULT_CANCEL;
63 break;
64 case 1:
65 pin_state = type_ == PIN ?
66 base::win::METRO_PIN_RESULT_OK :
67 base::win::METRO_UNPIN_RESULT_OK;
68 break;
69 default:
70 pin_state = type_ == PIN ?
71 base::win::METRO_PIN_RESULT_OTHER :
72 base::win::METRO_UNPIN_RESULT_OTHER;
73 break;
74 }
75 } else {
76 LOG(ERROR) << __FUNCTION__ << " Unexpected async status " << status;
77 pin_state = type_ == PIN ?
78 base::win::METRO_PIN_RESULT_ERROR :
79 base::win::METRO_UNPIN_RESULT_ERROR;
80 }
81 if (callback_)
82 callback_(pin_state);
83
84 delete this;
85 return S_OK;
86 }
87
88 void DeleteTileFromStartScreen(const string16& tile_id,
89 base::win::MetroPinResultCallback callback) {
20 DVLOG(1) << __FUNCTION__; 90 DVLOG(1) << __FUNCTION__;
21 mswr::ComPtr<winui::StartScreen::ISecondaryTileFactory> tile_factory; 91 mswr::ComPtr<winui::StartScreen::ISecondaryTileFactory> tile_factory;
22 HRESULT hr = winrt_utils::CreateActivationFactory( 92 HRESULT hr = winrt_utils::CreateActivationFactory(
23 RuntimeClass_Windows_UI_StartScreen_SecondaryTile, 93 RuntimeClass_Windows_UI_StartScreen_SecondaryTile,
24 tile_factory.GetAddressOf()); 94 tile_factory.GetAddressOf());
25 CheckHR(hr, "Failed to create instance of ISecondaryTileFactory"); 95 CheckHR(hr, "Failed to create instance of ISecondaryTileFactory");
26 96
27 mswrw::HString id; 97 mswrw::HString id;
28 id.Attach(MakeHString(tile_id)); 98 id.Attach(MakeHString(tile_id));
29 99
30 mswr::ComPtr<winui::StartScreen::ISecondaryTile> tile; 100 mswr::ComPtr<winui::StartScreen::ISecondaryTile> tile;
31 hr = tile_factory->CreateWithId(id.Get(), tile.GetAddressOf()); 101 hr = tile_factory->CreateWithId(id.Get(), tile.GetAddressOf());
32 CheckHR(hr, "Failed to create tile"); 102 CheckHR(hr, "Failed to create tile");
33 103
34 mswr::ComPtr<winfoundtn::IAsyncOperation<bool>> completion; 104 mswr::ComPtr<winfoundtn::IAsyncOperation<bool>> completion;
35 hr = tile->RequestDeleteAsync(completion.GetAddressOf()); 105 hr = tile->RequestDeleteAsync(completion.GetAddressOf());
36 CheckHR(hr, "RequestDeleteAsync failed"); 106 CheckHR(hr, "RequestDeleteAsync failed");
37 107
38 typedef winfoundtn::IAsyncOperationCompletedHandler<bool> RequestDoneType; 108 if (FAILED(hr)) {
39 mswr::ComPtr<RequestDoneType> handler(mswr::Callback<RequestDoneType>( 109 if (callback)
40 globals.view, &ChromeAppView::TileRequestCreateDone)); 110 callback(base::win::METRO_UNPIN_REQUEST_SHOW_ERROR);
41 DCHECK(handler.Get() != NULL); 111 return;
42 hr = completion->put_Completed(handler.Get()); 112 }
43 CheckHR(hr, "Failed to put_Completed"); 113
114 (new TileRequestDone(TileRequestDone::UNPIN,
115 callback))->Complete(completion);
44 } 116 }
45 117
46 void CreateTileOnStartScreen(const string16& tile_id, 118 void CreateTileOnStartScreen(const string16& tile_id,
47 const string16& title_str, 119 const string16& title_str,
48 const string16& url_str, 120 const string16& url_str,
49 const FilePath& logo_path) { 121 const FilePath& logo_path,
122 base::win::MetroPinResultCallback callback) {
50 VLOG(1) << __FUNCTION__; 123 VLOG(1) << __FUNCTION__;
51 124
52 mswr::ComPtr<winui::StartScreen::ISecondaryTileFactory> tile_factory; 125 mswr::ComPtr<winui::StartScreen::ISecondaryTileFactory> tile_factory;
53 HRESULT hr = winrt_utils::CreateActivationFactory( 126 HRESULT hr = winrt_utils::CreateActivationFactory(
54 RuntimeClass_Windows_UI_StartScreen_SecondaryTile, 127 RuntimeClass_Windows_UI_StartScreen_SecondaryTile,
55 tile_factory.GetAddressOf()); 128 tile_factory.GetAddressOf());
56 CheckHR(hr, "Failed to create instance of ISecondaryTileFactory"); 129 CheckHR(hr, "Failed to create instance of ISecondaryTileFactory");
57 130
58 winui::StartScreen::TileOptions options = 131 winui::StartScreen::TileOptions options =
59 winui::StartScreen::TileOptions_ShowNameOnLogo; 132 winui::StartScreen::TileOptions_ShowNameOnLogo;
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 tile.GetAddressOf()); 165 tile.GetAddressOf());
93 CheckHR(hr, "Failed to create tile"); 166 CheckHR(hr, "Failed to create tile");
94 167
95 hr = tile->put_ForegroundText(winui::StartScreen::ForegroundText_Light); 168 hr = tile->put_ForegroundText(winui::StartScreen::ForegroundText_Light);
96 CheckHR(hr, "Failed to change foreground text color"); 169 CheckHR(hr, "Failed to change foreground text color");
97 170
98 mswr::ComPtr<winfoundtn::IAsyncOperation<bool>> completion; 171 mswr::ComPtr<winfoundtn::IAsyncOperation<bool>> completion;
99 hr = tile->RequestCreateAsync(completion.GetAddressOf()); 172 hr = tile->RequestCreateAsync(completion.GetAddressOf());
100 CheckHR(hr, "RequestCreateAsync failed"); 173 CheckHR(hr, "RequestCreateAsync failed");
101 174
102 typedef winfoundtn::IAsyncOperationCompletedHandler<bool> RequestDoneType; 175 if (FAILED(hr)) {
103 mswr::ComPtr<RequestDoneType> handler(mswr::Callback<RequestDoneType>( 176 if (callback)
104 globals.view, &ChromeAppView::TileRequestCreateDone)); 177 callback(base::win::METRO_PIN_REQUEST_SHOW_ERROR);
105 DCHECK(handler.Get() != NULL); 178 return;
106 hr = completion->put_Completed(handler.Get()); 179 }
107 CheckHR(hr, "Failed to put_Completed"); 180
181 (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.
182 callback))->Complete(completion);
108 } 183 }
109 184
110 } // namespace 185 } // namespace
111 186
112 BOOL MetroIsPinnedToStartScreen(const string16& tile_id) { 187 BOOL MetroIsPinnedToStartScreen(const string16& tile_id) {
113 mswr::ComPtr<winui::StartScreen::ISecondaryTileStatics> tile_statics; 188 mswr::ComPtr<winui::StartScreen::ISecondaryTileStatics> tile_statics;
114 HRESULT hr = winrt_utils::CreateActivationFactory( 189 HRESULT hr = winrt_utils::CreateActivationFactory(
115 RuntimeClass_Windows_UI_StartScreen_SecondaryTile, 190 RuntimeClass_Windows_UI_StartScreen_SecondaryTile,
116 tile_statics.GetAddressOf()); 191 tile_statics.GetAddressOf());
117 CheckHR(hr, "Failed to create instance of ISecondaryTileStatics"); 192 CheckHR(hr, "Failed to create instance of ISecondaryTileStatics");
118 193
119 boolean exists; 194 boolean exists;
120 hr = tile_statics->Exists(MakeHString(tile_id), &exists); 195 hr = tile_statics->Exists(MakeHString(tile_id), &exists);
121 CheckHR(hr, "ISecondaryTileStatics.Exists failed"); 196 CheckHR(hr, "ISecondaryTileStatics.Exists failed");
122 return exists; 197 return exists;
123 } 198 }
124 199
125 void MetroUnPinFromStartScreen(const string16& tile_id) { 200 void MetroUnPinFromStartScreen(const string16& tile_id,
201 base::win::MetroPinResultCallback callback) {
202 // Ensure function signature is correct.
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 base::win::MetroPinResultCallback 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
« 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