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

Side by Side Diff: base/data_pack.cc

Issue 338027: Modify DataPacks so they can return RefCountedStaticMemory objects. (Closed)
Patch Set: Rewrite GetStaticMemory Created 11 years, 1 month 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
« no previous file with comments | « base/data_pack.h ('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
1 // Copyright (c) 2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2008 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 "base/data_pack.h" 5 #include "base/data_pack.h"
6 6
7 #include <errno.h> 7 #include <errno.h>
8 8
9 #include "base/file_util.h" 9 #include "base/file_util.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 LOG(ERROR) << "Entry #" << i << " in data pack points off end of file. " 82 LOG(ERROR) << "Entry #" << i << " in data pack points off end of file. "
83 << "Was the file corrupted?"; 83 << "Was the file corrupted?";
84 mmap_.reset(); 84 mmap_.reset();
85 return false; 85 return false;
86 } 86 }
87 } 87 }
88 88
89 return true; 89 return true;
90 } 90 }
91 91
92 bool DataPack::Get(uint32_t resource_id, StringPiece* data) { 92 bool DataPack::GetStringPiece(uint32_t resource_id, StringPiece* data) {
93 // It won't be hard to make this endian-agnostic, but it's not worth 93 // It won't be hard to make this endian-agnostic, but it's not worth
94 // bothering to do right now. 94 // bothering to do right now.
95 #if defined(__BYTE_ORDER) 95 #if defined(__BYTE_ORDER)
96 // Linux check 96 // Linux check
97 COMPILE_ASSERT(__BYTE_ORDER == __LITTLE_ENDIAN, 97 COMPILE_ASSERT(__BYTE_ORDER == __LITTLE_ENDIAN,
98 datapack_assumes_little_endian); 98 datapack_assumes_little_endian);
99 #elif defined(__BIG_ENDIAN__) 99 #elif defined(__BIG_ENDIAN__)
100 // Mac check 100 // Mac check
101 #error DataPack assumes little endian 101 #error DataPack assumes little endian
102 #endif 102 #endif
103 103
104 DataPackEntry* target = reinterpret_cast<DataPackEntry*>( 104 DataPackEntry* target = reinterpret_cast<DataPackEntry*>(
105 bsearch(&resource_id, mmap_->data() + kHeaderLength, resource_count_, 105 bsearch(&resource_id, mmap_->data() + kHeaderLength, resource_count_,
106 sizeof(DataPackEntry), DataPackEntry::CompareById)); 106 sizeof(DataPackEntry), DataPackEntry::CompareById));
107 if (!target) { 107 if (!target) {
108 LOG(ERROR) << "No resource found with id: " << resource_id; 108 LOG(ERROR) << "No resource found with id: " << resource_id;
109 return false; 109 return false;
110 } 110 }
111 111
112 data->set(mmap_->data() + target->file_offset, target->length); 112 data->set(mmap_->data() + target->file_offset, target->length);
113 return true; 113 return true;
114 } 114 }
115 115
116 RefCountedStaticMemory* DataPack::GetStaticMemory(uint32_t resource_id) {
117 base::StringPiece piece;
118 if (!GetStringPiece(resource_id, &piece)) {
119 return NULL;
120 }
Evan Martin 2009/10/26 23:57:42 curlies not necessary here
121
122 return new RefCountedStaticMemory(
123 reinterpret_cast<const unsigned char*>(piece.data()), piece.length());
124 }
125
116 } // namespace base 126 } // namespace base
OLDNEW
« no previous file with comments | « base/data_pack.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698