OLD | NEW |
---|---|
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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 "ios/chrome/browser/ui/activity_services/share_to_data.h" | 5 #include "ios/chrome/browser/ui/activity_services/share_to_data.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/strings/sys_string_conversions.h" | 8 #include "base/strings/sys_string_conversions.h" |
9 #include "ios/chrome/browser/tabs/tab.h" | 9 #include "ios/chrome/browser/tabs/tab.h" |
10 #import "net/base/mac/url_conversions.h" | 10 #import "net/base/mac/url_conversions.h" |
(...skipping 20 matching lines...) Expand all Loading... | |
31 | 31 |
32 @property(nonatomic, readwrite, copy) NSString* title; | 32 @property(nonatomic, readwrite, copy) NSString* title; |
33 @property(nonatomic, readwrite, assign) BOOL isOriginalTitle; | 33 @property(nonatomic, readwrite, assign) BOOL isOriginalTitle; |
34 @property(nonatomic, readwrite, assign) BOOL isPagePrintable; | 34 @property(nonatomic, readwrite, assign) BOOL isPagePrintable; |
35 @end | 35 @end |
36 | 36 |
37 @implementation ShareToData | 37 @implementation ShareToData |
38 | 38 |
39 @synthesize title = title_; | 39 @synthesize title = title_; |
40 @synthesize image = image_; | 40 @synthesize image = image_; |
41 @synthesize thumbnailGenerator = thumbnailGenerator_; | |
41 @synthesize isOriginalTitle = isOriginalTitle_; | 42 @synthesize isOriginalTitle = isOriginalTitle_; |
42 @synthesize isPagePrintable = isPagePrintable_; | 43 @synthesize isPagePrintable = isPagePrintable_; |
43 | 44 |
44 - (id)init { | 45 - (id)init { |
45 NOTREACHED(); | 46 NOTREACHED(); |
46 return nil; | 47 return nil; |
47 } | 48 } |
48 | 49 |
49 - (id)initWithURL:(const GURL&)url | 50 - (id)initWithURL:(const GURL&)url |
50 title:(NSString*)title | 51 title:(NSString*)title |
51 isOriginalTitle:(BOOL)isOriginalTitle | 52 isOriginalTitle:(BOOL)isOriginalTitle |
52 isPagePrintable:(BOOL)isPagePrintable { | 53 isPagePrintable:(BOOL)isPagePrintable |
54 thumbnailGenerator:(ThumbnailGeneratorBlock)thumbnailGenerator { | |
53 DCHECK(url.is_valid()); | 55 DCHECK(url.is_valid()); |
54 DCHECK(title); | 56 DCHECK(title); |
55 self = [super init]; | 57 self = [super init]; |
56 if (self) { | 58 if (self) { |
57 url_ = url; | 59 url_ = url; |
58 self.title = title; | 60 self.title = title; |
59 self.isOriginalTitle = isOriginalTitle; | 61 self.isOriginalTitle = isOriginalTitle; |
60 self.isPagePrintable = isPagePrintable; | 62 self.isPagePrintable = isPagePrintable; |
63 self.thumbnailGenerator = thumbnailGenerator; | |
61 } | 64 } |
62 return self; | 65 return self; |
63 } | 66 } |
64 | 67 |
65 - (const GURL&)url { | 68 - (const GURL&)url { |
66 return url_; | 69 return url_; |
67 } | 70 } |
68 | 71 |
69 - (NSURL*)nsurl { | 72 - (NSURL*)nsurl { |
70 return net::NSURLWithGURL(url_); | 73 return net::NSURLWithGURL(url_); |
71 } | 74 } |
72 | 75 |
73 - (BOOL)isEqual:(id)object { | 76 - (BOOL)isEqual:(id)object { |
77 // Used for testing. | |
74 if (![object isMemberOfClass:self.class]) | 78 if (![object isMemberOfClass:self.class]) |
75 return NO; | 79 return NO; |
76 DCHECK(self.url.is_valid()); | 80 DCHECK(self.url.is_valid()); |
77 DCHECK(self.title); | 81 DCHECK(self.title); |
78 ShareToData* other = (ShareToData*)object; | 82 ShareToData* other = (ShareToData*)object; |
83 CGSize size = CGSizeMake(40, 40); | |
Olivier
2017/01/24 16:54:05
Add comment.
Block are equal if they give the same
jif
2017/01/25 15:17:29
Ack.
I moved the code which makes this comment obs
| |
84 NSData* thumbnailData = | |
85 UIImagePNGRepresentation(self.thumbnailGenerator(size)); | |
86 NSData* otherThumbnailData = | |
87 UIImagePNGRepresentation(other.thumbnailGenerator(size)); | |
88 BOOL thumbnailDataIsEqual = thumbnailData == otherThumbnailData || | |
Olivier
2017/01/24 16:54:05
I don't think I see anywhere in tests where this c
jif
2017/01/25 15:17:29
Done.
The bitmap comparison is used in the bvc_uni
| |
89 [thumbnailData isEqual:otherThumbnailData]; | |
79 return self.url == other.url && [self.title isEqual:other.title] && | 90 return self.url == other.url && [self.title isEqual:other.title] && |
80 self.image == other.image && | 91 self.image == other.image && |
81 self.isOriginalTitle == other.isOriginalTitle; | 92 self.isOriginalTitle == other.isOriginalTitle && |
82 } | 93 self.isPagePrintable == other.isPagePrintable && thumbnailDataIsEqual; |
83 | |
84 - (NSUInteger)hash { | |
85 DCHECK(self.url.is_valid()); | |
86 DCHECK(self.title); | |
87 const NSUInteger kPrime = 31; | |
88 NSString* urlString = base::SysUTF8ToNSString(self.url.spec()); | |
89 return kPrime * kPrime * kPrime * urlString.hash + | |
90 kPrime * kPrime * self.title.hash + kPrime * self.image.hash + | |
91 (self.isOriginalTitle ? 0 : 1); | |
92 } | 94 } |
93 | 95 |
94 @end | 96 @end |
OLD | NEW |