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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « components/enhanced_bookmarks/image_store_unittest.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/enhanced_bookmarks/image_store_util_ios.mm
diff --git a/components/enhanced_bookmarks/image_store_util_ios.mm b/components/enhanced_bookmarks/image_store_util_ios.mm
new file mode 100644
index 0000000000000000000000000000000000000000..4b27dcebf77a4a9cfef315b443d63eec25a4cc20
--- /dev/null
+++ b/components/enhanced_bookmarks/image_store_util_ios.mm
@@ -0,0 +1,50 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "components/enhanced_bookmarks/image_store_util.h"
+
+#import <UIKit/UIKit.h>
+
+#include "base/mac/scoped_cftyperef.h"
+#include "base/mac/scoped_nsobject.h"
+
+namespace {
+// An implementation of RefCountedMemory, where the bytes are stored in a
+// NSData. This class assumes the NSData is non mutable to avoid a copy.
+class RefCountedNSDataMemory : public base::RefCountedMemory {
+ public:
+ explicit RefCountedNSDataMemory(NSData* memory) : data_([memory retain]) {}
+
+ virtual const unsigned char* front() const OVERRIDE {
+ return reinterpret_cast<const unsigned char*>([data_ bytes]);
+ }
+
+ virtual size_t size() const OVERRIDE {
+ return [data_ length];
+ }
+
+private:
+ virtual ~RefCountedNSDataMemory() {}
+
+ base::scoped_nsobject<NSData> data_;
+ DISALLOW_COPY_AND_ASSIGN(RefCountedNSDataMemory);
+};
+} // namespace
+
+namespace enhanced_bookmarks {
+
+// Encodes the UIImage representation of a gfx::Image.
+scoped_refptr<base::RefCountedMemory> BytesForImage(const gfx::Image& image) {
+ DCHECK(image.HasRepresentation(gfx::Image::kImageRepCocoaTouch));
+ return scoped_refptr<RefCountedNSDataMemory>(new RefCountedNSDataMemory(
+ [NSKeyedArchiver archivedDataWithRootObject:image.ToUIImage()]));
+}
+
+// Decodes the UIImage in the bytes and returns a gfx::Image.
+gfx::Image ImageForBytes(const scoped_refptr<base::RefCountedMemory>& data) {
+ return gfx::Image([[NSKeyedUnarchiver unarchiveObjectWithData:
+ [NSData dataWithBytes:data->front() length:data->size()]] retain]);
+}
+
+} // namespace enhanced_bookmarks
« 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