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

Side by Side Diff: components/enhanced_bookmarks/image_store_util_ios.mm

Issue 347513003: Adding iOS support for image_store. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 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 | Annotate | Revision Log
« no previous file with comments | « components/enhanced_bookmarks/image_store_unittest.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "components/enhanced_bookmarks/image_store_util.h"
6
7 #import <UIKit/UIKit.h>
8
9 #include "base/mac/scoped_cftyperef.h"
10 #include "base/mac/scoped_nsobject.h"
11
12 namespace {
13 // An implementation of RefCountedMemory, where the bytes are stored in a
14 // NSData. This class assumes the NSData is non mutable to avoid a copy.
15 class RefCountedNSDataMemory : public base::RefCountedMemory {
16 public:
17 explicit RefCountedNSDataMemory(NSData* memory) : data_([memory retain]) {}
18
19 virtual const unsigned char* front() const OVERRIDE {
20 return reinterpret_cast<const unsigned char*>([data_ bytes]);
21 }
22
23 virtual size_t size() const OVERRIDE {
24 return [data_ length];
25 }
26
27 private:
28 virtual ~RefCountedNSDataMemory() {}
29
30 base::scoped_nsobject<NSData> data_;
31 DISALLOW_COPY_AND_ASSIGN(RefCountedNSDataMemory);
32 };
33 } // namespace
34
35 namespace enhanced_bookmarks {
36
37 // Encodes the UIImage representation of a gfx::Image.
38 scoped_refptr<base::RefCountedMemory> BytesForImage(const gfx::Image& image) {
39 DCHECK(image.HasRepresentation(gfx::Image::kImageRepCocoaTouch));
40 return scoped_refptr<RefCountedNSDataMemory>(new RefCountedNSDataMemory(
41 [NSKeyedArchiver archivedDataWithRootObject:image.ToUIImage()]));
42 }
43
44 // Decodes the UIImage in the bytes and returns a gfx::Image.
45 gfx::Image ImageForBytes(const scoped_refptr<base::RefCountedMemory>& data) {
46 return gfx::Image([[NSKeyedUnarchiver unarchiveObjectWithData:
47 [NSData dataWithBytes:data->front() length:data->size()]] retain]);
48 }
49
50 } // namespace enhanced_bookmarks
OLDNEW
« no previous file with comments | « components/enhanced_bookmarks/image_store_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698