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

Side by Side Diff: ios/chrome/browser/ui/bookmarks/bookmark_collection_view.mm

Issue 2942923002: Implementing sign-in promo histograms for bookmark (Closed)
Patch Set: Created 3 years, 6 months 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 #import "ios/chrome/browser/ui/bookmarks/bookmark_collection_view.h" 5 #import "ios/chrome/browser/ui/bookmarks/bookmark_collection_view.h"
6 6
7 #import <UIKit/UIGestureRecognizerSubclass.h> 7 #import <UIKit/UIGestureRecognizerSubclass.h>
8 #include <algorithm> 8 #include <algorithm>
9 #include <map> 9 #include <map>
10 #include <memory> 10 #include <memory>
11 11
12 #include "base/logging.h" 12 #include "base/logging.h"
13 #include "base/mac/bind_objc_block.h" 13 #include "base/mac/bind_objc_block.h"
14 #include "base/mac/foundation_util.h" 14 #include "base/mac/foundation_util.h"
15 #include "base/strings/sys_string_conversions.h" 15 #include "base/strings/sys_string_conversions.h"
16 #include "components/bookmarks/browser/bookmark_model.h" 16 #include "components/bookmarks/browser/bookmark_model.h"
17 #include "components/bookmarks/browser/bookmark_model_observer.h" 17 #include "components/bookmarks/browser/bookmark_model_observer.h"
18 #include "components/favicon/core/fallback_url_util.h" 18 #include "components/favicon/core/fallback_url_util.h"
19 #include "components/favicon/core/large_icon_service.h" 19 #include "components/favicon/core/large_icon_service.h"
20 #include "components/favicon_base/fallback_icon_style.h" 20 #include "components/favicon_base/fallback_icon_style.h"
21 #include "components/favicon_base/favicon_types.h" 21 #include "components/favicon_base/favicon_types.h"
22 #include "components/pref_registry/pref_registry_syncable.h"
22 #include "ios/chrome/browser/bookmarks/bookmark_model_factory.h" 23 #include "ios/chrome/browser/bookmarks/bookmark_model_factory.h"
23 #include "ios/chrome/browser/bookmarks/bookmarks_utils.h" 24 #include "ios/chrome/browser/bookmarks/bookmarks_utils.h"
24 #include "ios/chrome/browser/experimental_flags.h" 25 #include "ios/chrome/browser/experimental_flags.h"
25 #include "ios/chrome/browser/favicon/ios_chrome_large_icon_service_factory.h" 26 #include "ios/chrome/browser/favicon/ios_chrome_large_icon_service_factory.h"
27 #include "ios/chrome/browser/pref_names.h"
26 #import "ios/chrome/browser/ui/authentication/signin_promo_view.h" 28 #import "ios/chrome/browser/ui/authentication/signin_promo_view.h"
27 #import "ios/chrome/browser/ui/authentication/signin_promo_view_configurator.h" 29 #import "ios/chrome/browser/ui/authentication/signin_promo_view_configurator.h"
28 #import "ios/chrome/browser/ui/authentication/signin_promo_view_consumer.h" 30 #import "ios/chrome/browser/ui/authentication/signin_promo_view_consumer.h"
29 #import "ios/chrome/browser/ui/authentication/signin_promo_view_mediator.h" 31 #import "ios/chrome/browser/ui/authentication/signin_promo_view_mediator.h"
30 #import "ios/chrome/browser/ui/bookmarks/bookmark_collection_cells.h" 32 #import "ios/chrome/browser/ui/bookmarks/bookmark_collection_cells.h"
31 #import "ios/chrome/browser/ui/bookmarks/bookmark_collection_view_background.h" 33 #import "ios/chrome/browser/ui/bookmarks/bookmark_collection_view_background.h"
32 #import "ios/chrome/browser/ui/bookmarks/bookmark_promo_cell.h" 34 #import "ios/chrome/browser/ui/bookmarks/bookmark_promo_cell.h"
33 #import "ios/chrome/browser/ui/bookmarks/bookmark_signin_promo_cell.h" 35 #import "ios/chrome/browser/ui/bookmarks/bookmark_signin_promo_cell.h"
34 #import "ios/chrome/browser/ui/bookmarks/bookmark_utils_ios.h" 36 #import "ios/chrome/browser/ui/bookmarks/bookmark_utils_ios.h"
35 #include "ios/chrome/browser/ui/ui_util.h" 37 #include "ios/chrome/browser/ui/ui_util.h"
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 CGFloat rowMarginTablet = 24.0; 72 CGFloat rowMarginTablet = 24.0;
71 CGFloat rowHeight = 48.0; 73 CGFloat rowHeight = 48.0;
72 // Minimal acceptable favicon size, in points. 74 // Minimal acceptable favicon size, in points.
73 CGFloat minFaviconSizePt = 16; 75 CGFloat minFaviconSizePt = 16;
74 76
75 // Delay in seconds to which the empty background view will be shown when the 77 // Delay in seconds to which the empty background view will be shown when the
76 // collection view is empty. 78 // collection view is empty.
77 // This delay should not be too small to let enough time to load bookmarks 79 // This delay should not be too small to let enough time to load bookmarks
78 // from network. 80 // from network.
79 const NSTimeInterval kShowEmptyBookmarksBackgroundRefreshDelay = 1.0; 81 const NSTimeInterval kShowEmptyBookmarksBackgroundRefreshDelay = 1.0;
82
83 // The histogram used to record the number of time was seen before the bookmark
sdefresne 2017/06/19 09:07:50 Why are those constants here and not in signin_pro
jlebel 2017/06/19 14:38:12 The sign-in promo mediator is used also for in "ot
84 // view has been closed.
85 const char kBookmarksDismissalCount[] =
86 "MobileSignInPromo.BookmarkManager.DismissalCount";
87 // The histogram used to record the number of time was seen before the user uses
88 // the sign-in promo.
89 const char kBookmarksCountTilSignin[] =
sdefresne 2017/06/19 09:07:50 Shouldn't this be "kBookmarksCountTillSignin"?
jlebel 2017/06/19 14:38:12 See signin_promo_view_mediator.h
90 "MobileSignInPromo.BookmarkManager.CountTilSignin";
91 // The histogram used to record the number of time was seen before the user
92 // dissmisses the sign-in promo.
93 const char kBookmarkCountTilX[] = "MobileSignInPromo.BookmarkManager.CountTilX";
sdefresne 2017/06/19 09:07:50 Shouldn't this be "kBookmarkCountTillX"?
jlebel 2017/06/19 14:38:12 See signin_promo_view_mediator.h
80 } 94 }
81 95
82 @interface BookmarkCollectionView ()<BookmarkPromoCellDelegate, 96 @interface BookmarkCollectionView ()<BookmarkPromoCellDelegate,
83 SigninPromoViewConsumer, 97 SigninPromoViewConsumer,
84 UICollectionViewDataSource, 98 UICollectionViewDataSource,
85 UICollectionViewDelegateFlowLayout, 99 UICollectionViewDelegateFlowLayout,
86 UIGestureRecognizerDelegate> { 100 UIGestureRecognizerDelegate> {
87 // A vector of folders to display in the collection view. 101 // A vector of folders to display in the collection view.
88 std::vector<const BookmarkNode*> _subFolders; 102 std::vector<const BookmarkNode*> _subFolders;
89 // A vector of bookmark urls to display in the collection view. 103 // A vector of bookmark urls to display in the collection view.
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 @synthesize folder = _folder; 149 @synthesize folder = _folder;
136 @synthesize bookmarkModel = _bookmarkModel; 150 @synthesize bookmarkModel = _bookmarkModel;
137 @synthesize collectionView = _collectionView; 151 @synthesize collectionView = _collectionView;
138 @synthesize editing = _editing; 152 @synthesize editing = _editing;
139 @synthesize emptyCollectionBackgroundView = _emptyCollectionBackgroundView; 153 @synthesize emptyCollectionBackgroundView = _emptyCollectionBackgroundView;
140 @synthesize loader = _loader; 154 @synthesize loader = _loader;
141 @synthesize longPressRecognizer = _longPressRecognizer; 155 @synthesize longPressRecognizer = _longPressRecognizer;
142 @synthesize browserState = _browserState; 156 @synthesize browserState = _browserState;
143 @synthesize shadow = _shadow; 157 @synthesize shadow = _shadow;
144 158
159 + (void)registerBrowserStatePrefs:(user_prefs::PrefRegistrySyncable*)registry {
160 registry->RegisterIntegerPref(prefs::kIosBookmarkSigninPromoDisplayedCount,
161 0);
162 }
163
145 #pragma mark - Initialization 164 #pragma mark - Initialization
146 165
147 - (void)setupViews { 166 - (void)setupViews {
148 self.backgroundColor = bookmark_utils_ios::mainBackgroundColor(); 167 self.backgroundColor = bookmark_utils_ios::mainBackgroundColor();
149 UICollectionViewFlowLayout* layout = 168 UICollectionViewFlowLayout* layout =
150 [[UICollectionViewFlowLayout alloc] init]; 169 [[UICollectionViewFlowLayout alloc] init];
151 170
152 UICollectionView* collectionView = 171 UICollectionView* collectionView =
153 [[UICollectionView alloc] initWithFrame:self.bounds 172 [[UICollectionView alloc] initWithFrame:self.bounds
154 collectionViewLayout:layout]; 173 collectionViewLayout:layout];
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
328 if (newPromoState != _promoVisible) { 347 if (newPromoState != _promoVisible) {
329 // This is awful, but until the old code to do the refresh when switching 348 // This is awful, but until the old code to do the refresh when switching
330 // in and out of edit mode is fixed, this is probably the cleanest thing to 349 // in and out of edit mode is fixed, this is probably the cleanest thing to
331 // do. 350 // do.
332 _promoVisible = newPromoState; 351 _promoVisible = newPromoState;
333 if (experimental_flags::IsSigninPromoEnabled()) { 352 if (experimental_flags::IsSigninPromoEnabled()) {
334 if (!_promoVisible) { 353 if (!_promoVisible) {
335 _signinPromoViewMediator.consumer = nil; 354 _signinPromoViewMediator.consumer = nil;
336 _signinPromoViewMediator = nil; 355 _signinPromoViewMediator = nil;
337 } else { 356 } else {
338 _signinPromoViewMediator = [[SigninPromoViewMediator alloc] init]; 357 _signinPromoViewMediator = [[SigninPromoViewMediator alloc]
358 initWithBrowserState:_browserState];
339 _signinPromoViewMediator.consumer = self; 359 _signinPromoViewMediator.consumer = self;
360 _signinPromoViewMediator.displayedCountPreferenceKey =
361 prefs::kIosBookmarkSigninPromoDisplayedCount;
362 _signinPromoViewMediator.alreadySeenSigninViewPreferenceKey =
363 prefs::kIosBookmarkPromoAlreadySeen;
364 _signinPromoViewMediator.dismissalCountHistogramName =
365 kBookmarksDismissalCount;
366 _signinPromoViewMediator.countTilXHistogramName = kBookmarkCountTilX;
367 _signinPromoViewMediator.countTilSigninHistogramName =
368 kBookmarksCountTilSignin;
340 _signinPromoViewMediator.accessPoint = 369 _signinPromoViewMediator.accessPoint =
341 signin_metrics::AccessPoint::ACCESS_POINT_BOOKMARK_MANAGER; 370 signin_metrics::AccessPoint::ACCESS_POINT_BOOKMARK_MANAGER;
371 [_signinPromoViewMediator signinPromoViewVisible];
342 } 372 }
343 } 373 }
344 [self.collectionView reloadData]; 374 [self.collectionView reloadData];
345 } 375 }
346 } 376 }
347 377
378 - (void)wasShown {
379 [_signinPromoViewMediator signinPromoViewVisible];
380 }
381
382 - (void)wasHidden {
383 [_signinPromoViewMediator signinPromoViewHidden];
384 }
385
348 #pragma mark - Sections 386 #pragma mark - Sections
349 387
350 - (NSInteger)promoSection { 388 - (NSInteger)promoSection {
351 return [self shouldShowPromoCell] ? 0 : -1; 389 return [self shouldShowPromoCell] ? 0 : -1;
352 } 390 }
353 391
354 - (NSInteger)folderSection { 392 - (NSInteger)folderSection {
355 return [self shouldShowPromoCell] ? 1 : 0; 393 return [self shouldShowPromoCell] ? 1 : 0;
356 } 394 }
357 395
(...skipping 408 matching lines...) Expand 10 before | Expand all | Expand 10 after
766 if (experimental_flags::IsSigninPromoEnabled()) { 804 if (experimental_flags::IsSigninPromoEnabled()) {
767 BookmarkSigninPromoCell* signinPromoCell = [self.collectionView 805 BookmarkSigninPromoCell* signinPromoCell = [self.collectionView
768 dequeueReusableCellWithReuseIdentifier:[BookmarkSigninPromoCell 806 dequeueReusableCellWithReuseIdentifier:[BookmarkSigninPromoCell
769 reuseIdentifier] 807 reuseIdentifier]
770 forIndexPath:indexPath]; 808 forIndexPath:indexPath];
771 signinPromoCell.signinPromoView.delegate = _signinPromoViewMediator; 809 signinPromoCell.signinPromoView.delegate = _signinPromoViewMediator;
772 [[_signinPromoViewMediator createConfigurator] 810 [[_signinPromoViewMediator createConfigurator]
773 configureSigninPromoView:signinPromoCell.signinPromoView]; 811 configureSigninPromoView:signinPromoCell.signinPromoView];
774 __weak BookmarkCollectionView* weakSelf = self; 812 __weak BookmarkCollectionView* weakSelf = self;
775 signinPromoCell.closeButtonAction = ^() { 813 signinPromoCell.closeButtonAction = ^() {
776 [weakSelf.delegate bookmarkCollectionViewDismissPromo:self]; 814 [weakSelf signinPromoCloseButtonAction];
777 }; 815 };
778 return signinPromoCell; 816 return signinPromoCell;
779 } else { 817 } else {
780 BookmarkPromoCell* promoCell = [self.collectionView 818 BookmarkPromoCell* promoCell = [self.collectionView
781 dequeueReusableCellWithReuseIdentifier:[BookmarkPromoCell 819 dequeueReusableCellWithReuseIdentifier:[BookmarkPromoCell
782 reuseIdentifier] 820 reuseIdentifier]
783 forIndexPath:indexPath]; 821 forIndexPath:indexPath];
784 promoCell.delegate = self; 822 promoCell.delegate = self;
785 return promoCell; 823 return promoCell;
786 } 824 }
787 } 825 }
788 const BookmarkNode* node = [self nodeAtIndexPath:indexPath]; 826 const BookmarkNode* node = [self nodeAtIndexPath:indexPath];
789 827
790 if (indexPath.section == self.folderSection) 828 if (indexPath.section == self.folderSection)
791 return [self cellForFolder:node indexPath:indexPath]; 829 return [self cellForFolder:node indexPath:indexPath];
792 830
793 BookmarkItemCell* cell = [self cellForBookmark:node indexPath:indexPath]; 831 BookmarkItemCell* cell = [self cellForBookmark:node indexPath:indexPath];
794 return cell; 832 return cell;
795 } 833 }
796 834
835 // Removes the sign-in promo view.
836 - (void)signinPromoCloseButtonAction {
837 [_signinPromoViewMediator signinPromoViewDismissed];
838 [_delegate bookmarkCollectionViewDismissPromo:self];
839 }
840
797 // Create a header view for the element at |indexPath|. 841 // Create a header view for the element at |indexPath|.
798 - (UICollectionReusableView*)headerAtIndexPath:(NSIndexPath*)indexPath { 842 - (UICollectionReusableView*)headerAtIndexPath:(NSIndexPath*)indexPath {
799 if (![self needsSectionHeaderForSection:indexPath.section]) 843 if (![self needsSectionHeaderForSection:indexPath.section])
800 return nil; 844 return nil;
801 845
802 BookmarkHeaderSeparatorView* view = [self.collectionView 846 BookmarkHeaderSeparatorView* view = [self.collectionView
803 dequeueReusableSupplementaryViewOfKind: 847 dequeueReusableSupplementaryViewOfKind:
804 UICollectionElementKindSectionHeader 848 UICollectionElementKindSectionHeader
805 withReuseIdentifier:[BookmarkHeaderSeparatorView 849 withReuseIdentifier:[BookmarkHeaderSeparatorView
806 reuseIdentifier] 850 reuseIdentifier]
(...skipping 440 matching lines...) Expand 10 before | Expand all | Expand 10 after
1247 1291
1248 - (BOOL)shouldShowPromoCell { 1292 - (BOOL)shouldShowPromoCell {
1249 return _promoVisible; 1293 return _promoVisible;
1250 } 1294 }
1251 1295
1252 - (BOOL)isPromoActive { 1296 - (BOOL)isPromoActive {
1253 return NO; 1297 return NO;
1254 } 1298 }
1255 1299
1256 @end 1300 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698