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

Side by Side Diff: chrome/browser/ui/metro_pin_tab_helper_win.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
« no previous file with comments | « no previous file | chrome/chrome_browser_ui.gypi » ('j') | chrome/chrome_browser_ui.gypi » ('J')
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 "chrome/browser/ui/metro_pin_tab_helper_win.h" 5 #include "chrome/browser/ui/metro_pin_tab_helper_win.h"
6 6
7 #include <set> 7 #include <set>
8 8
9 #include "base/base_paths.h" 9 #include "base/base_paths.h"
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/file_path.h" 11 #include "base/file_path.h"
12 #include "base/file_util.h" 12 #include "base/file_util.h"
13 #include "base/logging.h" 13 #include "base/logging.h"
14 #include "base/memory/ref_counted.h" 14 #include "base/memory/ref_counted.h"
15 #include "base/memory/ref_counted_memory.h" 15 #include "base/memory/ref_counted_memory.h"
16 #include "base/metrics/histogram.h"
16 #include "base/path_service.h" 17 #include "base/path_service.h"
17 #include "base/string_number_conversions.h" 18 #include "base/string_number_conversions.h"
18 #include "base/utf_string_conversions.h" 19 #include "base/utf_string_conversions.h"
19 #include "base/win/metro.h" 20 #include "base/win/metro.h"
20 #include "chrome/browser/favicon/favicon_download_helper.h" 21 #include "chrome/browser/favicon/favicon_download_helper.h"
21 #include "chrome/browser/favicon/favicon_tab_helper.h" 22 #include "chrome/browser/favicon/favicon_tab_helper.h"
22 #include "chrome/browser/favicon/favicon_util.h" 23 #include "chrome/browser/favicon/favicon_util.h"
23 #include "chrome/browser/ui/tab_contents/tab_contents.h" 24 #include "chrome/browser/ui/tab_contents/tab_contents.h"
24 #include "chrome/common/chrome_paths.h" 25 #include "chrome/common/chrome_paths.h"
25 #include "chrome/common/icon_messages.h" 26 #include "chrome/common/icon_messages.h"
26 #include "content/public/browser/browser_thread.h" 27 #include "content/public/browser/browser_thread.h"
27 #include "content/public/browser/web_contents.h" 28 #include "content/public/browser/web_contents.h"
28 #include "crypto/sha2.h" 29 #include "crypto/sha2.h"
29 #include "third_party/skia/include/core/SkCanvas.h" 30 #include "third_party/skia/include/core/SkCanvas.h"
30 #include "third_party/skia/include/core/SkColor.h" 31 #include "third_party/skia/include/core/SkColor.h"
31 #include "ui/gfx/canvas.h" 32 #include "ui/gfx/canvas.h"
32 #include "ui/gfx/codec/png_codec.h" 33 #include "ui/gfx/codec/png_codec.h"
33 #include "ui/gfx/color_analysis.h" 34 #include "ui/gfx/color_analysis.h"
34 #include "ui/gfx/color_utils.h" 35 #include "ui/gfx/color_utils.h"
35 #include "ui/gfx/image/image.h" 36 #include "ui/gfx/image/image.h"
36 #include "ui/gfx/rect.h" 37 #include "ui/gfx/rect.h"
37 #include "ui/gfx/size.h" 38 #include "ui/gfx/size.h"
39 #include "win8/metro_driver/secondary_tile_types.h"
38 40
39 DEFINE_WEB_CONTENTS_USER_DATA_KEY(MetroPinTabHelper) 41 DEFINE_WEB_CONTENTS_USER_DATA_KEY(MetroPinTabHelper)
40 42
41 namespace { 43 namespace {
42 44
45 // Histogram name for site-specific tile pinning metrics.
46 const char kMetroPinMetric[] = "Metro.SecondaryTilePin";
47
43 // Generate an ID for the tile based on |url_str|. The ID is simply a hash of 48 // Generate an ID for the tile based on |url_str|. The ID is simply a hash of
44 // the URL. 49 // the URL.
45 string16 GenerateTileId(const string16& url_str) { 50 string16 GenerateTileId(const string16& url_str) {
46 uint8 hash[crypto::kSHA256Length]; 51 uint8 hash[crypto::kSHA256Length];
47 crypto::SHA256HashString(UTF16ToUTF8(url_str), hash, sizeof(hash)); 52 crypto::SHA256HashString(UTF16ToUTF8(url_str), hash, sizeof(hash));
48 std::string hash_str = base::HexEncode(hash, sizeof(hash)); 53 std::string hash_str = base::HexEncode(hash, sizeof(hash));
49 return UTF8ToUTF16(hash_str); 54 return UTF8ToUTF16(hash_str);
50 } 55 }
51 56
52 // Get the path of the directory to store the tile logos in. 57 // Get the path of the directory to store the tile logos in.
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 return true; 156 return true;
152 157
153 FilePath default_logo_path; 158 FilePath default_logo_path;
154 if (!PathService::Get(base::DIR_MODULE, &default_logo_path)) 159 if (!PathService::Get(base::DIR_MODULE, &default_logo_path))
155 return false; 160 return false;
156 161
157 default_logo_path = default_logo_path.Append(kDefaultLogoFileName); 162 default_logo_path = default_logo_path.Append(kDefaultLogoFileName);
158 return file_util::CopyFile(default_logo_path, *logo_path); 163 return file_util::CopyFile(default_logo_path, *logo_path);
159 } 164 }
160 165
166 // UMA reporting callback for site-specific secondary tile creation.
167 void PinPageReportUMACallback(win8::MetroSecondaryTilePinState result) {
168 UMA_HISTOGRAM_ENUMERATION(kMetroPinMetric,
169 result,
170 win8::METRO_PIN_STATE_LIMIT);
171 }
172
161 // The PinPageTaskRunner class performs the necessary FILE thread actions to 173 // The PinPageTaskRunner class performs the necessary FILE thread actions to
162 // pin a page, such as generating or copying the tile image file. When it 174 // pin a page, such as generating or copying the tile image file. When it
163 // has performed these actions it will send the tile creation request to the 175 // has performed these actions it will send the tile creation request to the
164 // metro driver. 176 // metro driver.
165 class PinPageTaskRunner : public base::RefCountedThreadSafe<PinPageTaskRunner> { 177 class PinPageTaskRunner : public base::RefCountedThreadSafe<PinPageTaskRunner> {
166 public: 178 public:
167 // Creates a task runner for the pinning operation with the given details. 179 // Creates a task runner for the pinning operation with the given details.
168 // |favicon| can be a null image (i.e. favicon.isNull() can be true), in 180 // |favicon| can be a null image (i.e. favicon.isNull() can be true), in
169 // which case the backup tile image will be used. 181 // which case the backup tile image will be used.
170 PinPageTaskRunner(const string16& title, 182 PinPageTaskRunner(const string16& title,
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 LOG(ERROR) << "Could not create directory to store tile image."; 223 LOG(ERROR) << "Could not create directory to store tile image.";
212 return; 224 return;
213 } 225 }
214 226
215 FilePath logo_path; 227 FilePath logo_path;
216 if (!CreateSiteSpecificLogo(favicon_, tile_id, logo_dir, &logo_path) && 228 if (!CreateSiteSpecificLogo(favicon_, tile_id, logo_dir, &logo_path) &&
217 !GetPathToBackupLogo(logo_dir, &logo_path)) { 229 !GetPathToBackupLogo(logo_dir, &logo_path)) {
218 LOG(ERROR) << "Count not get path to logo tile."; 230 LOG(ERROR) << "Count not get path to logo tile.";
219 return; 231 return;
220 } 232 }
233 UMA_HISTOGRAM_ENUMERATION(kMetroPinMetric,
234 win8::METRO_PIN_LOGO_READY,
235 win8::METRO_PIN_STATE_LIMIT);
221 236
222 HMODULE metro_module = base::win::GetMetroModule(); 237 HMODULE metro_module = base::win::GetMetroModule();
223 if (!metro_module) 238 if (!metro_module)
224 return; 239 return;
225 240
226 typedef void (*MetroPinToStartScreen)(const string16&, const string16&, 241 win8::MetroPinToStartScreen metro_pin_to_start_screen =
227 const string16&, const FilePath&); 242 reinterpret_cast<win8::MetroPinToStartScreen>(
228 MetroPinToStartScreen metro_pin_to_start_screen =
229 reinterpret_cast<MetroPinToStartScreen>(
230 ::GetProcAddress(metro_module, "MetroPinToStartScreen")); 243 ::GetProcAddress(metro_module, "MetroPinToStartScreen"));
231 if (!metro_pin_to_start_screen) { 244 if (!metro_pin_to_start_screen) {
232 NOTREACHED(); 245 NOTREACHED();
233 return; 246 return;
234 } 247 }
235 248
236 metro_pin_to_start_screen(tile_id, title_, url_, logo_path); 249 metro_pin_to_start_screen(tile_id,
250 title_,
251 url_,
252 logo_path,
253 base::Bind(&PinPageReportUMACallback));
237 } 254 }
238 255
239 } // namespace 256 } // namespace
240 257
241 class MetroPinTabHelper::FaviconChooser { 258 class MetroPinTabHelper::FaviconChooser {
242 public: 259 public:
243 FaviconChooser(MetroPinTabHelper* helper, 260 FaviconChooser(MetroPinTabHelper* helper,
244 const string16& title, 261 const string16& title,
245 const string16& url, 262 const string16& url,
246 const gfx::ImageSkia& history_image); 263 const gfx::ImageSkia& history_image);
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
371 return false; 388 return false;
372 } 389 }
373 390
374 GURL url = web_contents()->GetURL(); 391 GURL url = web_contents()->GetURL();
375 string16 tile_id = GenerateTileId(UTF8ToUTF16(url.spec())); 392 string16 tile_id = GenerateTileId(UTF8ToUTF16(url.spec()));
376 return metro_is_pinned_to_start_screen(tile_id) != 0; 393 return metro_is_pinned_to_start_screen(tile_id) != 0;
377 } 394 }
378 395
379 void MetroPinTabHelper::TogglePinnedToStartScreen() { 396 void MetroPinTabHelper::TogglePinnedToStartScreen() {
380 if (IsPinned()) { 397 if (IsPinned()) {
398 UMA_HISTOGRAM_ENUMERATION(kMetroPinMetric,
399 win8::METRO_UNPIN_INITIATED,
400 win8::METRO_PIN_STATE_LIMIT);
381 UnPinPageFromStartScreen(); 401 UnPinPageFromStartScreen();
382 return; 402 return;
383 } 403 }
384 404
405 UMA_HISTOGRAM_ENUMERATION(kMetroPinMetric,
406 win8::METRO_PIN_INITIATED,
407 win8::METRO_PIN_STATE_LIMIT);
385 GURL url = web_contents()->GetURL(); 408 GURL url = web_contents()->GetURL();
386 string16 url_str = UTF8ToUTF16(url.spec()); 409 string16 url_str = UTF8ToUTF16(url.spec());
387 string16 title = web_contents()->GetTitle(); 410 string16 title = web_contents()->GetTitle();
388 // TODO(oshima): Use scoped_ptr::Pass to pass it to other thread. 411 // TODO(oshima): Use scoped_ptr::Pass to pass it to other thread.
389 gfx::ImageSkia favicon; 412 gfx::ImageSkia favicon;
390 FaviconTabHelper* favicon_tab_helper = FaviconTabHelper::FromWebContents( 413 FaviconTabHelper* favicon_tab_helper = FaviconTabHelper::FromWebContents(
391 web_contents()); 414 web_contents());
392 if (favicon_tab_helper->FaviconIsValid()) 415 if (favicon_tab_helper->FaviconIsValid())
393 favicon = *favicon_tab_helper->GetFavicon().AsImageSkia().DeepCopy().get(); 416 favicon = *favicon_tab_helper->GetFavicon().AsImageSkia().DeepCopy().get();
394 417
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
438 favicon_chooser_->UpdateCandidate(id, image_url, errored, 461 favicon_chooser_->UpdateCandidate(id, image_url, errored,
439 requested_size, bitmaps); 462 requested_size, bitmaps);
440 } 463 }
441 } 464 }
442 465
443 void MetroPinTabHelper::UnPinPageFromStartScreen() { 466 void MetroPinTabHelper::UnPinPageFromStartScreen() {
444 HMODULE metro_module = base::win::GetMetroModule(); 467 HMODULE metro_module = base::win::GetMetroModule();
445 if (!metro_module) 468 if (!metro_module)
446 return; 469 return;
447 470
448 typedef void (*MetroUnPinFromStartScreen)(const string16&); 471 win8::MetroUnPinFromStartScreen metro_un_pin_from_start_screen =
449 MetroUnPinFromStartScreen metro_un_pin_from_start_screen = 472 reinterpret_cast<win8::MetroUnPinFromStartScreen>(
450 reinterpret_cast<MetroUnPinFromStartScreen>(
451 ::GetProcAddress(metro_module, "MetroUnPinFromStartScreen")); 473 ::GetProcAddress(metro_module, "MetroUnPinFromStartScreen"));
452 if (!metro_un_pin_from_start_screen) { 474 if (!metro_un_pin_from_start_screen) {
453 NOTREACHED(); 475 NOTREACHED();
454 return; 476 return;
455 } 477 }
456 478
457 GURL url = web_contents()->GetURL(); 479 GURL url = web_contents()->GetURL();
458 string16 tile_id = GenerateTileId(UTF8ToUTF16(url.spec())); 480 string16 tile_id = GenerateTileId(UTF8ToUTF16(url.spec()));
459 metro_un_pin_from_start_screen(tile_id); 481 metro_un_pin_from_start_screen(tile_id,
482 base::Bind(&PinPageReportUMACallback));
460 } 483 }
461 484
462 void MetroPinTabHelper::FaviconDownloaderFinished() { 485 void MetroPinTabHelper::FaviconDownloaderFinished() {
463 favicon_chooser_.reset(); 486 favicon_chooser_.reset();
464 } 487 }
OLDNEW
« no previous file with comments | « no previous file | chrome/chrome_browser_ui.gypi » ('j') | chrome/chrome_browser_ui.gypi » ('J')

Powered by Google App Engine
This is Rietveld 408576698