OLD | NEW |
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" |
38 | 39 |
39 DEFINE_WEB_CONTENTS_USER_DATA_KEY(MetroPinTabHelper) | 40 DEFINE_WEB_CONTENTS_USER_DATA_KEY(MetroPinTabHelper) |
40 | 41 |
41 namespace { | 42 namespace { |
42 | 43 |
| 44 // Histogram name for site-specific tile pinning metrics. |
| 45 const char kMetroPinMetric[] = "Metro.SecondaryTilePin"; |
| 46 |
43 // Generate an ID for the tile based on |url_str|. The ID is simply a hash of | 47 // Generate an ID for the tile based on |url_str|. The ID is simply a hash of |
44 // the URL. | 48 // the URL. |
45 string16 GenerateTileId(const string16& url_str) { | 49 string16 GenerateTileId(const string16& url_str) { |
46 uint8 hash[crypto::kSHA256Length]; | 50 uint8 hash[crypto::kSHA256Length]; |
47 crypto::SHA256HashString(UTF16ToUTF8(url_str), hash, sizeof(hash)); | 51 crypto::SHA256HashString(UTF16ToUTF8(url_str), hash, sizeof(hash)); |
48 std::string hash_str = base::HexEncode(hash, sizeof(hash)); | 52 std::string hash_str = base::HexEncode(hash, sizeof(hash)); |
49 return UTF8ToUTF16(hash_str); | 53 return UTF8ToUTF16(hash_str); |
50 } | 54 } |
51 | 55 |
52 // Get the path of the directory to store the tile logos in. | 56 // Get the path of the directory to store the tile logos in. |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
151 return true; | 155 return true; |
152 | 156 |
153 FilePath default_logo_path; | 157 FilePath default_logo_path; |
154 if (!PathService::Get(base::DIR_MODULE, &default_logo_path)) | 158 if (!PathService::Get(base::DIR_MODULE, &default_logo_path)) |
155 return false; | 159 return false; |
156 | 160 |
157 default_logo_path = default_logo_path.Append(kDefaultLogoFileName); | 161 default_logo_path = default_logo_path.Append(kDefaultLogoFileName); |
158 return file_util::CopyFile(default_logo_path, *logo_path); | 162 return file_util::CopyFile(default_logo_path, *logo_path); |
159 } | 163 } |
160 | 164 |
| 165 // UMA reporting callback for site-specific secondary tile creation. |
| 166 void PinPageReportUmaCallback( |
| 167 base::win::MetroSecondaryTilePinUmaResult result) { |
| 168 UMA_HISTOGRAM_ENUMERATION(kMetroPinMetric, |
| 169 result, |
| 170 base::win::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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 } |
221 | 233 |
| 234 UMA_HISTOGRAM_ENUMERATION(kMetroPinMetric, |
| 235 base::win::METRO_PIN_LOGO_READY, |
| 236 base::win::METRO_PIN_STATE_LIMIT); |
| 237 |
222 HMODULE metro_module = base::win::GetMetroModule(); | 238 HMODULE metro_module = base::win::GetMetroModule(); |
223 if (!metro_module) | 239 if (!metro_module) |
224 return; | 240 return; |
225 | 241 |
226 typedef void (*MetroPinToStartScreen)(const string16&, const string16&, | 242 base::win::MetroPinToStartScreen metro_pin_to_start_screen = |
227 const string16&, const FilePath&); | 243 reinterpret_cast<base::win::MetroPinToStartScreen>( |
228 MetroPinToStartScreen metro_pin_to_start_screen = | |
229 reinterpret_cast<MetroPinToStartScreen>( | |
230 ::GetProcAddress(metro_module, "MetroPinToStartScreen")); | 244 ::GetProcAddress(metro_module, "MetroPinToStartScreen")); |
231 if (!metro_pin_to_start_screen) { | 245 if (!metro_pin_to_start_screen) { |
232 NOTREACHED(); | 246 NOTREACHED(); |
233 return; | 247 return; |
234 } | 248 } |
235 | 249 |
236 metro_pin_to_start_screen(tile_id, title_, url_, logo_path); | 250 metro_pin_to_start_screen(tile_id, |
| 251 title_, |
| 252 url_, |
| 253 logo_path, |
| 254 base::Bind(&PinPageReportUmaCallback)); |
237 } | 255 } |
238 | 256 |
239 } // namespace | 257 } // namespace |
240 | 258 |
241 class MetroPinTabHelper::FaviconChooser { | 259 class MetroPinTabHelper::FaviconChooser { |
242 public: | 260 public: |
243 FaviconChooser(MetroPinTabHelper* helper, | 261 FaviconChooser(MetroPinTabHelper* helper, |
244 const string16& title, | 262 const string16& title, |
245 const string16& url, | 263 const string16& url, |
246 const gfx::ImageSkia& history_image); | 264 const gfx::ImageSkia& history_image); |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
371 return false; | 389 return false; |
372 } | 390 } |
373 | 391 |
374 GURL url = web_contents()->GetURL(); | 392 GURL url = web_contents()->GetURL(); |
375 string16 tile_id = GenerateTileId(UTF8ToUTF16(url.spec())); | 393 string16 tile_id = GenerateTileId(UTF8ToUTF16(url.spec())); |
376 return metro_is_pinned_to_start_screen(tile_id) != 0; | 394 return metro_is_pinned_to_start_screen(tile_id) != 0; |
377 } | 395 } |
378 | 396 |
379 void MetroPinTabHelper::TogglePinnedToStartScreen() { | 397 void MetroPinTabHelper::TogglePinnedToStartScreen() { |
380 if (IsPinned()) { | 398 if (IsPinned()) { |
| 399 UMA_HISTOGRAM_ENUMERATION(kMetroPinMetric, |
| 400 base::win::METRO_UNPIN_INITIATED, |
| 401 base::win::METRO_PIN_STATE_LIMIT); |
381 UnPinPageFromStartScreen(); | 402 UnPinPageFromStartScreen(); |
382 return; | 403 return; |
383 } | 404 } |
384 | 405 |
| 406 UMA_HISTOGRAM_ENUMERATION(kMetroPinMetric, |
| 407 base::win::METRO_PIN_INITIATED, |
| 408 base::win::METRO_PIN_STATE_LIMIT); |
385 GURL url = web_contents()->GetURL(); | 409 GURL url = web_contents()->GetURL(); |
386 string16 url_str = UTF8ToUTF16(url.spec()); | 410 string16 url_str = UTF8ToUTF16(url.spec()); |
387 string16 title = web_contents()->GetTitle(); | 411 string16 title = web_contents()->GetTitle(); |
388 // TODO(oshima): Use scoped_ptr::Pass to pass it to other thread. | 412 // TODO(oshima): Use scoped_ptr::Pass to pass it to other thread. |
389 gfx::ImageSkia favicon; | 413 gfx::ImageSkia favicon; |
390 FaviconTabHelper* favicon_tab_helper = FaviconTabHelper::FromWebContents( | 414 FaviconTabHelper* favicon_tab_helper = FaviconTabHelper::FromWebContents( |
391 web_contents()); | 415 web_contents()); |
392 if (favicon_tab_helper->FaviconIsValid()) | 416 if (favicon_tab_helper->FaviconIsValid()) |
393 favicon = *favicon_tab_helper->GetFavicon().AsImageSkia().DeepCopy().get(); | 417 favicon = *favicon_tab_helper->GetFavicon().AsImageSkia().DeepCopy().get(); |
394 | 418 |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
438 favicon_chooser_->UpdateCandidate(id, image_url, errored, | 462 favicon_chooser_->UpdateCandidate(id, image_url, errored, |
439 requested_size, bitmaps); | 463 requested_size, bitmaps); |
440 } | 464 } |
441 } | 465 } |
442 | 466 |
443 void MetroPinTabHelper::UnPinPageFromStartScreen() { | 467 void MetroPinTabHelper::UnPinPageFromStartScreen() { |
444 HMODULE metro_module = base::win::GetMetroModule(); | 468 HMODULE metro_module = base::win::GetMetroModule(); |
445 if (!metro_module) | 469 if (!metro_module) |
446 return; | 470 return; |
447 | 471 |
448 typedef void (*MetroUnPinFromStartScreen)(const string16&); | 472 base::win::MetroUnPinFromStartScreen metro_un_pin_from_start_screen = |
449 MetroUnPinFromStartScreen metro_un_pin_from_start_screen = | 473 reinterpret_cast<base::win::MetroUnPinFromStartScreen>( |
450 reinterpret_cast<MetroUnPinFromStartScreen>( | |
451 ::GetProcAddress(metro_module, "MetroUnPinFromStartScreen")); | 474 ::GetProcAddress(metro_module, "MetroUnPinFromStartScreen")); |
452 if (!metro_un_pin_from_start_screen) { | 475 if (!metro_un_pin_from_start_screen) { |
453 NOTREACHED(); | 476 NOTREACHED(); |
454 return; | 477 return; |
455 } | 478 } |
456 | 479 |
457 GURL url = web_contents()->GetURL(); | 480 GURL url = web_contents()->GetURL(); |
458 string16 tile_id = GenerateTileId(UTF8ToUTF16(url.spec())); | 481 string16 tile_id = GenerateTileId(UTF8ToUTF16(url.spec())); |
459 metro_un_pin_from_start_screen(tile_id); | 482 metro_un_pin_from_start_screen(tile_id, |
| 483 base::Bind(&PinPageReportUmaCallback)); |
460 } | 484 } |
461 | 485 |
462 void MetroPinTabHelper::FaviconDownloaderFinished() { | 486 void MetroPinTabHelper::FaviconDownloaderFinished() { |
463 favicon_chooser_.reset(); | 487 favicon_chooser_.reset(); |
464 } | 488 } |
OLD | NEW |