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

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: no longer need to share this histogram name constant 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(mswr::ComPtr<winfoundtn::IAsyncOperation<bool>>& completion,
27 PinType type,
28 base::win::MetroPinResultCallback callback,
29 void* callback_data)
30 : type_(type), callback_(callback), callback_data_(callback_data) {
benwells 2012/11/27 08:56:39 Nit: indenting here is off. THe : should line up w
tapted 2012/11/28 00:33:43 Done.
31 typedef winfoundtn::IAsyncOperationCompletedHandler<bool> RequestDoneType;
32 mswr::ComPtr<RequestDoneType> handler(mswr::Callback<RequestDoneType>(
benwells 2012/11/27 08:56:39 Can you move this logic into another function? It
tapted 2012/11/28 00:33:43 Done.
33 this, &TileRequestDone::respond));
34 DCHECK(handler.Get() != NULL);
35 HRESULT hr = completion->put_Completed(handler.Get());
36 CheckHR(hr, "Failed to put_Completed");
37 }
38
39 private:
40 HRESULT respond(winfoundtn::IAsyncOperation<bool>* async,
41 AsyncStatus status);
42
43 PinType type_;
44 base::win::MetroPinResultCallback callback_;
45 void* callback_data_;
46 };
47
48 HRESULT TileRequestDone::respond(winfoundtn::IAsyncOperation<bool>* async,
benwells 2012/11/27 08:56:39 Is there a reason to have the constructor inline a
tapted 2012/11/28 00:33:43 No particular reason. (It met the style guide :) -
49 AsyncStatus status) {
50 PinType type = type_;
51 base::win::MetroPinResultCallback callback = callback_;
52 void* callback_data = callback_data_;
53 delete this;
benwells 2012/11/27 08:56:39 Hmm. I assume there is some reason to copy the mem
tapted 2012/11/28 00:33:43 Just defensive programming - more from a mindset l
54
55 base::win::MetroSecondaryTilePinState pin_state =
56 base::win::METRO_PIN_STATE_NONE;
57
58 if (status == Completed) {
59 unsigned char result;
60 CheckHR(async->GetResults(&result));
61 LOG(INFO) << __FUNCTION__ << " result " << static_cast<int>(result);
62 switch (result) {
63 case 0:
64 pin_state = type == PIN ?
65 base::win::METRO_PIN_RESULT_CANCEL :
66 base::win::METRO_UNPIN_RESULT_CANCEL;
67 break;
68 case 1:
69 pin_state = type == PIN ?
70 base::win::METRO_PIN_RESULT_OK :
71 base::win::METRO_UNPIN_RESULT_OK;
72 break;
73 default:
74 pin_state = type == PIN ?
75 base::win::METRO_PIN_RESULT_OTHER :
76 base::win::METRO_UNPIN_RESULT_OTHER;
77 break;
78 }
79 } else {
80 LOG(ERROR) << __FUNCTION__ << " Unexpected async status " << status;
81 pin_state = type == PIN ?
82 base::win::METRO_PIN_RESULT_ERROR :
83 base::win::METRO_UNPIN_RESULT_ERROR;
84 }
85 if (callback)
86 callback(callback_data, pin_state);
87
88 return S_OK;
89 }
90
91 void DeleteTileFromStartScreen(const string16& tile_id,
92 base::win::MetroPinResultCallback callback,
93 void* callback_data) {
20 DVLOG(1) << __FUNCTION__; 94 DVLOG(1) << __FUNCTION__;
21 mswr::ComPtr<winui::StartScreen::ISecondaryTileFactory> tile_factory; 95 mswr::ComPtr<winui::StartScreen::ISecondaryTileFactory> tile_factory;
22 HRESULT hr = winrt_utils::CreateActivationFactory( 96 HRESULT hr = winrt_utils::CreateActivationFactory(
23 RuntimeClass_Windows_UI_StartScreen_SecondaryTile, 97 RuntimeClass_Windows_UI_StartScreen_SecondaryTile,
24 tile_factory.GetAddressOf()); 98 tile_factory.GetAddressOf());
25 CheckHR(hr, "Failed to create instance of ISecondaryTileFactory"); 99 CheckHR(hr, "Failed to create instance of ISecondaryTileFactory");
26 100
27 mswrw::HString id; 101 mswrw::HString id;
28 id.Attach(MakeHString(tile_id)); 102 id.Attach(MakeHString(tile_id));
29 103
30 mswr::ComPtr<winui::StartScreen::ISecondaryTile> tile; 104 mswr::ComPtr<winui::StartScreen::ISecondaryTile> tile;
31 hr = tile_factory->CreateWithId(id.Get(), tile.GetAddressOf()); 105 hr = tile_factory->CreateWithId(id.Get(), tile.GetAddressOf());
32 CheckHR(hr, "Failed to create tile"); 106 CheckHR(hr, "Failed to create tile");
33 107
34 mswr::ComPtr<winfoundtn::IAsyncOperation<bool>> completion; 108 mswr::ComPtr<winfoundtn::IAsyncOperation<bool>> completion;
35 hr = tile->RequestDeleteAsync(completion.GetAddressOf()); 109 hr = tile->RequestDeleteAsync(completion.GetAddressOf());
36 CheckHR(hr, "RequestDeleteAsync failed"); 110 CheckHR(hr, "RequestDeleteAsync failed");
37 111
38 typedef winfoundtn::IAsyncOperationCompletedHandler<bool> RequestDoneType; 112 if (FAILED(hr)) {
39 mswr::ComPtr<RequestDoneType> handler(mswr::Callback<RequestDoneType>( 113 if (callback)
40 globals.view, &ChromeAppView::TileRequestCreateDone)); 114 callback(callback_data, base::win::METRO_UNPIN_REQUEST_SHOW_ERROR);
41 DCHECK(handler.Get() != NULL); 115 return;
42 hr = completion->put_Completed(handler.Get()); 116 }
43 CheckHR(hr, "Failed to put_Completed"); 117
118 new TileRequestDone(completion,
119 TileRequestDone::UNPIN,
120 callback,
121 callback_data);
44 } 122 }
45 123
46 void CreateTileOnStartScreen(const string16& tile_id, 124 void CreateTileOnStartScreen(const string16& tile_id,
47 const string16& title_str, 125 const string16& title_str,
48 const string16& url_str, 126 const string16& url_str,
49 const FilePath& logo_path) { 127 const FilePath& logo_path,
128 base::win::MetroPinResultCallback callback,
129 void* callback_data) {
50 VLOG(1) << __FUNCTION__; 130 VLOG(1) << __FUNCTION__;
51 131
52 mswr::ComPtr<winui::StartScreen::ISecondaryTileFactory> tile_factory; 132 mswr::ComPtr<winui::StartScreen::ISecondaryTileFactory> tile_factory;
53 HRESULT hr = winrt_utils::CreateActivationFactory( 133 HRESULT hr = winrt_utils::CreateActivationFactory(
54 RuntimeClass_Windows_UI_StartScreen_SecondaryTile, 134 RuntimeClass_Windows_UI_StartScreen_SecondaryTile,
55 tile_factory.GetAddressOf()); 135 tile_factory.GetAddressOf());
56 CheckHR(hr, "Failed to create instance of ISecondaryTileFactory"); 136 CheckHR(hr, "Failed to create instance of ISecondaryTileFactory");
57 137
58 winui::StartScreen::TileOptions options = 138 winui::StartScreen::TileOptions options =
59 winui::StartScreen::TileOptions_ShowNameOnLogo; 139 winui::StartScreen::TileOptions_ShowNameOnLogo;
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 tile.GetAddressOf()); 172 tile.GetAddressOf());
93 CheckHR(hr, "Failed to create tile"); 173 CheckHR(hr, "Failed to create tile");
94 174
95 hr = tile->put_ForegroundText(winui::StartScreen::ForegroundText_Light); 175 hr = tile->put_ForegroundText(winui::StartScreen::ForegroundText_Light);
96 CheckHR(hr, "Failed to change foreground text color"); 176 CheckHR(hr, "Failed to change foreground text color");
97 177
98 mswr::ComPtr<winfoundtn::IAsyncOperation<bool>> completion; 178 mswr::ComPtr<winfoundtn::IAsyncOperation<bool>> completion;
99 hr = tile->RequestCreateAsync(completion.GetAddressOf()); 179 hr = tile->RequestCreateAsync(completion.GetAddressOf());
100 CheckHR(hr, "RequestCreateAsync failed"); 180 CheckHR(hr, "RequestCreateAsync failed");
101 181
102 typedef winfoundtn::IAsyncOperationCompletedHandler<bool> RequestDoneType; 182 if (FAILED(hr)) {
103 mswr::ComPtr<RequestDoneType> handler(mswr::Callback<RequestDoneType>( 183 if (callback)
104 globals.view, &ChromeAppView::TileRequestCreateDone)); 184 callback(callback_data, base::win::METRO_PIN_REQUEST_SHOW_ERROR);
105 DCHECK(handler.Get() != NULL); 185 return;
106 hr = completion->put_Completed(handler.Get()); 186 }
107 CheckHR(hr, "Failed to put_Completed"); 187
188 new TileRequestDone(completion,
189 TileRequestDone::PIN,
190 callback,
191 callback_data);
108 } 192 }
109 193
110 } // namespace 194 } // namespace
111 195
112 BOOL MetroIsPinnedToStartScreen(const string16& tile_id) { 196 BOOL MetroIsPinnedToStartScreen(const string16& tile_id) {
113 mswr::ComPtr<winui::StartScreen::ISecondaryTileStatics> tile_statics; 197 mswr::ComPtr<winui::StartScreen::ISecondaryTileStatics> tile_statics;
114 HRESULT hr = winrt_utils::CreateActivationFactory( 198 HRESULT hr = winrt_utils::CreateActivationFactory(
115 RuntimeClass_Windows_UI_StartScreen_SecondaryTile, 199 RuntimeClass_Windows_UI_StartScreen_SecondaryTile,
116 tile_statics.GetAddressOf()); 200 tile_statics.GetAddressOf());
117 CheckHR(hr, "Failed to create instance of ISecondaryTileStatics"); 201 CheckHR(hr, "Failed to create instance of ISecondaryTileStatics");
118 202
119 boolean exists; 203 boolean exists;
120 hr = tile_statics->Exists(MakeHString(tile_id), &exists); 204 hr = tile_statics->Exists(MakeHString(tile_id), &exists);
121 CheckHR(hr, "ISecondaryTileStatics.Exists failed"); 205 CheckHR(hr, "ISecondaryTileStatics.Exists failed");
122 return exists; 206 return exists;
123 } 207 }
124 208
125 void MetroUnPinFromStartScreen(const string16& tile_id) { 209 void MetroUnPinFromStartScreen(const string16& tile_id,
210 base::win::MetroPinResultCallback callback,
211 void* callback_data) {
212 // Ensure function signature is correct.
213 base::win::MetroUnPinFromStartScreen check = &MetroUnPinFromStartScreen;
benwells 2012/11/27 08:56:39 Um ... I haven't seen anything like this in chrome
tapted 2012/11/28 00:33:43 In a unit test it would only check the prototype d
214 (void)check;
215
126 globals.appview_msg_loop->PostTask( 216 globals.appview_msg_loop->PostTask(
127 FROM_HERE, base::Bind(&DeleteTileFromStartScreen, tile_id)); 217 FROM_HERE, base::Bind(&DeleteTileFromStartScreen,
218 tile_id,
219 callback,
220 callback_data));
128 } 221 }
129 222
130 void MetroPinToStartScreen(const string16& tile_id, 223 void MetroPinToStartScreen(const string16& tile_id,
131 const string16& title, 224 const string16& title,
132 const string16& url, 225 const string16& url,
133 const FilePath& logo_path) { 226 const FilePath& logo_path,
227 base::win::MetroPinResultCallback callback,
228 void* callback_data) {
229 base::win::MetroPinToStartScreen check = &MetroPinToStartScreen;
230 (void)check;
231
134 globals.appview_msg_loop->PostTask( 232 globals.appview_msg_loop->PostTask(
135 FROM_HERE, base::Bind(&CreateTileOnStartScreen, 233 FROM_HERE, base::Bind(&CreateTileOnStartScreen,
136 tile_id, 234 tile_id,
137 title, 235 title,
138 url, 236 url,
139 logo_path)); 237 logo_path,
238 callback,
239 callback_data));
140 } 240 }
OLDNEW
« chrome/browser/ui/metro_pin_tab_helper_win.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