Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "components/favicon/core/favicon_driver_impl.h" | 5 #include "components/favicon/core/favicon_driver_impl.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/metrics/field_trial.h" | 9 #include "base/metrics/field_trial.h" |
|
sky
2017/02/06 17:26:21
Remove any stale includes.
| |
| 10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
| 11 #include "build/build_config.h" | 11 #include "build/build_config.h" |
| 12 #include "components/bookmarks/browser/bookmark_model.h" | 12 #include "components/bookmarks/browser/bookmark_model.h" |
| 13 #include "components/favicon/core/favicon_driver_observer.h" | 13 #include "components/favicon/core/favicon_driver_observer.h" |
| 14 #include "components/favicon/core/favicon_handler.h" | 14 #include "components/favicon/core/favicon_handler.h" |
| 15 #include "components/favicon/core/favicon_service.h" | 15 #include "components/favicon/core/favicon_service.h" |
| 16 #include "components/history/core/browser/history_service.h" | 16 #include "components/history/core/browser/history_service.h" |
| 17 #include "ui/base/ui_base_switches.h" | 17 #include "ui/base/ui_base_switches.h" |
| 18 | 18 |
| 19 namespace favicon { | 19 namespace favicon { |
| 20 namespace { | 20 namespace { |
| 21 | 21 |
| 22 // Returns whether icon NTP is enabled by experiment. | |
| 23 // TODO(huangs): Remove all 3 copies of this routine once Icon NTP launches. | |
| 24 bool IsIconNTPEnabled() { | |
| 25 // Note: It's important to query the field trial state first, to ensure that | |
| 26 // UMA reports the correct group. | |
| 27 const std::string group_name = base::FieldTrialList::FindFullName("IconNTP"); | |
| 28 using base::CommandLine; | |
| 29 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kDisableIconNtp)) | |
| 30 return false; | |
| 31 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kEnableIconNtp)) | |
| 32 return true; | |
| 33 | |
| 34 return base::StartsWith(group_name, "Enabled", base::CompareCase::SENSITIVE); | |
| 35 } | |
| 36 | |
| 37 #if defined(OS_ANDROID) || defined(OS_IOS) | 22 #if defined(OS_ANDROID) || defined(OS_IOS) |
| 38 const bool kEnableTouchIcon = true; | 23 const bool kEnableTouchIcon = true; |
| 39 #else | 24 #else |
| 40 const bool kEnableTouchIcon = false; | 25 const bool kEnableTouchIcon = false; |
| 41 #endif | 26 #endif |
| 42 | 27 |
| 43 } // namespace | 28 } // namespace |
| 44 | 29 |
| 45 FaviconDriverImpl::FaviconDriverImpl(FaviconService* favicon_service, | 30 FaviconDriverImpl::FaviconDriverImpl(FaviconService* favicon_service, |
| 46 history::HistoryService* history_service, | 31 history::HistoryService* history_service, |
| 47 bookmarks::BookmarkModel* bookmark_model) | 32 bookmarks::BookmarkModel* bookmark_model) |
| 48 : favicon_service_(favicon_service), | 33 : favicon_service_(favicon_service), |
| 49 history_service_(history_service), | 34 history_service_(history_service), |
| 50 bookmark_model_(bookmark_model) { | 35 bookmark_model_(bookmark_model) { |
| 51 favicon_handler_.reset(new FaviconHandler( | 36 favicon_handler_.reset(new FaviconHandler( |
| 52 favicon_service_, this, kEnableTouchIcon | 37 favicon_service_, this, kEnableTouchIcon |
| 53 ? FaviconDriverObserver::NON_TOUCH_LARGEST | 38 ? FaviconDriverObserver::NON_TOUCH_LARGEST |
| 54 : FaviconDriverObserver::NON_TOUCH_16_DIP)); | 39 : FaviconDriverObserver::NON_TOUCH_16_DIP)); |
| 55 if (kEnableTouchIcon || IsIconNTPEnabled()) { | 40 if (kEnableTouchIcon) { |
| 56 touch_icon_handler_.reset(new FaviconHandler( | 41 touch_icon_handler_.reset(new FaviconHandler( |
| 57 favicon_service_, this, FaviconDriverObserver::TOUCH_LARGEST)); | 42 favicon_service_, this, FaviconDriverObserver::TOUCH_LARGEST)); |
| 58 } | 43 } |
| 59 } | 44 } |
| 60 | 45 |
| 61 FaviconDriverImpl::~FaviconDriverImpl() { | 46 FaviconDriverImpl::~FaviconDriverImpl() { |
| 62 } | 47 } |
| 63 | 48 |
| 64 void FaviconDriverImpl::FetchFavicon(const GURL& url) { | 49 void FaviconDriverImpl::FetchFavicon(const GURL& url) { |
| 65 favicon_handler_->FetchFavicon(url); | 50 favicon_handler_->FetchFavicon(url); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 115 void FaviconDriverImpl::OnUpdateFaviconURL( | 100 void FaviconDriverImpl::OnUpdateFaviconURL( |
| 116 const GURL& page_url, | 101 const GURL& page_url, |
| 117 const std::vector<FaviconURL>& candidates) { | 102 const std::vector<FaviconURL>& candidates) { |
| 118 DCHECK(!candidates.empty()); | 103 DCHECK(!candidates.empty()); |
| 119 favicon_handler_->OnUpdateFaviconURL(page_url, candidates); | 104 favicon_handler_->OnUpdateFaviconURL(page_url, candidates); |
| 120 if (touch_icon_handler_.get()) | 105 if (touch_icon_handler_.get()) |
| 121 touch_icon_handler_->OnUpdateFaviconURL(page_url, candidates); | 106 touch_icon_handler_->OnUpdateFaviconURL(page_url, candidates); |
| 122 } | 107 } |
| 123 | 108 |
| 124 } // namespace favicon | 109 } // namespace favicon |
| OLD | NEW |